|
@@ -23,9 +23,19 @@
|
|
/* cJSON */
|
|
/* cJSON */
|
|
/* JSON parser in C. */
|
|
/* JSON parser in C. */
|
|
|
|
|
|
|
|
+/* disable warnings about old C89 functions in MSVC */
|
|
|
|
+#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
|
|
|
|
+#define _CRT_SECURE_NO_DEPRECATE
|
|
|
|
+#endif
|
|
|
|
+
|
|
#ifdef __GNUC__
|
|
#ifdef __GNUC__
|
|
#pragma GCC visibility push(default)
|
|
#pragma GCC visibility push(default)
|
|
#endif
|
|
#endif
|
|
|
|
+#if defined(_MSC_VER)
|
|
|
|
+#pragma warning (push)
|
|
|
|
+/* disable warning about single line comments in system headers */
|
|
|
|
+#pragma warning (disable : 4001)
|
|
|
|
+#endif
|
|
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
@@ -36,6 +46,9 @@
|
|
#include <ctype.h>
|
|
#include <ctype.h>
|
|
#include <locale.h>
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
+#if defined(_MSC_VER)
|
|
|
|
+#pragma warning (pop)
|
|
|
|
+#endif
|
|
#ifdef __GNUC__
|
|
#ifdef __GNUC__
|
|
#pragma GCC visibility pop
|
|
#pragma GCC visibility pop
|
|
#endif
|
|
#endif
|
|
@@ -101,7 +114,27 @@ typedef struct internal_hooks
|
|
void *(*reallocate)(void *pointer, size_t size);
|
|
void *(*reallocate)(void *pointer, size_t size);
|
|
} internal_hooks;
|
|
} 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)
|
|
static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
|
|
{
|
|
{
|
|
@@ -114,7 +147,8 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h
|
|
}
|
|
}
|
|
|
|
|
|
length = strlen((const char*)string) + sizeof("");
|
|
length = strlen((const char*)string) + sizeof("");
|
|
- if (!(copy = (unsigned char*)hooks->allocate(length)))
|
|
|
|
|
|
+ copy = (unsigned char*)hooks->allocate(length);
|
|
|
|
+ if (copy == NULL)
|
|
{
|
|
{
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
@@ -1815,7 +1849,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSO
|
|
item->type &= ~cJSON_StringIsConst;
|
|
item->type &= ~cJSON_StringIsConst;
|
|
}
|
|
}
|
|
|
|
|
|
-#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
|
|
|
|
|
+#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic push
|
|
#endif
|
|
#endif
|
|
#ifdef __GNUC__
|
|
#ifdef __GNUC__
|
|
@@ -1837,7 +1871,7 @@ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJ
|
|
item->type |= cJSON_StringIsConst;
|
|
item->type |= cJSON_StringIsConst;
|
|
cJSON_AddItemToArray(object, item);
|
|
cJSON_AddItemToArray(object, item);
|
|
}
|
|
}
|
|
-#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
|
|
|
|
|
+#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
|
|
#pragma GCC diagnostic pop
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
#endif
|
|
|
|
|