mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Add cJSON_Allocators new style allocator struct
This commit is contained in:
@ -33,11 +33,11 @@ void reset(cJSON *item) {
|
||||
}
|
||||
if ((item->valuestring != NULL) && !(item->type & cJSON_IsReference))
|
||||
{
|
||||
global_configuration.deallocate(item->valuestring);
|
||||
global_configuration.allocators.deallocate(item->valuestring, global_configuration.userdata);
|
||||
}
|
||||
if ((item->string != NULL) && !(item->type & cJSON_StringIsConst))
|
||||
{
|
||||
global_configuration.deallocate(item->string);
|
||||
global_configuration.allocators.deallocate(item->string, global_configuration.userdata);
|
||||
}
|
||||
|
||||
memset(item, 0, sizeof(cJSON));
|
||||
|
@ -410,16 +410,18 @@ static void cjson_functions_shouldnt_crash_with_null_pointers(void)
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
|
||||
static void *failing_realloc(void *pointer, size_t size)
|
||||
static void *failing_realloc(void *pointer, size_t size, void *userdata)
|
||||
{
|
||||
(void)size;
|
||||
(void)pointer;
|
||||
(void)userdata;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ensure_should_fail_on_failed_realloc(void)
|
||||
{
|
||||
printbuffer buffer = {NULL, 10, 0, 0, false, {256, false, true, true, &malloc, &free, &failing_realloc}};
|
||||
printbuffer buffer = {NULL, 10, 0, 0, false, {256, false, true, true, {global_allocate_wrapper, global_deallocate_wrapper, failing_realloc}, NULL } };
|
||||
buffer.configuration.userdata = &buffer;
|
||||
buffer.buffer = (unsigned char*)malloc(100);
|
||||
TEST_ASSERT_NOT_NULL(buffer.buffer);
|
||||
|
||||
|
@ -53,7 +53,7 @@ static void assert_parse_string(const char *string, const char *expected)
|
||||
TEST_ASSERT_TRUE_MESSAGE(parse_string(item, &buffer), "Couldn't parse string.");
|
||||
assert_is_string(item);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, item->valuestring, "The parsed result isn't as expected.");
|
||||
global_configuration.deallocate(item->valuestring);
|
||||
global_configuration.allocators.deallocate(item->valuestring, global_configuration.userdata);
|
||||
item->valuestring = NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user