Browse Source

Create a json_pointer_private.h and move a few things there, fix test warnings, note array_list_insert_idx is private.

tags/json-c-0.17-20230812
Eric Hawicz 2 years ago
parent
commit
efc530594b
8 changed files with 56 additions and 26 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +1
    -0
      json-c.sym
  3. +0
    -19
      json_object_private.h
  4. +4
    -3
      json_patch.c
  5. +1
    -0
      json_pointer.c
  6. +42
    -0
      json_pointer_private.h
  7. +2
    -1
      tests/test1.c
  8. +5
    -3
      tests/test_json_patch.c

+ 1
- 0
CMakeLists.txt View File

@@ -403,6 +403,7 @@ set(JSON_C_PUBLIC_HEADERS
set(JSON_C_HEADERS set(JSON_C_HEADERS
${JSON_C_PUBLIC_HEADERS} ${JSON_C_PUBLIC_HEADERS}
${PROJECT_SOURCE_DIR}/json_object_private.h ${PROJECT_SOURCE_DIR}/json_object_private.h
${PROJECT_SOURCE_DIR}/json_pointer_private.h
${PROJECT_SOURCE_DIR}/random_seed.h ${PROJECT_SOURCE_DIR}/random_seed.h
${PROJECT_SOURCE_DIR}/strerror_override.h ${PROJECT_SOURCE_DIR}/strerror_override.h
${PROJECT_SOURCE_DIR}/math_compat.h ${PROJECT_SOURCE_DIR}/math_compat.h


+ 1
- 0
json-c.sym View File

@@ -176,4 +176,5 @@ JSONC_0.16 {
JSONC_0.17 { JSONC_0.17 {
# global: # global:
# ...new symbols here... # ...new symbols here...
# array_list_insert_idx is intentionally not exported
} JSONC_0.16; } JSONC_0.16;

+ 0
- 19
json_object_private.h View File

@@ -100,25 +100,6 @@ void _json_c_set_last_err(const char *err_fmt, ...);


extern const char *json_hex_chars; 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 #ifdef __cplusplus
} }
#endif #endif


+ 4
- 3
json_patch.c View File

@@ -14,6 +14,7 @@


#include "json_patch.h" #include "json_patch.h"
#include "json_object_private.h" #include "json_object_private.h"
#include "json_pointer_private.h"


/** /**
* JavaScript Object Notation (JSON) Patch * 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, int json_patch_apply(struct json_object *base, struct json_object *patch,
struct json_object **res) struct json_object **res)
{ {
size_t i;
size_t ii;
int rc = 0; int rc = 0;


if (!base || !json_object_is_type(patch, json_type_array)) { 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; return -1;


/* Go through all operations ; apply them on res */ /* 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 *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; const char *op, *path;
if (!json_object_object_get_ex(patch_elem, "op", &jop)) { if (!json_object_object_get_ex(patch_elem, "op", &jop)) {
errno = EINVAL; errno = EINVAL;


+ 1
- 0
json_pointer.c View File

@@ -17,6 +17,7 @@


#include "json_object_private.h" #include "json_object_private.h"
#include "json_pointer.h" #include "json_pointer.h"
#include "json_pointer_private.h"
#include "strdup_compat.h" #include "strdup_compat.h"
#include "vasprintf_compat.h" #include "vasprintf_compat.h"




+ 42
- 0
json_pointer_private.h View 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

+ 2
- 1
tests/test1.c View File

@@ -189,9 +189,10 @@ void test_array_list_expand_internal(void)
json_object_put(my_array); json_object_put(my_array);
} }


void test_array_insert_idx(void);
void test_array_insert_idx() 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; struct json_object *jo1;


my_array = json_object_new_array(); my_array = json_object_new_array();


+ 5
- 3
tests/test_json_patch.c View File

@@ -7,7 +7,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>


#include "config.h"
#include "json.h" #include "json.h"
#include "snprintf_compat.h"


#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 256 #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]; char full_filename[PATH_MAX];
(void)snprintf(full_filename, sizeof(full_filename), "%s/%s", testdir, filename); (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); json_object *jo = json_object_from_file(full_filename);
if (!jo) { if (!jo) {
@@ -78,8 +80,8 @@ void test_json_patch_using_file(const char *testdir, const char *filename)
exit(EXIT_FAILURE); 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); test_json_patch_op(jo1);
} }




Loading…
Cancel
Save