[PATCH 001/103] virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers

Ján Tomko jtomko at redhat.com
Thu Oct 7 15:33:00 UTC 2021


On a Thursday in 2021, Peter Krempa wrote:
>In many cases we use a signed value, but use the sign to note that it
>was not assigned. For converting to JSON objects it will be handy to
>have possibility to do this automatically.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/util/virjson.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
>diff --git a/src/util/virjson.c b/src/util/virjson.c
>index 9adcea4fff..70ea71b505 100644
>--- a/src/util/virjson.c
>+++ b/src/util/virjson.c
>@@ -115,6 +115,7 @@ virJSONValueGetType(const virJSONValue *value)
>  *
>  * i: signed integer value
>  * j: signed integer value, error if negative
>+ * k: signed integer value, omitted if negative
>  * z: signed integer value, omitted if zero
>  * y: signed integer value, omitted if zero, error if negative
>  *
>@@ -189,6 +190,7 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,
>
>         case 'z':
>         case 'y':
>+        case 'k':
>         case 'j':
>         case 'i': {
>             int val = va_arg(args, int);
>@@ -200,7 +202,10 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,
>                 return -1;
>             }
>
>-            if (!val && (type == 'z' || type == 'y'))
>+            if (val == 0 && (type == 'z' || type == 'y'))
>+                continue;
>+

Please split out this cosmetic style change.

>+            if (val < 0 && type == 'k')
>                 continue;
>

k.

I mean
Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20211007/090bdef8/attachment-0001.sig>


More information about the libvir-list mailing list