]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virerror: Make it easier to add new error number
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 9 Jan 2020 08:53:31 +0000 (09:53 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 10 Jan 2020 12:53:32 +0000 (13:53 +0100)
In v5.0.0-rc1~94 we switched from one huge switch() to an array
for translating error numbers into error messages. However, the
array is declared to have VIR_ERR_NUMBER_LAST items which makes
it impossible to spot this place by compile checking when adding
new error number.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
scripts/apibuild.py
src/util/virerror.c

index 2f7314b379a7ba98dbe95a831fa420796e604053..05a169c30d794d817be95e8935c28f34a804c216 100755 (executable)
@@ -1657,6 +1657,13 @@ class CParser:
                 token = ("name", "virloginit")
             return token
 
+        elif token[0] == "name" and token[1] == "G_STATIC_ASSERT":
+            # skip whole line
+            while token is not None and not (token[0] == "sep" and
+                                             token[1] == ";"):
+                token = self.token()
+            return self.token()
+
         elif token[0] == "name":
             if self.type == "":
                 self.type = token[1]
index fd2f77329f12675d5e2022f5a6333398e58184ac..aac6ee359723d91299bbf172232669c166e2c8e1 100644 (file)
@@ -910,7 +910,7 @@ typedef struct {
 } virErrorMsgTuple;
 
 
-const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
+static const virErrorMsgTuple virErrorMsgStrings[] = {
     [VIR_ERR_OK] = { NULL, NULL },
     [VIR_ERR_INTERNAL_ERROR] = {
         N_("internal error"),
@@ -1235,6 +1235,8 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] = {
         N_("network port not found: %s") },
 };
 
+G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) == VIR_ERR_NUMBER_LAST);
+
 
 /**
  * virErrorMsg: