Index: third_party/brotli/enc/memory.h |
diff --git a/third_party/brotli/dec/bit_reader.c b/third_party/brotli/enc/memory.h |
similarity index 17% |
copy from third_party/brotli/dec/bit_reader.c |
copy to third_party/brotli/enc/memory.h |
index cde90af56e4f72cb4b30087f4456f689c5d217eb..eea91a97031a4ef6dcba4a5a8e98113032c537ca 100644 |
--- a/third_party/brotli/dec/bit_reader.c |
+++ b/third_party/brotli/enc/memory.h |
@@ -1,48 +1,62 @@ |
-/* Copyright 2013 Google Inc. All Rights Reserved. |
+/* Copyright 2016 Google Inc. All Rights Reserved. |
Distributed under MIT license. |
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
*/ |
-/* Bit reading helpers */ |
+/* Macros for memory management. */ |
-#include "./bit_reader.h" |
+#ifndef BROTLI_ENC_MEMORY_H_ |
+#define BROTLI_ENC_MEMORY_H_ |
+#include <brotli/types.h> |
#include "./port.h" |
-#include "./types.h" |
#if defined(__cplusplus) || defined(c_plusplus) |
extern "C" { |
#endif |
-void BrotliInitBitReader(BrotliBitReader* const br) { |
- br->val_ = 0; |
- br->bit_pos_ = sizeof(br->val_) << 3; |
-} |
+#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \ |
+ !defined(BROTLI_ENCODER_EXIT_ON_OOM) |
+#define BROTLI_ENCODER_EXIT_ON_OOM |
+#endif |
-int BrotliWarmupBitReader(BrotliBitReader* const br) { |
- size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1; |
- /* Fixing alignment after unaligned BrotliFillWindow would result accumulator |
- overflow. If unalignment is caused by BrotliSafeReadBits, then there is |
- enough space in accumulator to fix aligment. */ |
- if (!BROTLI_ALIGNED_READ) { |
- aligned_read_mask = 0; |
- } |
- if (BrotliGetAvailableBits(br) == 0) { |
- if (!BrotliPullByte(br)) { |
- return 0; |
- } |
- } |
- |
- while ((((size_t)br->next_in) & aligned_read_mask) != 0) { |
- if (!BrotliPullByte(br)) { |
- /* If we consumed all the input, we don't care about the alignment. */ |
- return 1; |
- } |
- } |
- return 1; |
+typedef struct MemoryManager { |
+ brotli_alloc_func alloc_func; |
+ brotli_free_func free_func; |
+ void* opaque; |
+#if !defined(BROTLI_ENCODER_EXIT_ON_OOM) |
+ BROTLI_BOOL is_oom; |
+ size_t perm_allocated; |
+ size_t new_allocated; |
+ size_t new_freed; |
+ void* pointers[256]; |
+#endif /* BROTLI_ENCODER_EXIT_ON_OOM */ |
+} MemoryManager; |
+ |
+BROTLI_INTERNAL void BrotliInitMemoryManager( |
+ MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func, |
+ void* opaque); |
+ |
+BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n); |
+#define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T))) |
+ |
+BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p); |
+#define BROTLI_FREE(M, P) { \ |
+ BrotliFree((M), (P)); \ |
+ P = NULL; \ |
} |
+#if defined(BROTLI_ENCODER_EXIT_ON_OOM) |
+#define BROTLI_IS_OOM(M) (!!0) |
+#else /* BROTLI_ENCODER_EXIT_ON_OOM */ |
+#define BROTLI_IS_OOM(M) (!!(M)->is_oom) |
+#endif /* BROTLI_ENCODER_EXIT_ON_OOM */ |
+ |
+BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m); |
+ |
#if defined(__cplusplus) || defined(c_plusplus) |
} /* extern "C" */ |
#endif |
+ |
+#endif /* BROTLI_ENC_MEMORY_H_ */ |