@@ -227,7 +227,7 @@ optional 'prefix' member overrides PREFIX.
The generated C enumeration constants have values 0, 1, ..., N-1 (in
QAPI schema order), where N is the number of values. There is an
-additional enumeration constant PREFIX__MAX with value N.
+additional definition constant PREFIX__MAX with value N.
Do not use string or an integer type when an enumeration type can do
the job satisfactorily.
@@ -1825,7 +1825,7 @@ Example::
typedef enum example_QAPIEvent {
EXAMPLE_QAPI_EVENT_MY_EVENT,
- EXAMPLE_QAPI_EVENT__MAX,
+ #define EXAMPLE_QAPI_EVENT__MAX 1
} example_QAPIEvent;
#define example_QAPIEvent_str(val) \
@@ -86,16 +86,13 @@ def gen_enum_lookup(name: str,
def gen_enum(name: str,
members: List[QAPISchemaEnumMember],
prefix: Optional[str] = None) -> str:
- # append automatically generated _MAX value
- enum_members = members + [QAPISchemaEnumMember('_MAX', None)]
-
ret = mcgen('''
typedef enum %(c_name)s {
''',
c_name=c_name(name))
- for memb in enum_members:
+ for memb in members:
ret += memb.ifcond.gen_if()
ret += mcgen('''
%(c_enum)s,
@@ -103,6 +100,12 @@ def gen_enum(name: str,
c_enum=c_enum_const(name, memb.name, prefix))
ret += memb.ifcond.gen_endif()
+ ret += mcgen('''
+#define %(c_name)s %(c_length)s
+''',
+ c_name=c_enum_const(name, '_MAX', prefix),
+ c_length=len(members))
+
ret += mcgen('''
} %(c_name)s;
''',
@@ -159,8 +159,6 @@ def gen_visit_object_members(name: str,
ret += var.ifcond.gen_endif()
ret += mcgen('''
- default:
- abort();
}
''')
@@ -376,9 +376,6 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
#endif
case AUDIODEV_DRIVER_WAV:
return dev->u.wav.TYPE;
-
- case AUDIODEV_DRIVER__MAX:
- break;
}
abort();
}
@@ -2071,9 +2071,6 @@ void audio_create_pdos(Audiodev *dev)
CASE(SPICE, spice, );
#endif
CASE(WAV, wav, );
-
- case AUDIODEV_DRIVER__MAX:
- abort();
};
}
@@ -2219,9 +2216,6 @@ int audioformat_bytes_per_sample(AudioFormat fmt)
case AUDIO_FORMAT_S32:
case AUDIO_FORMAT_F32:
return 4;
-
- case AUDIO_FORMAT__MAX:
- ;
}
abort();
}
@@ -2220,8 +2220,6 @@ bool migration_is_idle(void)
case MIGRATION_STATUS_DEVICE:
case MIGRATION_STATUS_WAIT_UNPLUG:
return false;
- case MIGRATION_STATUS__MAX:
- g_assert_not_reached();
}
return false;
@@ -38,9 +38,6 @@ void replay_save_input_event(InputEvent *evt)
replay_put_dword(key->key->u.qcode.data);
replay_put_byte(key->down);
break;
- case KEY_VALUE_KIND__MAX:
- /* keep gcc happy */
- break;
}
break;
case INPUT_EVENT_KIND_BTN:
@@ -58,9 +55,6 @@ void replay_save_input_event(InputEvent *evt)
replay_put_dword(move->axis);
replay_put_qword(move->value);
break;
- case INPUT_EVENT_KIND__MAX:
- /* keep gcc happy */
- break;
}
}
@@ -89,9 +83,6 @@ InputEvent *replay_read_input_event(void)
evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword();
evt.u.key.data->down = replay_get_byte();
break;
- case KEY_VALUE_KIND__MAX:
- /* keep gcc happy */
- break;
}
break;
case INPUT_EVENT_KIND_BTN:
@@ -109,9 +100,6 @@ InputEvent *replay_read_input_event(void)
evt.u.abs.data->axis = (InputAxis)replay_get_dword();
evt.u.abs.data->value = replay_get_qword();
break;
- case INPUT_EVENT_KIND__MAX:
- /* keep gcc happy */
- break;
}
return QAPI_CLONE(InputEvent, &evt);
@@ -52,8 +52,6 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
teo = ti->options->u.emulator.data;
monitor_printf(mon, ",chardev=%s", teo->chardev);
break;
- case TPM_TYPE__MAX:
- break;
}
monitor_printf(mon, "\n");
c++;
@@ -120,10 +120,6 @@ static bool input_linux_check_toggle(InputLinux *il)
return (il->keydown[KEY_LEFTCTRL] ||
il->keydown[KEY_RIGHTCTRL]) &&
il->keydown[KEY_SCROLLLOCK];
-
- case GRAB_TOGGLE_KEYS__MAX:
- /* avoid gcc error */
- break;
}
return false;
}
@@ -230,9 +230,6 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
name = QKeyCode_str(key->key->u.qcode.data);
trace_input_event_key_qcode(idx, name, key->down);
break;
- case KEY_VALUE_KIND__MAX:
- /* keep gcc happy */
- break;
}
break;
case INPUT_EVENT_KIND_BTN:
@@ -250,9 +247,6 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
name = InputAxis_str(move->axis);
trace_input_event_abs(idx, name, move->value);
break;
- case INPUT_EVENT_KIND__MAX:
- /* keep gcc happy */
- break;
}
}