mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 00:45:18 +00:00
maint: enforce use of _LAST marker
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.
This commit is contained in:
parent
7b4e5693c1
commit
bb69630b6c
13
cfg.mk
13
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
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user