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 | 12 +++++++++++-
src/conf/domain_conf.c | 2 +-
src/conf/domain_conf.h | 3 ++-
src/qemu/qemu_monitor_json.c | 9 +++++----
src/util/virtypedparam.c | 2 +-
5 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 817b5f3..95ba61c 100644
--- 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,16 @@ 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' \
+ | 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
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f97014e..8eed85b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b121f9c..a49795c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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 {
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7eb2a92..4a76fc0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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)
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index f71aa25..48ee5d5 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -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",
--
1.7.7.5