+++ /dev/null
-/* Copyright 2016 Google Inc. All Rights Reserved.\r
-\r
- Distributed under MIT license.\r
- See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
-*/\r
-\r
-/* Macros for memory management. */\r
-\r
-#ifndef BROTLI_ENC_MEMORY_H_\r
-#define BROTLI_ENC_MEMORY_H_\r
-\r
-#include <string.h> /* memcpy */\r
-\r
-#include "../common/platform.h"\r
-#include <brotli/types.h>\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-extern "C" {\r
-#endif\r
-\r
-#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \\r
- !defined(BROTLI_ENCODER_EXIT_ON_OOM)\r
-#define BROTLI_ENCODER_EXIT_ON_OOM\r
-#endif\r
-\r
-typedef struct MemoryManager {\r
- brotli_alloc_func alloc_func;\r
- brotli_free_func free_func;\r
- void* opaque;\r
-#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)\r
- BROTLI_BOOL is_oom;\r
- size_t perm_allocated;\r
- size_t new_allocated;\r
- size_t new_freed;\r
- void* pointers[256];\r
-#endif /* BROTLI_ENCODER_EXIT_ON_OOM */\r
-} MemoryManager;\r
-\r
-BROTLI_INTERNAL void BrotliInitMemoryManager(\r
- MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,\r
- void* opaque);\r
-\r
-BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);\r
-#define BROTLI_ALLOC(M, T, N) \\r
- ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULL)\r
-\r
-BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);\r
-#define BROTLI_FREE(M, P) { \\r
- BrotliFree((M), (P)); \\r
- P = NULL; \\r
-}\r
-\r
-#if defined(BROTLI_ENCODER_EXIT_ON_OOM)\r
-#define BROTLI_IS_OOM(M) (!!0)\r
-#else /* BROTLI_ENCODER_EXIT_ON_OOM */\r
-#define BROTLI_IS_OOM(M) (!!(M)->is_oom)\r
-#endif /* BROTLI_ENCODER_EXIT_ON_OOM */\r
-\r
-BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);\r
-\r
-/*\r
-Dynamically grows array capacity to at least the requested size\r
-M: MemoryManager\r
-T: data type\r
-A: array\r
-C: capacity\r
-R: requested size\r
-*/\r
-#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \\r
- if (C < (R)) { \\r
- size_t _new_size = (C == 0) ? (R) : C; \\r
- T* new_array; \\r
- while (_new_size < (R)) _new_size *= 2; \\r
- new_array = BROTLI_ALLOC((M), T, _new_size); \\r
- if (!BROTLI_IS_OOM(M) && C != 0) \\r
- memcpy(new_array, A, C * sizeof(T)); \\r
- BROTLI_FREE((M), A); \\r
- A = new_array; \\r
- C = _new_size; \\r
- } \\r
-}\r
-\r
-/*\r
-Appends value and dynamically grows array capacity when needed\r
-M: MemoryManager\r
-T: data type\r
-A: array\r
-C: array capacity\r
-S: array size\r
-V: value to append\r
-*/\r
-#define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \\r
- (S)++; \\r
- BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \\r
- A[(S) - 1] = (V); \\r
-}\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-} /* extern "C" */\r
-#endif\r
-\r
-#endif /* BROTLI_ENC_MEMORY_H_ */\r