diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index cc67c89..0b8f5e1 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -77,19 +77,19 @@ public: static const bool kNeedFree = true; void* Malloc(size_t size) { if (size) // behavior of malloc(0) is implementation defined. - return std::malloc(size); + return RAPIDJSON_MALLOC(size); else return NULL; // standardize to returning NULL. } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; if (newSize == 0) { - std::free(originalPtr); + RAPIDJSON_FREE(originalPtr); return NULL; } - return std::realloc(originalPtr, newSize); + return RAPIDJSON_REALLOC(originalPtr, newSize); } - static void Free(void *ptr) { std::free(ptr); } + static void Free(void *ptr) { RAPIDJSON_FREE(ptr); } }; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 329ce92..c5f4d65 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -639,6 +639,22 @@ RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_ASSERT_THROWS #endif // RAPIDJSON_NOEXCEPT_ASSERT +/////////////////////////////////////////////////////////////////////////////// +// malloc/realloc/free + +#ifndef RAPIDJSON_MALLOC +///! customization point for global \c malloc +#define RAPIDJSON_MALLOC(size) std::malloc(size) +#endif +#ifndef RAPIDJSON_REALLOC +///! customization point for global \c realloc +#define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size) +#endif +#ifndef RAPIDJSON_FREE +///! customization point for global \c free +#define RAPIDJSON_FREE(ptr) std::free(ptr) +#endif + /////////////////////////////////////////////////////////////////////////////// // new/delete