From patchwork Mon Apr 8 15:48:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 161943 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3843791jan; Mon, 8 Apr 2019 08:48:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkXShK2y4eZH5lXP5S7T1/p4UJr2xLhq3PIyRFb4u2MQkTUXxm/6WoLX87KW0IyFumUy+M X-Received: by 2002:ac8:3f58:: with SMTP id w24mr25573067qtk.307.1554738534081; Mon, 08 Apr 2019 08:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554738534; cv=none; d=google.com; s=arc-20160816; b=TpYItcf7iFi1we3y2od9H3+CGWoCsWP4FzpTjcrFv9LKDt4jqr1L86niX7s9r/lvU5 VdDrMJcMqc9iMf/DjLp1htG0PkZnbdo4MRc5hnCt5YBi3/y7pFKXtaubkdSiVpJygq8c DJJ/wJpa91d0n0+XTNR+C4wPJOsBHxtw4BLDOslKLJsoHdqtcJQHBEgGgXVwaLBBMlsh 691yk8wpk6WYaGFbv2p+Ck1ERwPJzVJUfZPqjrJ7puR/9dE3GGMMyZr1E/x60o/OdOl7 Mkp/dhhtOlJ98RC2WOqIf733q3ub0ajuZqcmurNpI1clyFxpYnOuYYUavEFgDAQiYHIJ Obdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=rHyBeoaL+O4nFxadAmYUV2ur9b7csHW/r4XbV86zJ6I=; b=0ynCNtkhrG733VQ3rOx3ihCzkU6LRo70DwC3aW/KyZD/aFw8XQsHT574V3+8yF8ubn JdbKpUj3kXO2A8yFMVQk3S8EMRC0u/RELFYbJgs9B9v8fU87wQo9Y42Kol4ufU3G6dwz CMb46Vr642wIjZ7l0MgF05Sucor36j/EFIq6l+8d8+tfS8jUr3IjGbYLCOjD99sF8kd/ 9uK8oJWJyZx5mdenMN9WJWYic6UeD/ZQIb4w8diBM3qG4SU+3bwZk0nnsXAgUdtAkuXn m9TQv7jQOgYh59Sz2yQWKnCbA0gQ7tmob6IVa9AlIoGWdA1KYGet7FWnXgHyl1ZQLwoz bjIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 24si3917553qto.56.2019.04.08.08.48.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Apr 2019 08:48:54 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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) Delivered-To: libvirt-list@redhat.com 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: , 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) 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=83 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(-) -- 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list 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 = self.token() + # The 'label' field + if token[0] != "string": + self.error("parsing VIR_ENUM_IMPL: expecting string", token) + token = self.token() + + if token[0] != "sep": + self.error("parsing VIR_ENUM_IMPL: expecting ','", token) + + if token[1] != ',': + self.error("parsing VIR_ENUM_IMPL: expecting ','", token) + token = self.token() + # Now the sentinel name if token[0] != "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; for (i = 0; i < ntypes; i++) if (STREQ(types[i], type)) return i; + error: + /* To be enabled at a later date + * + * virReportError(VIR_ERR_INVALID_ARG, + * _("Unknown '%s' value '%s'"), label, NULLSTR(type)); + */ return -1; } @@ -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 >= ntypes) + if (type < 0 || type >= ntypes) { + /* To be enabled at a later date + * + * virReportError(VIR_ERR_INTERNAL_ERROR, + * _("Unknown '%s' internal value %d"), label, type); + */ return NULL; + } 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); const char * virEnumToString(const char * const *types, unsigned int ntypes, - int type); + int type, + const char *label); -# define VIR_ENUM_IMPL(name, lastVal, ...) \ +# define VIR_ENUM_IMPL(name, label, lastVal, ...) \ + static const char *name ## TypeLabel = label; \ static const char *const name ## TypeList[] = { __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) == lastVal)