From nobody Sun Feb 8 13:32:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554738534604363.1627275379527; Mon, 8 Apr 2019 08:48:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B8B68124D; Mon, 8 Apr 2019 15:48:52 +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 41A585C666; Mon, 8 Apr 2019 15:48:52 +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 0072C41F3E; Mon, 8 Apr 2019 15:48:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x38FmdnH024582 for ; Mon, 8 Apr 2019 11:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF24C5DA2C; Mon, 8 Apr 2019 15:48:39 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-126-26.rdu2.redhat.com [10.10.126.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9F1B5D9C9; Mon, 8 Apr 2019 15:48:35 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Mon, 8 Apr 2019 11:48:18 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] util: Add 'label' field to VIR_ENUM_IMPL 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 08 Apr 2019 15:48:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This allows us to raise error messages from virEnum*String functions. FromString failure will report this error for value 'zzzz' invalid argument: Unknown 'domain type' value 'zzzz' ToString failure will report this error for unknown type=3D83 internal error: Unknown 'domain type' internal value '83' However we disable the error reporting for now. It should only be enabled when we decide to begin dropping duplicate error reporting. Note: this patch will be combined with the next patch when pushing Signed-off-by: Cole Robinson --- docs/apibuild.py | 12 ++++++++++++ src/util/virenum.c | 22 ++++++++++++++++++---- src/util/virenum.h | 15 ++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 9e04871220..1450355eeb 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -1404,6 +1404,18 @@ class CParser: self.error("parsing VIR_ENUM_IMPL: expecting ','", token) token =3D self.token() =20 + # The 'label' field + if token[0] !=3D "string": + self.error("parsing VIR_ENUM_IMPL: expecting string", token) + token =3D self.token() + + if token[0] !=3D "sep": + self.error("parsing VIR_ENUM_IMPL: expecting ','", token) + + if token[1] !=3D ',': + self.error("parsing VIR_ENUM_IMPL: expecting ','", token) + token =3D self.token() + # Now the sentinel name if token[0] !=3D "name": self.error("parsing VIR_ENUM_IMPL: expecting name", token) diff --git a/src/util/virenum.c b/src/util/virenum.c index 26093bd795..58968e7357 100644 --- a/src/util/virenum.c +++ b/src/util/virenum.c @@ -60,16 +60,23 @@ virTristateSwitchFromBool(bool val) int virEnumFromString(const char * const *types, unsigned int ntypes, - const char *type) + const char *type, + const char *label ATTRIBUTE_UNUSED) { size_t i; if (!type) - return -1; + goto error; =20 for (i =3D 0; i < ntypes; i++) if (STREQ(types[i], type)) return i; =20 + error: + /* To be enabled at a later date + * + * virReportError(VIR_ERR_INVALID_ARG, + * _("Unknown '%s' value '%s'"), label, NULLSTR(type)); + */ return -1; } =20 @@ -77,10 +84,17 @@ virEnumFromString(const char * const *types, const char * virEnumToString(const char * const *types, unsigned int ntypes, - int type) + int type, + const char *label ATTRIBUTE_UNUSED) { - if (type < 0 || type >=3D ntypes) + if (type < 0 || type >=3D ntypes) { + /* To be enabled at a later date + * + * virReportError(VIR_ERR_INTERNAL_ERROR, + * _("Unknown '%s' internal value %d"), label, type= ); + */ return NULL; + } =20 return types[type]; } diff --git a/src/util/virenum.h b/src/util/virenum.h index 3ae1a70b72..2c68e7f6a0 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -24,24 +24,29 @@ int virEnumFromString(const char * const *types, unsigned int ntypes, - const char *type); + const char *type, + const char *label); =20 const char * virEnumToString(const char * const *types, unsigned int ntypes, - int type); + int type, + const char *label); =20 -# define VIR_ENUM_IMPL(name, lastVal, ...) \ +# define VIR_ENUM_IMPL(name, label, lastVal, ...) \ + static const char *name ## TypeLabel =3D label; \ static const char *const name ## TypeList[] =3D { __VA_ARGS__ }; \ const char *name ## TypeToString(int type) { \ return virEnumToString(name ## TypeList, \ ARRAY_CARDINALITY(name ## TypeList), \ - type); \ + type, \ + name ## TypeLabel); \ } \ int name ## TypeFromString(const char *type) { \ return virEnumFromString(name ## TypeList, \ ARRAY_CARDINALITY(name ## TypeList), \ - type); \ + type, \ + name ## TypeLabel); \ } \ verify(ARRAY_CARDINALITY(name ## TypeList) =3D=3D lastVal) =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list