]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/BrotliCompress/enc/memory.h
BaseTools: Copy Brotli algorithm 3rd party source code for tool
[mirror_edk2.git] / BaseTools / Source / C / BrotliCompress / enc / memory.h
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_
11
12 #include "../common/types.h"
13 #include "./port.h"
14
15 #if defined(__cplusplus) || defined(c_plusplus)
16 extern "C" {
17 #endif
18
19 #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
20 !defined(BROTLI_ENCODER_EXIT_ON_OOM)
21 #define BROTLI_ENCODER_EXIT_ON_OOM
22 #endif
23
24 typedef struct MemoryManager {
25 brotli_alloc_func alloc_func;
26 brotli_free_func free_func;
27 void* opaque;
28 #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
29 BROTLI_BOOL is_oom;
30 size_t perm_allocated;
31 size_t new_allocated;
32 size_t new_freed;
33 void* pointers[256];
34 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
35 } MemoryManager;
36
37 BROTLI_INTERNAL void BrotliInitMemoryManager(
38 MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
39 void* opaque);
40
41 BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);
42 #define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T)))
43
44 BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
45 #define BROTLI_FREE(M, P) { \
46 BrotliFree((M), (P)); \
47 P = NULL; \
48 }
49
50 #if defined(BROTLI_ENCODER_EXIT_ON_OOM)
51 #define BROTLI_IS_OOM(M) (!!0)
52 #else /* BROTLI_ENCODER_EXIT_ON_OOM */
53 #define BROTLI_IS_OOM(M) (!!(M)->is_oom)
54 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
55
56 BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
57
58 #if defined(__cplusplus) || defined(c_plusplus)
59 } /* extern "C" */
60 #endif
61
62 #endif /* BROTLI_ENC_MEMORY_H_ */