]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: enforce use of _LAST marker
authorEric Blake <eblake@redhat.com>
Fri, 20 Jan 2012 21:00:58 +0000 (14:00 -0700)
committerEric Blake <eblake@redhat.com>
Fri, 20 Jan 2012 23:16:04 +0000 (16:16 -0700)
When converting a linear enum to a string, we have checks in
place in the VIR_ENUM_IMPL macro to ensure that there is one
string for every value, which lets us quickly flag if a user
added a value but forgot to add a counterpart string.  However,
this only works if we use the _LAST marker.

* cfg.mk (sc_require_enum_last_marker): New syntax check.
* src/conf/domain_conf.h (virDomainSnapshotState): Add new marker.
* src/conf/domain_conf.c (virDomainSnapshotState): Fix offender.
* src/qemu/qemu_monitor_json.c (qemuMonitorWatchdogAction)
(qemuMonitorIOErrorAction, qemuMonitorGraphicsAddressFamily):
Likewise.
* src/util/virtypedparam.c (virTypedParameter): Likewise.

cfg.mk
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_monitor_json.c
src/util/virtypedparam.c

diff --git a/cfg.mk b/cfg.mk
index 817b5f31f9bcc1ad4ab0f6b4497f63acb30f03c2..20a085ec75db73684d94907bed21facd8a73fd4f 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1,5 +1,5 @@
 # Customize Makefile.maint.                           -*- makefile -*-
-# Copyright (C) 2008-2011 Red Hat, Inc.
+# Copyright (C) 2008-2012 Red Hat, Inc.
 # Copyright (C) 2003-2008 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
@@ -610,6 +610,17 @@ sc_prohibit_gettext_markup:
        halt='do not mark these strings for translation'                \
          $(_sc_search_regexp)
 
+# When converting an enum to a string, make sure that we track any new
+# elements added to the enum by using a _LAST marker.
+sc_require_enum_last_marker:
+       @grep -A1 -nE '^[^#]*VIR_ENUM_IMPL *\(' $$($(VC_LIST_EXCEPT))   \
+          | sed -ne '/VIR_ENUM_IMPL[^,]*,$$/N'                         \
+            -e '/VIR_ENUM_IMPL[^,]*,[^,]*[^_,][^L,][^A,][^S,][^T,],/p' \
+            -e '/VIR_ENUM_IMPL[^,]*,[^,]\{0,4\},/p'                    \
+          | grep . &&                                                  \
+         { echo '$(ME): enum impl needs to use _LAST marker' 1>&2;     \
+           exit 1; } || :
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
 
index f97014eef47e71489ef9b5a5e41d5f7ccb74db0c..8eed85b61a2e8ceb84d66b85e392cedaf07c1abe 100644 (file)
@@ -500,7 +500,7 @@ VIR_ENUM_IMPL(virDomainState, VIR_DOMAIN_LAST,
               "crashed")
 
 /* virDomainSnapshotState is really virDomainState plus one extra state */
-VIR_ENUM_IMPL(virDomainSnapshotState, VIR_DOMAIN_DISK_SNAPSHOT+1,
+VIR_ENUM_IMPL(virDomainSnapshotState, VIR_DOMAIN_SNAPSHOT_STATE_LAST,
               "nostate",
               "running",
               "blocked",
index b121f9c17ecc3f827e05af2ff0bfa3dd5355a6c8..a49795cdda330062d6aa03429f02861da3c2fd0e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * domain_conf.h: domain XML processing
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -328,6 +328,7 @@ enum virDomainDiskSnapshot {
 enum virDomainSnapshotState {
     /* Inherit the VIR_DOMAIN_* states from virDomainState.  */
     VIR_DOMAIN_DISK_SNAPSHOT = VIR_DOMAIN_LAST,
+    VIR_DOMAIN_SNAPSHOT_STATE_LAST
 };
 
 enum virDomainStartupPolicy {
index 7eb2a9219c2fb344d0715fd962426ebb1bcc776a..4a76fc03322d275a618defe0f086be9ee07fbac5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor_json.c: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -554,7 +554,7 @@ static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr d
 }
 
 VIR_ENUM_DECL(qemuMonitorWatchdogAction)
-VIR_ENUM_IMPL(qemuMonitorWatchdogAction, VIR_DOMAIN_EVENT_WATCHDOG_DEBUG + 1,
+VIR_ENUM_IMPL(qemuMonitorWatchdogAction, VIR_DOMAIN_EVENT_WATCHDOG_LAST,
               "none", "pause", "reset", "poweroff", "shutdown", "debug");
 
 static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr data)
@@ -576,7 +576,7 @@ static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr da
 }
 
 VIR_ENUM_DECL(qemuMonitorIOErrorAction)
-VIR_ENUM_IMPL(qemuMonitorIOErrorAction, VIR_DOMAIN_EVENT_IO_ERROR_REPORT + 1,
+VIR_ENUM_IMPL(qemuMonitorIOErrorAction, VIR_DOMAIN_EVENT_IO_ERROR_LAST,
               "ignore", "stop", "report");
 
 
@@ -619,7 +619,8 @@ static void qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr dat
 
 
 VIR_ENUM_DECL(qemuMonitorGraphicsAddressFamily)
-VIR_ENUM_IMPL(qemuMonitorGraphicsAddressFamily, VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_UNIX + 1,
+VIR_ENUM_IMPL(qemuMonitorGraphicsAddressFamily,
+              VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST,
               "ipv4", "ipv6", "unix");
 
 static void qemuMonitorJSONHandleVNC(qemuMonitorPtr mon, virJSONValuePtr data, int phase)
index f71aa25a06a4fd9aec3d86ec843c535f09008a57..48ee5d53d0386cc3933e7cbca0ed786c74ed22ba 100644 (file)
@@ -35,7 +35,7 @@
                              __FUNCTION__, __LINE__, __VA_ARGS__)
 
 VIR_ENUM_DECL(virTypedParameter)
-VIR_ENUM_IMPL(virTypedParameter, VIR_TYPED_PARAM_STRING + 1,
+VIR_ENUM_IMPL(virTypedParameter, VIR_TYPED_PARAM_LAST,
               "unknown",
               "int",
               "uint",