| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef CORE_FXCRT_INCLUDE_FX_MEMORY_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_MEMORY_H_ |
| 8 #define CORE_FXCRT_INCLUDE_FX_MEMORY_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_MEMORY_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_system.h" | 10 #include "core/fxcrt/include/fx_system.h" |
| 11 | 11 |
| 12 #ifdef __cplusplus | 12 #ifdef __cplusplus |
| 13 extern "C" { | 13 extern "C" { |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 // For external C libraries to malloc through PDFium. These may return nullptr. | 16 // For external C libraries to malloc through PDFium. These may return nullptr. |
| 17 void* FXMEM_DefaultAlloc(size_t byte_size, int flags); | 17 void* FXMEM_DefaultAlloc(size_t byte_size, int flags); |
| 18 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); | 18 void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); |
| 19 void FXMEM_DefaultFree(void* pointer, int flags); | 19 void FXMEM_DefaultFree(void* pointer, int flags); |
| 20 | 20 |
| 21 #ifdef __cplusplus | 21 #ifdef __cplusplus |
| 22 } // extern "C" | 22 } // extern "C" |
| 23 | 23 |
| 24 #include <stdlib.h> | 24 #include <stdlib.h> |
| 25 #include <limits> | 25 #include <limits> |
| 26 #include <memory> |
| 26 #include <new> | 27 #include <new> |
| 27 | 28 |
| 28 NEVER_INLINE void FX_OutOfMemoryTerminate(); | 29 NEVER_INLINE void FX_OutOfMemoryTerminate(); |
| 29 | 30 |
| 30 inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { | 31 inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { |
| 31 if (num_members < std::numeric_limits<size_t>::max() / member_size) { | 32 if (num_members < std::numeric_limits<size_t>::max() / member_size) { |
| 32 return realloc(ptr, num_members * member_size); | 33 return realloc(ptr, num_members * member_size); |
| 33 } | 34 } |
| 34 return nullptr; | 35 return nullptr; |
| 35 } | 36 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 struct FxFreeDeleter { | 94 struct FxFreeDeleter { |
| 94 inline void operator()(void* ptr) const { FX_Free(ptr); } | 95 inline void operator()(void* ptr) const { FX_Free(ptr); } |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 // Used with std::unique_ptr to Release() objects that can't be deleted. | 98 // Used with std::unique_ptr to Release() objects that can't be deleted. |
| 98 template <class T> | 99 template <class T> |
| 99 struct ReleaseDeleter { | 100 struct ReleaseDeleter { |
| 100 inline void operator()(T* ptr) const { ptr->Release(); } | 101 inline void operator()(T* ptr) const { ptr->Release(); } |
| 101 }; | 102 }; |
| 102 | 103 |
| 104 // Used to help transfer ownership of a raw pointer to std::unique_ptr. |
| 105 template <typename T> |
| 106 std::unique_ptr<T> WrapUnique(T* ptr) { |
| 107 return std::unique_ptr<T>(ptr); |
| 108 } |
| 109 |
| 103 class CFX_Deletable { | 110 class CFX_Deletable { |
| 104 public: | 111 public: |
| 105 virtual ~CFX_Deletable() {} | 112 virtual ~CFX_Deletable() {} |
| 106 }; | 113 }; |
| 107 | 114 |
| 108 #endif // __cplusplus | 115 #endif // __cplusplus |
| 109 | 116 |
| 110 #endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_ | 117 #endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_ |
| OLD | NEW |