Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Yip <miloyip@gmail.com>2020-06-23 09:34:10 +0300
committerGitHub <noreply@github.com>2020-06-23 09:34:10 +0300
commit88bd956d66d348f478bceebfdadb8e26c6844695 (patch)
treed5934c4dda5fbff3d4e5786ffc71cd24ffb6745a
parent1a803826f1197b5e30703afe4b9c0e7dd48074f5 (diff)
parent004e8e61a0e721e1ac7785c955350ddf89cd2f24 (diff)
Merge pull request #1453 from eidosmontreal/custom_malloc
Adding a single customization point that ensures all allocations within rapidjson can be performed with a custom memory allocator
-rw-r--r--include/rapidjson/allocators.h8
-rw-r--r--include/rapidjson/rapidjson.h16
2 files changed, 20 insertions, 4 deletions
diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h
index cc67c897..0b8f5e14 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 329ce92b..c5f4d65f 100644
--- a/include/rapidjson/rapidjson.h
+++ b/include/rapidjson/rapidjson.h
@@ -640,6 +640,22 @@ RAPIDJSON_NAMESPACE_END
#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
#ifndef RAPIDJSON_NEW