diff --git a/CMakeLists.txt b/CMakeLists.txt index 964c174..64e1260 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,6 +403,7 @@ set(JSON_C_PUBLIC_HEADERS set(JSON_C_HEADERS ${JSON_C_PUBLIC_HEADERS} ${PROJECT_SOURCE_DIR}/json_object_private.h + ${PROJECT_SOURCE_DIR}/json_pointer_private.h ${PROJECT_SOURCE_DIR}/random_seed.h ${PROJECT_SOURCE_DIR}/strerror_override.h ${PROJECT_SOURCE_DIR}/math_compat.h diff --git a/json-c.sym b/json-c.sym index 9b5933b..15440bf 100644 --- a/json-c.sym +++ b/json-c.sym @@ -176,4 +176,5 @@ JSONC_0.16 { JSONC_0.17 { # global: # ...new symbols here... +# array_list_insert_idx is intentionally not exported } JSONC_0.16; diff --git a/json_object_private.h b/json_object_private.h index ff7bbef..e143b46 100644 --- a/json_object_private.h +++ b/json_object_private.h @@ -100,25 +100,6 @@ void _json_c_set_last_err(const char *err_fmt, ...); extern const char *json_hex_chars; -struct json_pointer_get_result { - struct json_object *parent; - struct json_object *obj; - union { - const char *key; - uint32_t index; - } id; -}; - -int json_pointer_get_internal(struct json_object *obj, const char *path, - struct json_pointer_get_result *res); - -typedef int(*json_pointer_array_set_cb)(json_object *parent, size_t idx, - json_object *value, void *priv); - -int json_pointer_set_with_array_cb(struct json_object **obj, const char *path, - struct json_object *value, - json_pointer_array_set_cb array_set_cb, void *priv); - #ifdef __cplusplus } #endif diff --git a/json_patch.c b/json_patch.c index 296985c..97d9dd8 100644 --- a/json_patch.c +++ b/json_patch.c @@ -14,6 +14,7 @@ #include "json_patch.h" #include "json_object_private.h" +#include "json_pointer_private.h" /** * JavaScript Object Notation (JSON) Patch @@ -193,7 +194,7 @@ static int json_patch_apply_move_copy(struct json_object **res, int json_patch_apply(struct json_object *base, struct json_object *patch, struct json_object **res) { - size_t i; + size_t ii; int rc = 0; if (!base || !json_object_is_type(patch, json_type_array)) { @@ -206,9 +207,9 @@ int json_patch_apply(struct json_object *base, struct json_object *patch, return -1; /* Go through all operations ; apply them on res */ - for (i = 0; i < json_object_array_length(patch); i++) { + for (ii = 0; ii < json_object_array_length(patch); ii++) { struct json_object *jop, *jpath; - struct json_object *patch_elem = json_object_array_get_idx(patch, i); + struct json_object *patch_elem = json_object_array_get_idx(patch, ii); const char *op, *path; if (!json_object_object_get_ex(patch_elem, "op", &jop)) { errno = EINVAL; diff --git a/json_pointer.c b/json_pointer.c index 8260256..e6e5f91 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -17,6 +17,7 @@ #include "json_object_private.h" #include "json_pointer.h" +#include "json_pointer_private.h" #include "strdup_compat.h" #include "vasprintf_compat.h" diff --git a/json_pointer_private.h b/json_pointer_private.h new file mode 100644 index 0000000..40ec76d --- /dev/null +++ b/json_pointer_private.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Eric Hawicz + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See COPYING for details. + */ + +/** + * @file + * @brief Do not use, json-c internal, may be changed or removed at any time. + */ +#ifndef _json_pointer_private_h_ +#define _json_pointer_private_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct json_pointer_get_result { + struct json_object *parent; + struct json_object *obj; + union { + const char *key; + uint32_t index; + } id; +}; + +int json_pointer_get_internal(struct json_object *obj, const char *path, + struct json_pointer_get_result *res); + +typedef int(*json_pointer_array_set_cb)(json_object *parent, size_t idx, + json_object *value, void *priv); + +int json_pointer_set_with_array_cb(struct json_object **obj, const char *path, + struct json_object *value, + json_pointer_array_set_cb array_set_cb, void *priv); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tests/test1.c b/tests/test1.c index 986861b..12097b2 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -189,9 +189,10 @@ void test_array_list_expand_internal(void) json_object_put(my_array); } +void test_array_insert_idx(void); void test_array_insert_idx() { - json_object *my_string, *my_int, *my_null, *my_object, *my_array; + json_object *my_array; struct json_object *jo1; my_array = json_object_new_array(); diff --git a/tests/test_json_patch.c b/tests/test_json_patch.c index dad7521..8dd593f 100644 --- a/tests/test_json_patch.c +++ b/tests/test_json_patch.c @@ -7,7 +7,9 @@ #include #include +#include "config.h" #include "json.h" +#include "snprintf_compat.h" #ifndef PATH_MAX #define PATH_MAX 256 @@ -70,7 +72,7 @@ void test_json_patch_using_file(const char *testdir, const char *filename) { char full_filename[PATH_MAX]; (void)snprintf(full_filename, sizeof(full_filename), "%s/%s", testdir, filename); - int i; + size_t ii; json_object *jo = json_object_from_file(full_filename); if (!jo) { @@ -78,8 +80,8 @@ void test_json_patch_using_file(const char *testdir, const char *filename) exit(EXIT_FAILURE); } - for (i = 0; i < json_object_array_length(jo); i++) { - struct json_object *jo1 = json_object_array_get_idx(jo, i); + for (ii = 0; ii < json_object_array_length(jo); ii++) { + struct json_object *jo1 = json_object_array_get_idx(jo, ii); test_json_patch_op(jo1); }