From nobody Mon Feb 9 06:26:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633620572; cv=none; d=zohomail.com; s=zohoarc; b=RpanDekPZIFmgRAbY++GlXtrOHvyGt7B04wqMqvTrdgTxWKCfmRga6kh+uzR9owcasfEG3lJwyDye+8uTDiK/JevRtsB6pfER5wBe8F8dhVsQTlwGa627VPrfr8cp8Vwjt7W/ayGviyfNLEfwLYTwe7B3uUxi+/KEugf3KTqHQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633620572; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WjG7fXfXSa9br+K7/zYtunO2q6GiANmwcwrhgQ3lxOI=; b=llbOfpemQKhh9wWqD+yh9RkkB15QW+BQjc2Xn8hHKGWgm5JLw3dgmD9mulCmBjRckhzA2edqCR2pgIWaKWTru7htuwBckC0sJwobwaSiSIQcJOMJWh7djBrLFuPiUvuy4Gy+APGUP/gPvWmXuOXVxBoX7QFiZ7QIrvepYa/Gkzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633620572241487.325788463089; Thu, 7 Oct 2021 08:29:32 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-Qv0Ui3iMOWaHGAIMafkwqg-1; Thu, 07 Oct 2021 11:29:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3DB1115B301; Thu, 7 Oct 2021 15:23:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45BF81F6; Thu, 7 Oct 2021 15:23:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F1C514EA30; Thu, 7 Oct 2021 15:23:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197FIYKY023493 for ; Thu, 7 Oct 2021 11:18:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8EFC05D6D5; Thu, 7 Oct 2021 15:18:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA4EF5D6BA for ; Thu, 7 Oct 2021 15:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633620571; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WjG7fXfXSa9br+K7/zYtunO2q6GiANmwcwrhgQ3lxOI=; b=cjS7aLaGFXf3YIhOx79Aw6FxRblmwi7k9RtjvwVvOOSB5HzjO32hWW6XwyNxp4BR1BVd55 Ksbcwgh6rPQXflxBrPGAc1PruV4kXxWF3PV9RSs3NcCgLmZ21NgBdL1Vj1rpXimaiNmlto kI+UTMAtbCYyDXzRyke8rjM+x9BJUw8= X-MC-Unique: Qv0Ui3iMOWaHGAIMafkwqg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 001/103] virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers Date: Thu, 7 Oct 2021 17:16:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633620573747100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko --- 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 =3D va_arg(args, int); @@ -200,7 +202,10 @@ virJSONValueObjectAddVArgs(virJSONValue *obj, return -1; } - if (!val && (type =3D=3D 'z' || type =3D=3D 'y')) + if (val =3D=3D 0 && (type =3D=3D 'z' || type =3D=3D 'y')) + continue; + + if (val < 0 && type =3D=3D 'k') continue; rc =3D virJSONValueObjectAppendNumberInt(obj, key, val); --=20 2.31.1