Debian Codegraph @

c/enc/memory.h

raw symbols SCIP
1 /* Copyright 2016 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 /* Macros for memory management. */
8
9 #ifndef BROTLI_ENC_MEMORY_H_
10 #define BROTLI_ENC_MEMORY_H_cxx . . $ `c/enc/memory.h:10:9`!
11
12 #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/
13
14 #if defined(__cplusplus) || defined(c_plusplus)
15 extern "C" {
16 #endif
17
18 #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
19 !defined(BROTLI_ENCODER_EXIT_ON_OOM)
20 #define BROTLI_ENCODER_EXIT_ON_OOMcxx . . $ `c/enc/memory.h:20:9`!
21 #endif
22
23 #if !defined(BROTLI_ENCODER_EXIT_ON_OOMcxx . . $ `c/enc/memory.h:20:9`!)
24 #if defined(BROTLI_EXPERIMENTAL)
25 #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS (48*1024)
26 #else /* BROTLI_EXPERIMENTAL */
27 #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
28 #endif /* BROTLI_EXPERIMENTAL */
29 #else /* BROTLI_ENCODER_EXIT_ON_OOM */
30 #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTScxx . . $ `c/enc/memory.h:30:9`! 0
31 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
32
33 typedef struct MemoryManagercxx . . $ MemoryManager# {
34 brotli_alloc_funccxx . . $ brotli_alloc_func# alloc_funccxx . . $ MemoryManager#alloc_func.;
35 brotli_free_funccxx . . $ brotli_free_func# free_funccxx . . $ MemoryManager#free_func.;
36 void* opaquecxx . . $ MemoryManager#opaque.;
37 #if !defined(BROTLI_ENCODER_EXIT_ON_OOMcxx . . $ `c/enc/memory.h:20:9`!)
38 BROTLI_BOOL is_oom;
39 size_t perm_allocated;
40 size_t new_allocated;
41 size_t new_freed;
42 void* pointers[BROTLI_ENCODER_MEMORY_MANAGER_SLOTS];
43 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
44 } MemoryManagercxx . . $ MemoryManager#;
45
46 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void BrotliInitMemoryManagercxx . . $ BrotliInitMemoryManager(ac4371077d97fb6d).(
47 MemoryManagercxx . . $ MemoryManager#* m, brotli_alloc_funccxx . . $ brotli_alloc_func# alloc_func, brotli_free_funccxx . . $ brotli_free_func# free_func,
48 void* opaque);
49
50 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void* BrotliAllocatecxx . . $ BrotliAllocate(3a5baae79ae3d3c0).(MemoryManagercxx . . $ MemoryManager#* m, size_t n);
51 #define BROTLI_ALLOCcxx . . $ `c/enc/memory.h:51:9`!(M, T, N) \
52 ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)
53
54 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void BrotliFreecxx . . $ BrotliFree(5538fcdac3b070fa).(MemoryManagercxx . . $ MemoryManager#* m, void* p);
55 #define BROTLI_FREEcxx . . $ `c/enc/memory.h:55:9`!(M, P) { \
56 BrotliFree((M), (P)); \
57 P = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; \
58 }
59
60 #if defined(BROTLI_ENCODER_EXIT_ON_OOMcxx . . $ `c/enc/memory.h:20:9`!)
61 #define BROTLI_IS_OOMcxx . . $ `c/enc/memory.h:61:9`!(M) (!!0)
62 #else /* BROTLI_ENCODER_EXIT_ON_OOM */
63 #define BROTLI_IS_OOM(M) (!!(M)->is_oom)
64 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
65
66 /*
67 BROTLI_IS_NULL is a fake check, BROTLI_IS_OOM does the heavy lifting.
68 The only purpose of it is to explain static analyzers the state of things.
69 NB: use ONLY together with BROTLI_IS_OOM
70 AND ONLY for allocations in the current scope.
71 */
72 #if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOMcxx . . $ `c/enc/memory.h:20:9`!)
73 #define BROTLI_IS_NULL(A) ((A) == nullptr)
74 #else /* defined(__clang_analyzer__) */
75 #define BROTLI_IS_NULLcxx . . $ `c/enc/memory.h:75:9`!(A) (!!0)
76 #endif /* defined(__clang_analyzer__) */
77
78 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void BrotliWipeOutMemoryManagercxx . . $ BrotliWipeOutMemoryManager(9576d646167720e4).(MemoryManagercxx . . $ MemoryManager#* m);
79
80 /*
81 Dynamically grows array capacity to at least the requested size
82 M: MemoryManager
83 T: data type
84 A: array
85 C: capacity
86 R: requested size
87 */
88 #define BROTLI_ENSURE_CAPACITYcxx . . $ `c/enc/memory.h:88:9`!(M, T, A, C, R) { \
89 if (C < (R)) { \
90 size_t _new_size = (C == 0) ? (R) : C; \
91 T* new_array; \
92 while (_new_size < (R)) _new_size *= 2; \
93 new_array = BROTLI_ALLOC((M), T, _new_size); \
94 if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
95 memcpy(new_array, A, C * sizeof(T)); \
96 BROTLI_FREE((M), A); \
97 A = new_array; \
98 C = _new_size; \
99 } \
100 }
101
102 /*
103 Appends value and dynamically grows array capacity when needed
104 M: MemoryManager
105 T: data type
106 A: array
107 C: array capacity
108 S: array size
109 V: value to append
110 */
111 #define BROTLI_ENSURE_CAPACITY_APPENDcxx . . $ `c/enc/memory.h:111:9`!(M, T, A, C, S, V) { \
112 (S)++; \
113 BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \
114 A[(S) - 1] = (V); \
115 }
116
117 /* "Bootstrap" allocations are not tracked by memory manager; should be used
118 only to allocate MemoryManager itself (or structure containing it). */
119 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void* BrotliBootstrapAlloccxx . . $ BrotliBootstrapAlloc(a675a088e02e999).(size_t size,
120 brotli_alloc_funccxx . . $ brotli_alloc_func# alloc_func, brotli_free_funccxx . . $ brotli_free_func# free_func, void* opaque);
121 BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void BrotliBootstrapFreecxx . . $ BrotliBootstrapFree(d05455272567872a).(void* address, MemoryManagercxx . . $ MemoryManager#* m);
122
123 #if defined(__cplusplus) || defined(c_plusplus)
124 } /* extern "C" */
125 #endif
126
127 #endif /* BROTLI_ENC_MEMORY_H_ */