]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Create a json_pointer_private.h and move a few things there, fix test warnings, note...
authorEric Hawicz <erh+git@nimenees.com>
Sun, 16 Jul 2023 14:48:20 +0000 (10:48 -0400)
committerEric Hawicz <erh+git@nimenees.com>
Tue, 1 Aug 2023 02:18:03 +0000 (22:18 -0400)
CMakeLists.txt
json-c.sym
json_object_private.h
json_patch.c
json_pointer.c
json_pointer_private.h [new file with mode: 0644]
tests/test1.c
tests/test_json_patch.c

index 964c174cb99637fc1dfeefa622ed2681db80a3b2..64e1260363bc6f9f525deab62ae38778455cd8eb 100644 (file)
@@ -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
index 9b5933b250ba446136ef8efda33af9f9f4332862..15440bf2b47edd629b242f8743798e6865a59bce 100644 (file)
@@ -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;
index ff7bbef0a3338e0e3fd3896d4ae13a059108c03b..e143b4649acdd8e8815aab0fbed5e36506c95a9d 100644 (file)
@@ -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
index 296985c48fbcf9ee08956b57625c0c2dd7d8735d..97d9dd843c767f99df40acc035f0d90dff56f121 100644 (file)
@@ -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;
index 826025668a1e862e4f6dd684868229c5beb52136..e6e5f91b1c9f152ee6fc62b77f0c1f15e9252075 100644 (file)
@@ -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 (file)
index 0000000..40ec76d
--- /dev/null
@@ -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
index 986861b62bf4d19ea6ee9ce5a118b6629871d700..12097b21810eecf78afb5be1746742a0a19dfafc 100644 (file)
@@ -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();
index dad7521c801f1542f18017e9daa4438d526679cc..8dd593f6012854bedb2fc16e18f37d559d67b59a 100644 (file)
@@ -7,7 +7,9 @@
 #include <stdio.h>
 #include <string.h>
 
+#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);
        }