qapi: Don't let implicit enum MAX member collide

Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes.  Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.

This patch was mostly generated by applying a temporary patch:

|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
|     max_index = c_enum_const(name, 'MAX', prefix)
|     ret += mcgen('''
|     [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
|                max_index=max_index)

then running:

$ cat qapi-{types,event}.c tests/test-qapi-types.c |
    sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list

The only things not generated are the changes in scripts/qapi.py.

Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
stable-2.6
Eric Blake 2015-11-18 01:52:57 -07:00 committed by Markus Armbruster
parent 59a92feedc
commit 7fb1cf1606
34 changed files with 83 additions and 83 deletions

View File

@ -36,7 +36,7 @@ typedef struct BDRVBlkdebugState {
int state;
int new_state;
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_MAX];
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG__MAX];
QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
QLIST_HEAD(, BlkdebugSuspendedReq) suspended_reqs;
} BDRVBlkdebugState;
@ -147,7 +147,7 @@ static int get_event_by_name(const char *name, BlkdebugEvent *event)
{
int i;
for (i = 0; i < BLKDBG_MAX; i++) {
for (i = 0; i < BLKDBG__MAX; i++) {
if (!strcmp(BlkdebugEvent_lookup[i], name)) {
*event = i;
return 0;
@ -507,7 +507,7 @@ static void blkdebug_close(BlockDriverState *bs)
BlkdebugRule *rule, *next;
int i;
for (i = 0; i < BLKDBG_MAX; i++) {
for (i = 0; i < BLKDBG__MAX; i++) {
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
remove_rule(rule);
}
@ -576,7 +576,7 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkdebugEvent event)
struct BlkdebugRule *rule, *next;
bool injected;
assert((int)event >= 0 && event < BLKDBG_MAX);
assert((int)event >= 0 && event < BLKDBG__MAX);
injected = false;
s->new_state = s->state;
@ -633,7 +633,7 @@ static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
BlkdebugRule *rule, *next;
int i, ret = -ENOENT;
for (i = 0; i < BLKDBG_MAX; i++) {
for (i = 0; i < BLKDBG__MAX; i++) {
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
if (rule->action == ACTION_SUSPEND &&
!strcmp(rule->options.suspend.tag, tag)) {

View File

@ -61,7 +61,7 @@ typedef struct ParallelsHeader {
typedef enum ParallelsPreallocMode {
PRL_PREALLOC_MODE_FALLOCATE = 0,
PRL_PREALLOC_MODE_TRUNCATE = 1,
PRL_PREALLOC_MODE_MAX = 2,
PRL_PREALLOC_MODE__MAX = 2,
} ParallelsPreallocMode;
static const char *prealloc_mode_lookup[] = {
@ -660,7 +660,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
PRL_PREALLOC_MODE_MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err);
PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err);
g_free(buf);
if (local_err != NULL) {
goto fail_options;

View File

@ -2269,7 +2269,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
DEFAULT_CLUSTER_SIZE);
buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
PREALLOC_MODE_MAX, PREALLOC_MODE_OFF,
PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
&local_err);
if (local_err) {
error_propagate(errp, local_err);

View File

@ -847,7 +847,7 @@ static int parse_read_pattern(const char *opt)
return QUORUM_READ_PATTERN_QUORUM;
}
for (i = 0; i < QUORUM_READ_PATTERN_MAX; i++) {
for (i = 0; i < QUORUM_READ_PATTERN__MAX; i++) {
if (!strcmp(opt, QuorumReadPattern_lookup[i])) {
return i;
}

View File

@ -1636,7 +1636,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
PREALLOC_MODE_MAX, PREALLOC_MODE_OFF,
PREALLOC_MODE__MAX, PREALLOC_MODE_OFF,
&local_err);
g_free(buf);
if (local_err) {

View File

@ -454,7 +454,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
*detect_zeroes =
qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
qemu_opt_get(opts, "detect-zeroes"),
BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX,
BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
&local_error);
if (local_error) {

View File

@ -1053,7 +1053,7 @@ Example:
const char *const example_QAPIEvent_lookup[] = {
[EXAMPLE_QAPI_EVENT_MY_EVENT] = "MY_EVENT",
[EXAMPLE_QAPI_EVENT_MAX] = NULL,
[EXAMPLE_QAPI_EVENT__MAX] = NULL,
};
$ cat qapi-generated/example-qapi-event.h
[Uninteresting stuff omitted...]
@ -1070,7 +1070,7 @@ Example:
typedef enum example_QAPIEvent {
EXAMPLE_QAPI_EVENT_MY_EVENT = 0,
EXAMPLE_QAPI_EVENT_MAX = 1,
EXAMPLE_QAPI_EVENT__MAX = 1,
} example_QAPIEvent;
extern const char *const example_QAPIEvent_lookup[];

14
hmp.c
View File

@ -855,7 +855,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
tpo->has_cancel_path ? ",cancel-path=" : "",
tpo->has_cancel_path ? tpo->cancel_path : "");
break;
case TPM_TYPE_OPTIONS_KIND_MAX:
case TPM_TYPE_OPTIONS_KIND__MAX:
break;
}
monitor_printf(mon, "\n");
@ -1203,7 +1203,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
int i;
for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
caps->value = g_malloc0(sizeof(*caps->value));
caps->value->capability = i;
@ -1214,7 +1214,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
}
}
if (i == MIGRATION_CAPABILITY_MAX) {
if (i == MIGRATION_CAPABILITY__MAX) {
error_setg(&err, QERR_INVALID_PARAMETER, cap);
}
@ -1239,7 +1239,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
bool has_x_cpu_throttle_increment = false;
int i;
for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
switch (i) {
case MIGRATION_PARAMETER_COMPRESS_LEVEL:
@ -1268,7 +1268,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
}
}
if (i == MIGRATION_PARAMETER_MAX) {
if (i == MIGRATION_PARAMETER__MAX) {
error_setg(&err, QERR_INVALID_PARAMETER, param);
}
@ -1368,7 +1368,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
if (read_only) {
read_only_mode =
qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_MAX,
read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX,
BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
if (err) {
hmp_handle_error(mon, &err);
@ -1771,7 +1771,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
keylist->value->u.number = value;
} else {
int idx = index_from_key(keyname_buf);
if (idx == Q_KEY_CODE_MAX) {
if (idx == Q_KEY_CODE__MAX) {
goto err_out;
}
keylist->value->type = KEY_VALUE_KIND_QCODE;

View File

@ -714,7 +714,7 @@ MemoryRegion *escc_init(hwaddr base, qemu_irq irqA, qemu_irq irqB,
return &d->mmio;
}
static const uint8_t qcode_to_keycode[Q_KEY_CODE_MAX] = {
static const uint8_t qcode_to_keycode[Q_KEY_CODE__MAX] = {
[Q_KEY_CODE_SHIFT] = 99,
[Q_KEY_CODE_SHIFT_R] = 110,
[Q_KEY_CODE_ALT] = 19,

View File

@ -225,7 +225,7 @@ static void pc_init1(MachineState *machine,
pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
assert(pcms->vmport != ON_OFF_AUTO_MAX);
assert(pcms->vmport != ON_OFF_AUTO__MAX);
if (pcms->vmport == ON_OFF_AUTO_AUTO) {
pcms->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
}

View File

@ -233,7 +233,7 @@ static void pc_q35_init(MachineState *machine)
pc_register_ferr_irq(gsi[13]);
assert(pcms->vmport != ON_OFF_AUTO_MAX);
assert(pcms->vmport != ON_OFF_AUTO__MAX);
if (pcms->vmport == ON_OFF_AUTO_AUTO) {
pcms->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
}

View File

@ -108,7 +108,7 @@ void hid_set_next_idle(HIDState *hs)
static void hid_pointer_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
static const int bmap[INPUT_BUTTON_MAX] = {
static const int bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = 0x01,
[INPUT_BUTTON_RIGHT] = 0x02,
[INPUT_BUTTON_MIDDLE] = 0x04,

View File

@ -382,7 +382,7 @@ static void ps2_mouse_send_packet(PS2MouseState *s)
static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
static const int bmap[INPUT_BUTTON_MAX] = {
static const int bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,

View File

@ -21,7 +21,7 @@
/* ----------------------------------------------------------------- */
static const unsigned int keymap_qcode[Q_KEY_CODE_MAX] = {
static const unsigned int keymap_qcode[Q_KEY_CODE__MAX] = {
[Q_KEY_CODE_ESC] = KEY_ESC,
[Q_KEY_CODE_1] = KEY_1,
[Q_KEY_CODE_2] = KEY_2,
@ -138,7 +138,7 @@ static const unsigned int keymap_qcode[Q_KEY_CODE_MAX] = {
[Q_KEY_CODE_MENU] = KEY_MENU,
};
static const unsigned int keymap_button[INPUT_BUTTON_MAX] = {
static const unsigned int keymap_button[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = BTN_LEFT,
[INPUT_BUTTON_RIGHT] = BTN_RIGHT,
[INPUT_BUTTON_MIDDLE] = BTN_MIDDLE,
@ -146,12 +146,12 @@ static const unsigned int keymap_button[INPUT_BUTTON_MAX] = {
[INPUT_BUTTON_WHEEL_DOWN] = BTN_GEAR_DOWN,
};
static const unsigned int axismap_rel[INPUT_AXIS_MAX] = {
static const unsigned int axismap_rel[INPUT_AXIS__MAX] = {
[INPUT_AXIS_X] = REL_X,
[INPUT_AXIS_Y] = REL_Y,
};
static const unsigned int axismap_abs[INPUT_AXIS_MAX] = {
static const unsigned int axismap_abs[INPUT_AXIS__MAX] = {
[INPUT_AXIS_X] = ABS_X,
[INPUT_AXIS_Y] = ABS_Y,
};

View File

@ -133,7 +133,7 @@ struct MigrationState
QemuThread thread;
QEMUBH *cleanup_bh;
QEMUFile *file;
int parameters[MIGRATION_PARAMETER_MAX];
int parameters[MIGRATION_PARAMETER__MAX];
int state;
MigrationParams params;
@ -151,7 +151,7 @@ struct MigrationState
int64_t expected_downtime;
int64_t dirty_pages_rate;
int64_t dirty_bytes_rate;
bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
bool enabled_capabilities[MIGRATION_CAPABILITY__MAX];
int64_t xbzrle_cache_size;
int64_t setup_time;
int64_t dirty_sync_count;

View File

@ -202,7 +202,7 @@ static int global_state_post_load(void *opaque, int version_id)
s->received = true;
trace_migrate_global_state_post_load(runstate);
r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE_MAX,
r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX,
-1, &local_err);
if (r == -1) {
@ -479,7 +479,7 @@ MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
int i;
caps = NULL; /* silence compiler warning */
for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
if (head == NULL) {
head = g_malloc0(sizeof(*caps));
caps = head;

View File

@ -441,7 +441,7 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data,
}
static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT_MAX] = {
static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
/* Limit guest-triggerable events to 1 per second */
[QAPI_EVENT_RTC_CHANGE] = { 1000 * SCALE_MS },
[QAPI_EVENT_WATCHDOG] = { 1000 * SCALE_MS },
@ -481,7 +481,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
MonitorQAPIEventConf *evconf;
MonitorQAPIEventState *evstate;
assert(event < QAPI_EVENT_MAX);
assert(event < QAPI_EVENT__MAX);
evconf = &monitor_qapi_event_conf[event];
trace_monitor_protocol_event_queue(event, qdict, evconf->rate);
@ -946,7 +946,7 @@ EventInfoList *qmp_query_events(Error **errp)
EventInfoList *info, *ev_list = NULL;
QAPIEvent e;
for (e = 0 ; e < QAPI_EVENT_MAX ; e++) {
for (e = 0 ; e < QAPI_EVENT__MAX ; e++) {
const char *event_name = QAPIEvent_lookup[e];
assert(event_name != NULL);
info = g_malloc0(sizeof(*info));
@ -1386,7 +1386,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
@ -3217,7 +3217,7 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
}
len = strlen(str);
readline_set_completion_index(rs, len);
for (i = 0; i < Q_KEY_CODE_MAX; i++) {
for (i = 0; i < Q_KEY_CODE__MAX; i++) {
if (!strncmp(str, QKeyCode_lookup[i], len)) {
readline_add_completion(rs, QKeyCode_lookup[i]);
}
@ -3316,7 +3316,7 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
readline_set_completion_index(rs, len);
if (nb_args == 2) {
int i;
for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
const char *name = MigrationCapability_lookup[i];
if (!strncmp(str, name, len)) {
readline_add_completion(rs, name);
@ -3337,7 +3337,7 @@ void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
readline_set_completion_index(rs, len);
if (nb_args == 2) {
int i;
for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
const char *name = MigrationParameter_lookup[i];
if (!strncmp(str, name, len)) {
readline_add_completion(rs, name);

View File

@ -943,7 +943,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
}
static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])(
const NetClientOptions *opts,
const char *name,
NetClientState *peer, Error **errp) = {
@ -1296,7 +1296,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
int queues, i;
queues = qemu_find_net_clients_except(name, ncs,
NET_CLIENT_OPTIONS_KIND_MAX,
NET_CLIENT_OPTIONS_KIND__MAX,
MAX_QUEUE_NUM);
if (queues == 0) {

View File

@ -487,7 +487,7 @@ int main(int argc, char **argv)
detect_zeroes =
qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
optarg,
BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX,
BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
&local_err);
if (local_err) {

View File

@ -61,7 +61,7 @@ void replay_save_input_event(InputEvent *evt)
replay_put_dword(evt->u.key->key->u.qcode);
replay_put_byte(evt->u.key->down);
break;
case KEY_VALUE_KIND_MAX:
case KEY_VALUE_KIND__MAX:
/* keep gcc happy */
break;
}
@ -78,7 +78,7 @@ void replay_save_input_event(InputEvent *evt)
replay_put_dword(evt->u.abs->axis);
replay_put_qword(evt->u.abs->value);
break;
case INPUT_EVENT_KIND_MAX:
case INPUT_EVENT_KIND__MAX:
/* keep gcc happy */
break;
}
@ -109,7 +109,7 @@ InputEvent *replay_read_input_event(void)
evt.u.key->key->u.qcode = (QKeyCode)replay_get_dword();
evt.u.key->down = replay_get_byte();
break;
case KEY_VALUE_KIND_MAX:
case KEY_VALUE_KIND__MAX:
/* keep gcc happy */
break;
}
@ -129,7 +129,7 @@ InputEvent *replay_read_input_event(void)
evt.u.abs->axis = (InputAxis)replay_get_dword();
evt.u.abs->value = replay_get_qword();
break;
case INPUT_EVENT_KIND_MAX:
case INPUT_EVENT_KIND__MAX:
/* keep gcc happy */
break;
}

View File

@ -918,7 +918,7 @@ class QAPISchemaEnumType(QAPISchemaType):
return c_name(self.name)
def c_null(self):
return c_enum_const(self.name, (self.values + ['MAX'])[0],
return c_enum_const(self.name, (self.values + ['_MAX'])[0],
self.prefix)
def json_type(self):
@ -1568,7 +1568,7 @@ const char *const %(c_name)s_lookup[] = {
''',
index=index, value=value)
max_index = c_enum_const(name, 'MAX', prefix)
max_index = c_enum_const(name, '_MAX', prefix)
ret += mcgen('''
[%(max_index)s] = NULL,
};
@ -1579,7 +1579,7 @@ const char *const %(c_name)s_lookup[] = {
def gen_enum(name, values, prefix=None):
# append automatically generated _MAX value
enum_values = values + ['MAX']
enum_values = values + ['_MAX']
ret = mcgen('''

View File

@ -128,7 +128,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
QObject *obj;
EnumOne i;
for (i = 0; i < ENUM_ONE_MAX; i++) {
for (i = 0; i < ENUM_ONE__MAX; i++) {
visit_type_EnumOne(data->ov, &i, "unused", &error_abort);
obj = qmp_output_get_qobject(data->qov);
@ -143,7 +143,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
const void *unused)
{
EnumOne i, bad_values[] = { ENUM_ONE_MAX, -1 };
EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
Error *err;
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
@ -247,7 +247,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
static void test_visitor_out_struct_errors(TestOutputVisitorData *data,
const void *unused)
{
EnumOne bad_values[] = { ENUM_ONE_MAX, -1 };
EnumOne bad_values[] = { ENUM_ONE__MAX, -1 };
UserDefOne u = {0};
UserDefOne *pu = &u;
Error *err;

View File

@ -194,7 +194,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
char *str;
EnumOne i;
for (i = 0; i < ENUM_ONE_MAX; i++) {
for (i = 0; i < ENUM_ONE__MAX; i++) {
char *str_human;
visit_type_EnumOne(data->ov, &i, "unused", &err);
@ -217,7 +217,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
const void *unused)
{
EnumOne i, bad_values[] = { ENUM_ONE_MAX, -1 };
EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
Error *err;
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {

10
tpm.c
View File

@ -32,7 +32,7 @@ static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = {
};
static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
TPM_MODEL_MAX,
TPM_MODEL__MAX,
};
int tpm_register_model(enum TpmModel model)
@ -40,7 +40,7 @@ int tpm_register_model(enum TpmModel model)
int i;
for (i = 0; i < TPM_MAX_MODELS; i++) {
if (tpm_models[i] == TPM_MODEL_MAX) {
if (tpm_models[i] == TPM_MODEL__MAX) {
tpm_models[i] = model;
return 0;
}
@ -272,7 +272,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)
tpo->has_cancel_path = true;
}
break;
case TPM_TYPE_MAX:
case TPM_TYPE__MAX:
break;
}
@ -311,7 +311,7 @@ TpmTypeList *qmp_query_tpm_types(Error **errp)
unsigned int i = 0;
TpmTypeList *head = NULL, *prev = NULL, *cur_item;
for (i = 0; i < TPM_TYPE_MAX; i++) {
for (i = 0; i < TPM_TYPE__MAX; i++) {
if (!tpm_driver_find_by_type(i)) {
continue;
}
@ -335,7 +335,7 @@ TpmModelList *qmp_query_tpm_models(Error **errp)
unsigned int i = 0;
TpmModelList *head = NULL, *prev = NULL, *cur_item;
for (i = 0; i < TPM_MODEL_MAX; i++) {
for (i = 0; i < TPM_MODEL__MAX; i++) {
if (!tpm_model_is_registered(i)) {
continue;
}

View File

@ -733,7 +733,7 @@ QemuCocoaView *cocoaView;
*/
if ((isMouseGrabbed || [[self window] isKeyWindow]) &&
(last_buttons != buttons)) {
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,

View File

@ -1108,7 +1108,7 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym)
}
}
static const int qcode_to_keysym[Q_KEY_CODE_MAX] = {
static const int qcode_to_keysym[Q_KEY_CODE__MAX] = {
[Q_KEY_CODE_UP] = QEMU_KEY_UP,
[Q_KEY_CODE_DOWN] = QEMU_KEY_DOWN,
[Q_KEY_CODE_RIGHT] = QEMU_KEY_RIGHT,

View File

@ -132,7 +132,7 @@ static const int qcode_to_number[] = {
[Q_KEY_CODE_RO] = 0x73,
[Q_KEY_CODE_KP_COMMA] = 0x7e,
[Q_KEY_CODE_MAX] = 0,
[Q_KEY_CODE__MAX] = 0,
};
static int number_to_qcode[0x100];
@ -154,7 +154,7 @@ int qemu_input_key_number_to_qcode(uint8_t nr)
if (first) {
int qcode, number;
first = false;
for (qcode = 0; qcode < Q_KEY_CODE_MAX; qcode++) {
for (qcode = 0; qcode < Q_KEY_CODE__MAX; qcode++) {
number = qcode_to_number[qcode];
assert(number < ARRAY_SIZE(number_to_qcode));
number_to_qcode[number] = qcode;

View File

@ -38,7 +38,7 @@ struct QEMUPutMouseEntry {
/* new input core */
QemuInputHandler h;
QemuInputHandlerState *s;
int axis[INPUT_AXIS_MAX];
int axis[INPUT_AXIS__MAX];
int buttons;
};
@ -67,7 +67,7 @@ int index_from_key(const char *key)
}
}
/* Return Q_KEY_CODE_MAX if the key is invalid */
/* Return Q_KEY_CODE__MAX if the key is invalid */
return i;
}
@ -143,7 +143,7 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
static const int bmap[INPUT_BUTTON_MAX] = {
static const int bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
[INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
[INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,

View File

@ -211,7 +211,7 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
name = QKeyCode_lookup[evt->u.key->key->u.qcode];
trace_input_event_key_qcode(idx, name, evt->u.key->down);
break;
case KEY_VALUE_KIND_MAX:
case KEY_VALUE_KIND__MAX:
/* keep gcc happy */
break;
}
@ -228,7 +228,7 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
name = InputAxis_lookup[evt->u.abs->axis];
trace_input_event_abs(idx, name, evt->u.abs->value);
break;
case INPUT_EVENT_KIND_MAX:
case INPUT_EVENT_KIND__MAX:
/* keep gcc happy */
break;
}
@ -430,7 +430,7 @@ void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
InputButton btn;
uint32_t mask;
for (btn = 0; btn < INPUT_BUTTON_MAX; btn++) {
for (btn = 0; btn < INPUT_BUTTON__MAX; btn++) {
mask = button_map[btn];
if ((button_old & mask) == (button_new & mask)) {
continue;

View File

@ -465,7 +465,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
static void sdl_send_mouse_event(int dx, int dy, int x, int y, int state)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT),
[INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
[INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT),

View File

@ -256,7 +256,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy,
int x, int y, int state)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT),
[INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
[INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT),

View File

@ -107,7 +107,7 @@ typedef struct QemuSpicePointer {
static void spice_update_buttons(QemuSpicePointer *pointer,
int wheel, uint32_t button_mask)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = 0x01,
[INPUT_BUTTON_MIDDLE] = 0x04,
[INPUT_BUTTON_RIGHT] = 0x02,

View File

@ -1676,7 +1676,7 @@ static void check_pointer_type_change(Notifier *notifier, void *data)
static void pointer_event(VncState *vs, int button_mask, int x, int y)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
static uint32_t bmap[INPUT_BUTTON__MAX] = {
[INPUT_BUTTON_LEFT] = 0x01,
[INPUT_BUTTON_MIDDLE] = 0x02,
[INPUT_BUTTON_RIGHT] = 0x04,

18
vl.c
View File

@ -570,8 +570,8 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
static RunState current_run_state = RUN_STATE_PRELAUNCH;
/* We use RUN_STATE_MAX but any invalid value will do */
static RunState vmstop_requested = RUN_STATE_MAX;
/* We use RUN_STATE__MAX but any invalid value will do */
static RunState vmstop_requested = RUN_STATE__MAX;
static QemuMutex vmstop_lock;
typedef struct {
@ -642,10 +642,10 @@ static const RunStateTransition runstate_transitions_def[] = {
{ RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
{ RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
{ RUN_STATE_MAX, RUN_STATE_MAX },
{ RUN_STATE__MAX, RUN_STATE__MAX },
};
static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX];
bool runstate_check(RunState state)
{
@ -669,7 +669,7 @@ static void runstate_init(void)
const RunStateTransition *p;
memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) {
runstate_valid_transitions[p->from][p->to] = true;
}
@ -679,7 +679,7 @@ static void runstate_init(void)
/* This function will abort() on invalid state transitions */
void runstate_set(RunState new_state)
{
assert(new_state < RUN_STATE_MAX);
assert(new_state < RUN_STATE__MAX);
if (!runstate_valid_transitions[current_run_state][new_state]) {
error_report("invalid runstate transition: '%s' -> '%s'",
@ -717,9 +717,9 @@ static bool qemu_vmstop_requested(RunState *r)
{
qemu_mutex_lock(&vmstop_lock);
*r = vmstop_requested;
vmstop_requested = RUN_STATE_MAX;
vmstop_requested = RUN_STATE__MAX;
qemu_mutex_unlock(&vmstop_lock);
return *r < RUN_STATE_MAX;
return *r < RUN_STATE__MAX;
}
void qemu_system_vmstop_request_prepare(void)
@ -739,7 +739,7 @@ void vm_start(void)
RunState requested;
qemu_vmstop_requested(&requested);
if (runstate_is_running() && requested == RUN_STATE_MAX) {
if (runstate_is_running() && requested == RUN_STATE__MAX) {
return;
}