mirror of
https://github.com/kgabis/parson.git
synced 2024-11-24 06:05:29 +00:00
parent
1314bf8ad6
commit
3c4ee26dbb
@ -3,7 +3,7 @@ project(parson C)
|
||||
|
||||
include (GNUInstallDirs)
|
||||
|
||||
set(PARSON_VERSION 1.5.0)
|
||||
set(PARSON_VERSION 1.5.1)
|
||||
add_library(parson parson.c)
|
||||
target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
|
||||
|
4
Makefile
4
Makefile
@ -1,8 +1,8 @@
|
||||
CC = gcc
|
||||
CFLAGS = -O0 -g -Wall -Wextra -std=c89 -pedantic-errors -DTESTS_MAIN
|
||||
CFLAGS = -O0 -g -Wall -Wextra -Wno-deprecated-declarations -std=c89 -pedantic-errors -DTESTS_MAIN
|
||||
|
||||
CPPC = g++
|
||||
CPPFLAGS = -O0 -g -Wall -Wextra -DTESTS_MAIN
|
||||
CPPFLAGS = -O0 -g -Wall -Wextra -Wno-deprecated-declarations -DTESTS_MAIN
|
||||
|
||||
all: test testcpp test_hash_collisions
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
project('parson', 'c',
|
||||
version : '1.5.0',
|
||||
version : '1.5.1',
|
||||
license : 'MIT',
|
||||
meson_version : '>=0.46.0',
|
||||
default_options : [
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "parson",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"repo": "kgabis/parson",
|
||||
"description": "Small json parser and reader",
|
||||
"keywords": [ "json", "parser" ],
|
||||
|
13
parson.c
13
parson.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Parson 1.5.0 (https://github.com/kgabis/parson)
|
||||
Copyright (c) 2012 - 2022 Krzysztof Gabis
|
||||
Parson 1.5.1 (https://github.com/kgabis/parson)
|
||||
Copyright (c) 2012 - 2023 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
#define PARSON_IMPL_VERSION_MAJOR 1
|
||||
#define PARSON_IMPL_VERSION_MINOR 5
|
||||
#define PARSON_IMPL_VERSION_PATCH 0
|
||||
#define PARSON_IMPL_VERSION_PATCH 1
|
||||
|
||||
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\
|
||||
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
|
||||
@ -2274,9 +2274,15 @@ JSON_Status json_object_clear(JSON_Object *object) {
|
||||
}
|
||||
for (i = 0; i < json_object_get_count(object); i++) {
|
||||
parson_free(object->names[i]);
|
||||
object->names[i] = NULL;
|
||||
|
||||
json_value_free(object->values[i]);
|
||||
object->values[i] = NULL;
|
||||
}
|
||||
object->count = 0;
|
||||
for (i = 0; i < object->cell_capacity; i++) {
|
||||
object->cells[i] = OBJECT_INVALID_IX;
|
||||
}
|
||||
return JSONSuccess;
|
||||
}
|
||||
|
||||
@ -2445,6 +2451,7 @@ void json_set_escape_slashes(int escape_slashes) {
|
||||
void json_set_float_serialization_format(const char *format) {
|
||||
if (parson_float_format) {
|
||||
parson_free(parson_float_format);
|
||||
parson_float_format = NULL;
|
||||
}
|
||||
if (!format) {
|
||||
parson_float_format = NULL;
|
||||
|
8
parson.h
8
parson.h
@ -1,8 +1,8 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Parson 1.5.0 (https://github.com/kgabis/parson)
|
||||
Copyright (c) 2012 - 2022 Krzysztof Gabis
|
||||
Parson 1.5.1 (https://github.com/kgabis/parson)
|
||||
Copyright (c) 2012 - 2023 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -36,9 +36,9 @@ extern "C"
|
||||
|
||||
#define PARSON_VERSION_MAJOR 1
|
||||
#define PARSON_VERSION_MINOR 5
|
||||
#define PARSON_VERSION_PATCH 0
|
||||
#define PARSON_VERSION_PATCH 1
|
||||
|
||||
#define PARSON_VERSION_STRING "1.5.0"
|
||||
#define PARSON_VERSION_STRING "1.5.1"
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
|
28
tests.c
28
tests.c
@ -2,7 +2,7 @@
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Parson (https://github.com/kgabis/parson)
|
||||
Copyright (c) 2012 - 2022 Krzysztof Gabis
|
||||
Copyright (c) 2012 - 2023 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -64,6 +64,7 @@ void test_memory_leaks(void);
|
||||
void test_failing_allocations(void);
|
||||
void test_custom_number_format(void);
|
||||
void test_custom_number_serialization_function(void);
|
||||
void test_object_clear(void);
|
||||
|
||||
void print_commits_info(const char *username, const char *repo);
|
||||
void persistence_example(void);
|
||||
@ -134,6 +135,7 @@ int tests_main(int argc, char *argv[]) {
|
||||
test_failing_allocations();
|
||||
test_custom_number_format();
|
||||
test_custom_number_serialization_function();
|
||||
test_object_clear();
|
||||
|
||||
printf("Tests failed: %d\n", g_tests_failed);
|
||||
printf("Tests passed: %d\n", g_tests_passed);
|
||||
@ -691,20 +693,25 @@ void test_failing_allocations() {
|
||||
}
|
||||
}
|
||||
|
||||
json_set_allocation_functions(malloc, free);
|
||||
json_set_allocation_functions(counted_malloc, counted_free);
|
||||
printf("OK (tested %d failing allocations)\n", n - 1);
|
||||
g_tests_passed++;
|
||||
}
|
||||
|
||||
void test_custom_number_format() {
|
||||
g_malloc_count = 0;
|
||||
{
|
||||
char *serialized = NULL;
|
||||
JSON_Value *val = json_value_init_number(0.6);
|
||||
json_set_float_serialization_format("%.1f");
|
||||
serialized = json_serialize_to_string(val);
|
||||
json_set_float_serialization_format(NULL);
|
||||
TEST(STREQ(serialized, "0.6"));
|
||||
json_free_serialized_string(serialized);
|
||||
json_value_free(val);
|
||||
}
|
||||
TEST(g_malloc_count == 0);
|
||||
}
|
||||
|
||||
static int custom_serialization_func_called = 0;
|
||||
static int custom_serialization_func(double num, char *buf) {
|
||||
@ -716,6 +723,8 @@ static int custom_serialization_func(double num, char *buf) {
|
||||
}
|
||||
|
||||
void test_custom_number_serialization_function() {
|
||||
g_malloc_count = 0;
|
||||
{
|
||||
/* We just test that custom_serialization_func() gets called, not it's performance */
|
||||
char *serialized = NULL;
|
||||
JSON_Value *val = json_value_init_number(0.6);
|
||||
@ -727,6 +736,21 @@ void test_custom_number_serialization_function() {
|
||||
json_free_serialized_string(serialized);
|
||||
json_value_free(val);
|
||||
}
|
||||
TEST(g_malloc_count == 0);
|
||||
}
|
||||
|
||||
void test_object_clear() {
|
||||
g_malloc_count = 0;
|
||||
{
|
||||
JSON_Value *val = json_value_init_object();
|
||||
JSON_Object *obj = json_value_get_object(val);
|
||||
json_object_set_string(obj, "foo", "bar");
|
||||
json_object_clear(obj);
|
||||
TEST(json_object_get_value(obj, "foo") == NULL);
|
||||
json_value_free(val);
|
||||
}
|
||||
TEST(g_malloc_count == 0);
|
||||
}
|
||||
|
||||
void print_commits_info(const char *username, const char *repo) {
|
||||
JSON_Value *root_value;
|
||||
|
Loading…
Reference in New Issue
Block a user