Rename internal_hooks -> internal_configuration, cJSON_New_item -> create_item

This commit is contained in:
Max Bruckner
2018-01-31 22:22:53 +01:00
parent 3ebc06196a
commit 677f0cb1bb
12 changed files with 111 additions and 112 deletions

View File

@ -33,11 +33,11 @@ void reset(cJSON *item) {
}
if ((item->valuestring != NULL) && !(item->type & cJSON_IsReference))
{
global_hooks.deallocate(item->valuestring);
global_configuration.deallocate(item->valuestring);
}
if ((item->string != NULL) && !(item->type & cJSON_StringIsConst))
{
global_hooks.deallocate(item->string);
global_configuration.deallocate(item->string);
}
memset(item, 0, sizeof(cJSON));

View File

@ -10,8 +10,7 @@
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@ -432,7 +431,7 @@ static void skip_utf8_bom_should_skip_bom(void)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = string;
buffer.length = sizeof(string);
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_TRUE(skip_utf8_bom(&buffer) == &buffer);
TEST_ASSERT_EQUAL_UINT(3U, (unsigned int)buffer.offset);
@ -444,7 +443,7 @@ static void skip_utf8_bom_should_not_skip_bom_if_not_at_beginning(void)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = string;
buffer.length = sizeof(string);
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
buffer.offset = 1;
TEST_ASSERT_NULL(skip_utf8_bom(&buffer));
@ -512,7 +511,7 @@ static void cjson_add_item_to_object_should_not_use_after_free_when_string_is_al
{
cJSON *object = cJSON_CreateObject();
cJSON *number = cJSON_CreateNumber(42);
char *name = (char*)cJSON_strdup((const unsigned char*)"number", &global_hooks);
char *name = (char*)custom_strdup((const unsigned char*)"number", &global_configuration);
TEST_ASSERT_NOT_NULL(object);
TEST_ASSERT_NOT_NULL(number);

View File

@ -47,7 +47,7 @@ static void assert_not_array(const char *json)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*)json;
buffer.length = strlen(json) + sizeof("");
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_FALSE(parse_array(item, &buffer));
assert_is_invalid(item);
@ -58,7 +58,7 @@ static void assert_parse_array(const char *json)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*)json;
buffer.length = strlen(json) + sizeof("");
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_TRUE(parse_array(item, &buffer));
assert_is_array(item);

View File

@ -55,7 +55,7 @@ static void assert_not_object(const char *json)
parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
parsebuffer.content = (const unsigned char*)json;
parsebuffer.length = strlen(json) + sizeof("");
parsebuffer.hooks = global_hooks;
parsebuffer.configuration = global_configuration;
TEST_ASSERT_FALSE(parse_object(item, &parsebuffer));
assert_is_invalid(item);
@ -67,7 +67,7 @@ static void assert_parse_object(const char *json)
parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
parsebuffer.content = (const unsigned char*)json;
parsebuffer.length = strlen(json) + sizeof("");
parsebuffer.hooks = global_hooks;
parsebuffer.configuration = global_configuration;
TEST_ASSERT_TRUE(parse_object(item, &parsebuffer));
assert_is_object(item);

View File

@ -48,12 +48,12 @@ static void assert_parse_string(const char *string, const char *expected)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*)string;
buffer.length = strlen(string) + sizeof("");
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
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_hooks.deallocate(item->valuestring);
global_configuration.deallocate(item->valuestring);
item->valuestring = NULL;
}
@ -62,7 +62,7 @@ static void assert_not_parse_string(const char * const string)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*)string;
buffer.length = strlen(string) + sizeof("");
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_FALSE_MESSAGE(parse_string(item, &buffer), "Malformed string should not be accepted.");
assert_is_invalid(item);

View File

@ -46,7 +46,7 @@ static void assert_parse_value(const char *string, int type)
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
buffer.content = (const unsigned char*) string;
buffer.length = strlen(string) + sizeof("");
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_TRUE(parse_value(item, &buffer));
assert_is_value(item, type);

View File

@ -37,21 +37,21 @@ static void assert_print_array(const char * const expected, const char * const i
parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
parsebuffer.content = (const unsigned char*)input;
parsebuffer.length = strlen(input) + sizeof("");
parsebuffer.hooks = global_hooks;
parsebuffer.configuration = global_configuration;
/* buffer for formatted printing */
formatted_buffer.buffer = printed_formatted;
formatted_buffer.length = sizeof(printed_formatted);
formatted_buffer.offset = 0;
formatted_buffer.noalloc = true;
formatted_buffer.hooks = global_hooks;
formatted_buffer.configuration = global_configuration;
/* buffer for unformatted printing */
unformatted_buffer.buffer = printed_unformatted;
unformatted_buffer.length = sizeof(printed_unformatted);
unformatted_buffer.offset = 0;
unformatted_buffer.noalloc = true;
unformatted_buffer.hooks = global_hooks;
unformatted_buffer.configuration = global_configuration;
memset(item, 0, sizeof(item));
TEST_ASSERT_TRUE_MESSAGE(parse_array(item, &parsebuffer), "Failed to parse array.");

View File

@ -33,7 +33,7 @@ static void assert_print_number(const char *expected, double input)
buffer.length = sizeof(printed);
buffer.offset = 0;
buffer.noalloc = true;
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
memset(item, 0, sizeof(item));
cJSON_SetNumberValue(item, input);

View File

@ -38,21 +38,21 @@ static void assert_print_object(const char * const expected, const char * const
/* buffer for parsing */
parsebuffer.content = (const unsigned char*)input;
parsebuffer.length = strlen(input) + sizeof("");
parsebuffer.hooks = global_hooks;
parsebuffer.configuration = global_configuration;
/* buffer for formatted printing */
formatted_buffer.buffer = printed_formatted;
formatted_buffer.length = sizeof(printed_formatted);
formatted_buffer.offset = 0;
formatted_buffer.noalloc = true;
formatted_buffer.hooks = global_hooks;
formatted_buffer.configuration = global_configuration;
/* buffer for unformatted printing */
unformatted_buffer.buffer = printed_unformatted;
unformatted_buffer.length = sizeof(printed_unformatted);
unformatted_buffer.offset = 0;
unformatted_buffer.noalloc = true;
unformatted_buffer.hooks = global_hooks;
unformatted_buffer.configuration = global_configuration;
memset(item, 0, sizeof(item));
TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer), "Failed to parse object.");

View File

@ -32,7 +32,7 @@ static void assert_print_string(const char *expected, const char *input)
buffer.length = sizeof(printed);
buffer.offset = 0;
buffer.noalloc = true;
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
TEST_ASSERT_TRUE_MESSAGE(print_string_ptr((const unsigned char*)input, &buffer), "Failed to print string.");
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed, "The printed string isn't as expected.");

View File

@ -38,11 +38,11 @@ static void assert_print_value(const char *input)
buffer.length = sizeof(printed);
buffer.offset = 0;
buffer.noalloc = true;
buffer.hooks = global_hooks;
buffer.configuration = global_configuration;
parsebuffer.content = (const unsigned char*)input;
parsebuffer.length = strlen(input) + sizeof("");
parsebuffer.hooks = global_hooks;
parsebuffer.configuration = global_configuration;
memset(item, 0, sizeof(item));