api: upgrade cjson and fix realloc
Upgrade cJSON library to patchlevel 17. Replace internal realloc added earlier 36217e3ca. Type: fix Fixes: 36217e3ca Change-Id: I7d8a80dc4241e9f952895d24adca8fa2d873e746 Signed-off-by: Ole Troan <otroan@employees.org>
This commit is contained in:
parent
ee98c9dd8e
commit
4013851e42
@ -365,7 +365,7 @@ class FromJSON:
|
||||
write(" char *p = cJSON_GetStringValue(item);\n")
|
||||
write(" size_t plen = strlen(p);\n")
|
||||
write(
|
||||
" {msgvar} = cJSON_realloc({msgvar}, {msgsize} + plen, {msgsize});\n".format(
|
||||
" {msgvar} = cJSON_realloc({msgvar}, {msgsize} + plen);\n".format(
|
||||
msgvar=msgvar, msgsize=msgsize
|
||||
)
|
||||
)
|
||||
@ -434,7 +434,7 @@ class FromJSON:
|
||||
cJSON *array = cJSON_GetObjectItem(o, "{n}");
|
||||
int size = cJSON_GetArraySize(array);
|
||||
{lfield} = size;
|
||||
{realloc} = cJSON_realloc({realloc}, {msgsize} + sizeof({t}) * size, {msgsize});
|
||||
{realloc} = cJSON_realloc({realloc}, {msgsize} + sizeof({t}) * size);
|
||||
{t} *d = (void *){realloc} + {msgsize};
|
||||
{msgsize} += sizeof({t}) * size;
|
||||
for (i = 0; i < size; i++) {{
|
||||
@ -461,12 +461,12 @@ class FromJSON:
|
||||
|
||||
write(
|
||||
" {realloc} = cJSON_realloc({realloc}, {msgsize} + "
|
||||
"vec_len(s), {msgsize});\n".format(
|
||||
"vec_len(s));\n".format(
|
||||
msgvar=msgvar, msgsize=msgsize, realloc=realloc
|
||||
)
|
||||
)
|
||||
write(
|
||||
" memcpy((void *){realloc} + {msgsize}, s, "
|
||||
" clib_memcpy((void *){realloc} + {msgsize}, s, "
|
||||
"vec_len(s));\n".format(realloc=realloc, msgsize=msgsize)
|
||||
)
|
||||
write(" {msgsize} += vec_len(s);\n".format(msgsize=msgsize))
|
||||
|
@ -197,6 +197,7 @@ vlib_api_init (void)
|
||||
cJSON_Hooks cjson_hooks = {
|
||||
.malloc_fn = clib_mem_alloc,
|
||||
.free_fn = clib_mem_free,
|
||||
.realloc_fn = clib_mem_realloc,
|
||||
};
|
||||
cJSON_InitHooks (&cjson_hooks);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -81,7 +81,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 14
|
||||
#define CJSON_VERSION_PATCH 17
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@ -127,8 +127,7 @@ typedef struct cJSON_Hooks
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
void *(CJSON_CDECL *realloc_fn) (void *ptr, size_t new_size,
|
||||
size_t old_size);
|
||||
void *(CJSON_CDECL *realloc_fn) (void *ptr, size_t sz);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
@ -256,9 +255,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable adress area. */
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n')
|
||||
* from strings. The input pointer json cannot point to a read-only address
|
||||
* area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
@ -281,14 +281,21 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* If the object is not a boolean type this does nothing and returns
|
||||
* cJSON_Invalid else it returns the new type*/
|
||||
#define cJSON_SetBoolValue(object, boolValue) \
|
||||
((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) ? \
|
||||
(object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) | \
|
||||
((boolValue) ? cJSON_True : cJSON_False) : \
|
||||
cJSON_Invalid)
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
CJSON_PUBLIC (void *)
|
||||
cJSON_realloc (void *object, size_t new_size, size_t old_size);
|
||||
CJSON_PUBLIC (void *) cJSON_realloc (void *object, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user