From d1c2e2df4a7cddaae621d2d9c973fa8b8f6b672d Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 17 Jun 2017 14:33:04 +0200 Subject: [PATCH] MSVC: workaround for C2322 --- cJSON.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index e816cde..f6ee1ad 100644 --- a/cJSON.c +++ b/cJSON.c @@ -114,7 +114,27 @@ typedef struct internal_hooks void *(*reallocate)(void *pointer, size_t size); } internal_hooks; -static internal_hooks global_hooks = { malloc, free, realloc }; +#if defined(_MSC_VER) +/* work around MSVC error C2322: '...' address of dillimport '...' is not static */ +static void *internal_malloc(size_t size) +{ + return malloc(size); +} +static void internal_free(void *pointer) +{ + free(pointer); +} +static void *internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} +#else +#define internal_malloc malloc +#define internal_free free +#define internal_realloc realloc +#endif + +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) {