On 7/1/22 13:11, Ilya Maximets wrote: > When reference counting for json objects was introduced the > old json_clone() function became json_deep_clone(), but it > still calls shallow json_clone() while cloning objects and > arrays not really producing a deep copy. > > Fixing that by making other functions to perform a deep copy > as well. There are no users for this functionality inside > OVS right now, but OVS exports this functionality externally. > > 'ovstest test-json' extended to test both versions of a clone > on provided inputs. > > Fixes: 9854d473adea ("json: Use reference counting in JSON objects") > Signed-off-by: Ilya Maximets <i.maxim...@ovn.org> > --- > lib/json.c | 16 +++--- > tests/test-json.c | 125 ++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 129 insertions(+), 12 deletions(-) > > diff --git a/lib/json.c b/lib/json.c > index 3267a6196..aded8bb01 100644 > --- a/lib/json.c > +++ b/lib/json.c > @@ -420,8 +420,8 @@ json_destroy_array(struct json_array *array) > free(array->elems); > } > > -static struct json *json_clone_object(const struct shash *object); > -static struct json *json_clone_array(const struct json_array *array); > +static struct json *json_deep_clone_object(const struct shash *object); > +static struct json *json_deep_clone_array(const struct json_array *array); > > /* Returns a deep copy of 'json'. */ > struct json * > @@ -429,10 +429,10 @@ json_deep_clone(const struct json *json) > { > switch (json->type) { > case JSON_OBJECT: > - return json_clone_object(json->object); > + return json_deep_clone_object(json->object); > > case JSON_ARRAY: > - return json_clone_array(&json->array); > + return json_deep_clone_array(&json->array); > > case JSON_STRING: > return json_string_create(json->string); > @@ -464,7 +464,7 @@ json_nullable_clone(const struct json *json) > } > > static struct json * > -json_clone_object(const struct shash *object) > +json_deep_clone_object(const struct shash *object) > { > struct shash_node *node; > struct json *json; > @@ -472,20 +472,20 @@ json_clone_object(const struct shash *object) > json = json_object_create(); > SHASH_FOR_EACH (node, object) { > struct json *value = node->data; > - json_object_put(json, node->name, json_clone(value)); > + json_object_put(json, node->name, json_deep_clone(value)); > } > return json; > } > > static struct json * > -json_clone_array(const struct json_array *array) > +json_deep_clone_array(const struct json_array *array) > { > struct json **elems; > size_t i; > > elems = xmalloc(array->n * sizeof *elems); > for (i = 0; i < array->n; i++) { > - elems[i] = json_clone(array->elems[i]); > + elems[i] = json_deep_clone(array->elems[i]); > } > return json_array_create(elems, array->n); > } > diff --git a/tests/test-json.c b/tests/test-json.c > index a2f4332e7..225badf70 100644 > --- a/tests/test-json.c > +++ b/tests/test-json.c > @@ -34,8 +34,124 @@ static int pretty = 0; > * instead of exactly one object or array. */ > static int multiple = 0; > > +
Nit: newline not really needed. > +static void test_json_equal(const struct json *a, const struct json *b, > + bool allow_the_same); > + Nit: not needed here either I think. Anyway, these can be fixed at apply time if you agree, the fix itself makes sense: Acked-by: Dumitru Ceara <dce...@redhat.com> Thanks, Dumitru _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev