mirror of
https://github.com/json-c/json-c.git
synced 2026-03-23 23:19:06 +08:00
Create a json_pointer_private.h and move a few things there, fix test warnings, note array_list_insert_idx is private.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
42
json_pointer_private.h
Normal file
42
json_pointer_private.h
Normal file
@@ -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
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user