On Wed, Nov 02, 2016 at 05:13:33PM +0100, Peter Krempa wrote: > Simplifies cases where JSON array members need to be transferred to a > different structure. > --- > > Notes: > v2: > - iterate from beginning > - add option to keep array member in the array without breaking iteration > - documented callback return codes > > src/libvirt_private.syms | 1 + > src/util/virjson.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ > src/util/virjson.h | 6 ++++++ > 3 files changed, 61 insertions(+) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index 162fda5..4c08508 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -1764,6 +1764,7 @@ virISCSIScanTargets; > > # util/virjson.h > virJSONValueArrayAppend; > +virJSONValueArrayForeachSteal; > virJSONValueArrayGet; > virJSONValueArraySize; > virJSONValueArraySteal; > diff --git a/src/util/virjson.c b/src/util/virjson.c > index 1d8e6d5..d55600a 100644 > --- a/src/util/virjson.c > +++ b/src/util/virjson.c > @@ -949,6 +949,60 @@ virJSONValueArraySteal(virJSONValuePtr array, > } > > > +/** > + * virJSONValueArrayForeachSteal: > + * @array: array to iterate > + * @cb: callback called on every member of the array > + * @opaque: custom data for the callback > + * > + * Iterates members of the array and calls the callback on every single member. > + * The return codes of the callback are interpreted as follows: > + * 0: callback claims ownership of the array element and is responsible for > + * freeing it Maybe mention that the iteration continues in this case too. > + * 1: callback does not claim the ownership, but the iteration continues > + * -1: callback doesn't claim ownership and iteration does not continue Just my OCD kicking in, use "does not" or "doesn't" in both cases :) > + * > + * Returns 0 if all members were iterated and/or stolen by the callback; -1 > + * on callback failure or if the JSON value object is not an array. > + * The rest of the members stay in possession of the array and it's condensed. > + */ > +int > +virJSONValueArrayForeachSteal(virJSONValuePtr array, > + virJSONArrayIteratorFunc cb, > + void *opaque) ACK
Attachment:
signature.asc
Description: Digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list