You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace cJSON.[ch] with latest from official repo at https://github.com/DaveGamble/cJSON
Newer function cJSON_ParseWithOpts can be used instead of my own cJSON_Parse_Stream
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
38
+
39
+
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
40
+
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
41
+
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
42
+
43
+
For *nix builds that support visibility attribute, you can define similar behavior by
44
+
45
+
setting default visibility to hidden by adding
46
+
-fvisibility=hidden (for gcc)
47
+
or
48
+
-xldscope=hidden (for sun cc)
49
+
to CFLAGS
50
+
51
+
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
52
+
53
+
*/
54
+
55
+
#defineCJSON_CDECL __cdecl
56
+
#defineCJSON_STDCALL __stdcall
57
+
58
+
/* export symbols by default, this is necessary for copy pasting the C and header file */
#defineCJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
67
+
#elif defined(CJSON_IMPORT_SYMBOLS)
68
+
#defineCJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
69
+
#endif
70
+
#else/* !__WINDOWS__ */
71
+
#defineCJSON_CDECL
72
+
#defineCJSON_STDCALL
73
+
74
+
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
75
+
#defineCJSON_PUBLIC(type) __attribute__((visibility("default"))) type
76
+
#else
77
+
#defineCJSON_PUBLIC(type) type
78
+
#endif
79
+
#endif
80
+
81
+
/* project version */
82
+
#defineCJSON_VERSION_MAJOR 1
83
+
#defineCJSON_VERSION_MINOR 7
84
+
#defineCJSON_VERSION_PATCH 15
85
+
86
+
#include<stddef.h>
87
+
31
88
/* cJSON Types: */
32
-
#definecJSON_False 0
33
-
#definecJSON_True 1
34
-
#definecJSON_NULL 2
35
-
#definecJSON_Number 3
36
-
#definecJSON_String 4
37
-
#definecJSON_Array 5
38
-
#definecJSON_Object 6
39
-
89
+
#definecJSON_Invalid (0)
90
+
#definecJSON_False (1 << 0)
91
+
#definecJSON_True (1 << 1)
92
+
#definecJSON_NULL (1 << 2)
93
+
#definecJSON_Number (1 << 3)
94
+
#definecJSON_String (1 << 4)
95
+
#definecJSON_Array (1 << 5)
96
+
#definecJSON_Object (1 << 6)
97
+
#definecJSON_Raw (1 << 7) /* raw json */
98
+
40
99
#definecJSON_IsReference 256
100
+
#definecJSON_StringIsConst 512
41
101
42
102
/* The cJSON structure: */
43
-
typedefstructcJSON {
44
-
structcJSON*next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
45
-
structcJSON*child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
103
+
typedefstructcJSON
104
+
{
105
+
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
106
+
structcJSON*next;
107
+
structcJSON*prev;
108
+
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
109
+
structcJSON*child;
46
110
47
-
inttype; /* The type of the item, as above. */
111
+
/* The type of the item, as above. */
112
+
inttype;
48
113
49
-
char*valuestring; /* The item's string, if type==cJSON_String */
50
-
intvalueint; /* The item's number, if type==cJSON_Number */
51
-
doublevaluedouble; /* The item's number, if type==cJSON_Number */
114
+
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
115
+
char*valuestring;
116
+
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
117
+
intvalueint;
118
+
/* The item's number, if type==cJSON_Number */
119
+
doublevaluedouble;
52
120
53
-
char*string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
121
+
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
122
+
char*string;
54
123
} cJSON;
55
124
56
-
typedefstructcJSON_Hooks {
57
-
void*(*malloc_fn)(size_tsz);
58
-
void (*free_fn)(void*ptr);
125
+
typedefstructcJSON_Hooks
126
+
{
127
+
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
128
+
void*(CJSON_CDECL*malloc_fn)(size_tsz);
129
+
void (CJSON_CDECL*free_fn)(void*ptr);
59
130
} cJSON_Hooks;
60
131
132
+
typedefintcJSON_bool;
133
+
134
+
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
135
+
* This is to prevent stack overflows. */
136
+
#ifndefCJSON_NESTING_LIMIT
137
+
#defineCJSON_NESTING_LIMIT 1000
138
+
#endif
139
+
140
+
/* returns the version of cJSON as a string */
141
+
CJSON_PUBLIC(constchar*) cJSON_Version(void);
142
+
61
143
/* Supply malloc, realloc and free functions to cJSON */
62
-
externvoidcJSON_InitHooks(cJSON_Hooks*hooks);
63
-
64
-
65
-
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
66
-
externcJSON*cJSON_Parse(constchar*value);
67
-
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished.
68
-
* end_ptr will point to 1 past the end of the JSON object */
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
147
+
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
151
+
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
0 commit comments