qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qapi: Change data type of the FOO_lookup generated for enum FOO

Currently, a FOO_lookup is an array of strings terminated by a NULL
sentinel.

A future patch will generate enums with "holes". NULL-termination
will cease to work then.

To prepare for that, store the length in the FOO_lookup by wrapping it
in a struct and adding a member for the length.

The sentinel will be dropped next.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20170822132255.23945-13-marcandre.lureau@redhat.com>
[Basically redone]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1503564371-26090-16-git-send-email-armbru@redhat.com>
[Rebased]

authored by

Marc-André Lureau and committed by
Markus Armbruster
f7abe0ec 788b305c

+106 -89
+1 -1
backends/hostmem.c
··· 395 395 host_memory_backend_set_host_nodes, 396 396 NULL, NULL, &error_abort); 397 397 object_class_property_add_enum(oc, "policy", "HostMemPolicy", 398 - HostMemPolicy_lookup, 398 + &HostMemPolicy_lookup, 399 399 host_memory_backend_get_policy, 400 400 host_memory_backend_set_policy, &error_abort); 401 401 object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
+1 -1
block.c
··· 1332 1332 detect_zeroes = qemu_opt_get(opts, "detect-zeroes"); 1333 1333 if (detect_zeroes) { 1334 1334 BlockdevDetectZeroesOptions value = 1335 - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, 1335 + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, 1336 1336 detect_zeroes, 1337 1337 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, 1338 1338 &local_err);
+2 -2
block/blkdebug.c
··· 169 169 error_setg(errp, "Missing event name for rule"); 170 170 return -1; 171 171 } 172 - event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp); 172 + event = qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp); 173 173 if (event < 0) { 174 174 return -1; 175 175 } ··· 732 732 struct BlkdebugRule *rule; 733 733 int blkdebug_event; 734 734 735 - blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL); 735 + blkdebug_event = qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, NULL); 736 736 if (blkdebug_event < 0) { 737 737 return -ENOENT; 738 738 }
+5 -3
block/file-posix.c
··· 437 437 aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO) 438 438 ? BLOCKDEV_AIO_OPTIONS_NATIVE 439 439 : BLOCKDEV_AIO_OPTIONS_THREADS; 440 - aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), 440 + aio = qapi_enum_parse(&BlockdevAioOptions_lookup, 441 + qemu_opt_get(opts, "aio"), 441 442 aio_default, &local_err); 442 443 if (local_err) { 443 444 error_propagate(errp, local_err); ··· 446 447 } 447 448 s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE); 448 449 449 - locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"), 450 + locking = qapi_enum_parse(&OnOffAuto_lookup, 451 + qemu_opt_get(opts, "locking"), 450 452 ON_OFF_AUTO_AUTO, &local_err); 451 453 if (local_err) { 452 454 error_propagate(errp, local_err); ··· 1973 1975 BDRV_SECTOR_SIZE); 1974 1976 nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false); 1975 1977 buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); 1976 - prealloc = qapi_enum_parse(PreallocMode_lookup, buf, 1978 + prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, 1977 1979 PREALLOC_MODE_OFF, &local_err); 1978 1980 g_free(buf); 1979 1981 if (local_err) {
+1 -1
block/file-win32.c
··· 302 302 303 303 aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE 304 304 : BLOCKDEV_AIO_OPTIONS_THREADS; 305 - aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), 305 + aio = qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), 306 306 aio_default, errp); 307 307 308 308 switch (aio) {
+2 -2
block/gluster.c
··· 543 543 if (!strcmp(ptr, "tcp")) { 544 544 ptr = "inet"; /* accept legacy "tcp" */ 545 545 } 546 - type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL); 546 + type = qapi_enum_parse(&SocketAddressType_lookup, ptr, -1, NULL); 547 547 if (type != SOCKET_ADDRESS_TYPE_INET 548 548 && type != SOCKET_ADDRESS_TYPE_UNIX) { 549 549 error_setg(&local_err, ··· 1000 1000 BDRV_SECTOR_SIZE); 1001 1001 1002 1002 tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); 1003 - prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF, 1003 + prealloc = qapi_enum_parse(&PreallocMode_lookup, tmp, PREALLOC_MODE_OFF, 1004 1004 &local_err); 1005 1005 g_free(tmp); 1006 1006 if (local_err) {
+8 -6
block/parallels.c
··· 68 68 PRL_PREALLOC_MODE__MAX = 2, 69 69 } ParallelsPreallocMode; 70 70 71 - static const char *prealloc_mode_lookup[] = { 72 - "falloc", 73 - "truncate", 74 - NULL, 71 + static QEnumLookup prealloc_mode_lookup = { 72 + .array = (const char *const[]) { 73 + "falloc", 74 + "truncate", 75 + NULL, 76 + }, 77 + .size = PRL_PREALLOC_MODE__MAX 75 78 }; 76 - 77 79 78 80 typedef struct BDRVParallelsState { 79 81 /** Locking is conservative, the lock protects ··· 695 697 qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0); 696 698 s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS); 697 699 buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE); 698 - s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf, 700 + s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf, 699 701 PRL_PREALLOC_MODE_FALLOCATE, 700 702 &local_err); 701 703 g_free(buf);
+2 -2
block/qcow2.c
··· 2915 2915 goto finish; 2916 2916 } 2917 2917 buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); 2918 - prealloc = qapi_enum_parse(PreallocMode_lookup, buf, 2918 + prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, 2919 2919 PREALLOC_MODE_OFF, &local_err); 2920 2920 if (local_err) { 2921 2921 error_propagate(errp, local_err); ··· 3605 3605 } 3606 3606 3607 3607 optstr = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); 3608 - prealloc = qapi_enum_parse(PreallocMode_lookup, optstr, 3608 + prealloc = qapi_enum_parse(&PreallocMode_lookup, optstr, 3609 3609 PREALLOC_MODE_OFF, &local_err); 3610 3610 g_free(optstr); 3611 3611 if (local_err) {
+1 -1
block/quorum.c
··· 912 912 if (!pattern_str) { 913 913 ret = QUORUM_READ_PATTERN_QUORUM; 914 914 } else { 915 - ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str, 915 + ret = qapi_enum_parse(&QuorumReadPattern_lookup, pattern_str, 916 916 -EINVAL, NULL); 917 917 } 918 918 if (ret < 0) {
+1 -1
blockdev.c
··· 437 437 438 438 if (detect_zeroes) { 439 439 *detect_zeroes = 440 - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, 440 + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, 441 441 qemu_opt_get(opts, "detect-zeroes"), 442 442 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, 443 443 &local_error);
+4 -4
crypto/block-luks.c
··· 264 264 /* XXX replace with qapi_enum_parse() in future, when we can 265 265 * make that function emit a more friendly error message */ 266 266 static int qcrypto_block_luks_name_lookup(const char *name, 267 - const char *const *map, 267 + const QEnumLookup *map, 268 268 const char *type, 269 269 Error **errp) 270 270 { ··· 279 279 280 280 #define qcrypto_block_luks_cipher_mode_lookup(name, errp) \ 281 281 qcrypto_block_luks_name_lookup(name, \ 282 - QCryptoCipherMode_lookup, \ 282 + &QCryptoCipherMode_lookup, \ 283 283 "Cipher mode", \ 284 284 errp) 285 285 286 286 #define qcrypto_block_luks_hash_name_lookup(name, errp) \ 287 287 qcrypto_block_luks_name_lookup(name, \ 288 - QCryptoHashAlgorithm_lookup, \ 288 + &QCryptoHashAlgorithm_lookup, \ 289 289 "Hash algorithm", \ 290 290 errp) 291 291 292 292 #define qcrypto_block_luks_ivgen_name_lookup(name, errp) \ 293 293 qcrypto_block_luks_name_lookup(name, \ 294 - QCryptoIVGenAlgorithm_lookup, \ 294 + &QCryptoIVGenAlgorithm_lookup, \ 295 295 "IV generator", \ 296 296 errp) 297 297
+1 -1
crypto/secret.c
··· 378 378 NULL); 379 379 object_class_property_add_enum(oc, "format", 380 380 "QCryptoSecretFormat", 381 - QCryptoSecretFormat_lookup, 381 + &QCryptoSecretFormat_lookup, 382 382 qcrypto_secret_prop_get_format, 383 383 qcrypto_secret_prop_set_format, 384 384 NULL);
+1 -1
crypto/tlscreds.c
··· 233 233 NULL); 234 234 object_class_property_add_enum(oc, "endpoint", 235 235 "QCryptoTLSCredsEndpoint", 236 - QCryptoTLSCredsEndpoint_lookup, 236 + &QCryptoTLSCredsEndpoint_lookup, 237 237 qcrypto_tls_creds_prop_get_endpoint, 238 238 qcrypto_tls_creds_prop_set_endpoint, 239 239 NULL);
+3 -3
hmp.c
··· 1528 1528 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); 1529 1529 int val; 1530 1530 1531 - val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err); 1531 + val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); 1532 1532 if (val < 0) { 1533 1533 goto end; 1534 1534 } ··· 1557 1557 Error *err = NULL; 1558 1558 int val, ret; 1559 1559 1560 - val = qapi_enum_parse(MigrationParameter_lookup, param, -1, &err); 1560 + val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); 1561 1561 if (val < 0) { 1562 1562 goto cleanup; 1563 1563 } ··· 1735 1735 } else { 1736 1736 if (read_only) { 1737 1737 read_only_mode = 1738 - qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup, 1738 + qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, 1739 1739 read_only, 1740 1740 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); 1741 1741 if (err) {
+5 -5
hw/core/qdev-properties.c
··· 587 587 const PropertyInfo qdev_prop_on_off_auto = { 588 588 .name = "OnOffAuto", 589 589 .description = "on/off/auto", 590 - .enum_table = OnOffAuto_lookup, 590 + .enum_table = &OnOffAuto_lookup, 591 591 .get = get_enum, 592 592 .set = set_enum, 593 593 .set_default_value = set_default_value_enum, ··· 599 599 600 600 const PropertyInfo qdev_prop_losttickpolicy = { 601 601 .name = "LostTickPolicy", 602 - .enum_table = LostTickPolicy_lookup, 602 + .enum_table = &LostTickPolicy_lookup, 603 603 .get = get_enum, 604 604 .set = set_enum, 605 605 .set_default_value = set_default_value_enum, ··· 613 613 .name = "BlockdevOnError", 614 614 .description = "Error handling policy, " 615 615 "report/ignore/enospc/stop/auto", 616 - .enum_table = BlockdevOnError_lookup, 616 + .enum_table = &BlockdevOnError_lookup, 617 617 .get = get_enum, 618 618 .set = set_enum, 619 619 .set_default_value = set_default_value_enum, ··· 627 627 .name = "BiosAtaTranslation", 628 628 .description = "Logical CHS translation algorithm, " 629 629 "auto/none/lba/large/rechs", 630 - .enum_table = BiosAtaTranslation_lookup, 630 + .enum_table = &BiosAtaTranslation_lookup, 631 631 .get = get_enum, 632 632 .set = set_enum, 633 633 .set_default_value = set_default_value_enum, ··· 639 639 .name = "FdcDriveType", 640 640 .description = "FDC drive type, " 641 641 "144/288/120/none/auto", 642 - .enum_table = FloppyDriveType_lookup, 642 + .enum_table = &FloppyDriveType_lookup, 643 643 .get = get_enum, 644 644 .set = set_enum, 645 645 .set_default_value = set_default_value_enum,
+1 -1
include/hw/qdev-core.h
··· 249 249 struct PropertyInfo { 250 250 const char *name; 251 251 const char *description; 252 - const char * const *enum_table; 252 + const QEnumLookup *enum_table; 253 253 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 254 254 void (*set_default_value)(Object *obj, const Property *prop); 255 255 void (*create)(Object *obj, Property *prop, Error **errp);
+7 -2
include/qapi/util.h
··· 11 11 #ifndef QAPI_UTIL_H 12 12 #define QAPI_UTIL_H 13 13 14 - const char *qapi_enum_lookup(const char *const lookup[], int val); 15 - int qapi_enum_parse(const char * const lookup[], const char *buf, 14 + typedef struct QEnumLookup { 15 + const char *const *array; 16 + int size; 17 + } QEnumLookup; 18 + 19 + const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); 20 + int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, 16 21 int def, Error **errp); 17 22 18 23 int parse_qapi_name(const char *name, bool complete);
+1 -1
include/qapi/visitor.h
··· 469 469 * that visit_type_str() must have no unwelcome side effects. 470 470 */ 471 471 void visit_type_enum(Visitor *v, const char *name, int *obj, 472 - const char *const strings[], Error **errp); 472 + const QEnumLookup *lookup, Error **errp); 473 473 474 474 /* 475 475 * Check if visitor is an input visitor.
+2 -2
include/qom/object.h
··· 1415 1415 */ 1416 1416 void object_property_add_enum(Object *obj, const char *name, 1417 1417 const char *typename, 1418 - const char * const *strings, 1418 + const QEnumLookup *lookup, 1419 1419 int (*get)(Object *, Error **), 1420 1420 void (*set)(Object *, int, Error **), 1421 1421 Error **errp); 1422 1422 1423 1423 void object_class_property_add_enum(ObjectClass *klass, const char *name, 1424 1424 const char *typename, 1425 - const char * const *strings, 1425 + const QEnumLookup *lookup, 1426 1426 int (*get)(Object *, Error **), 1427 1427 void (*set)(Object *, int, Error **), 1428 1428 Error **errp);
+1 -1
migration/global_state.c
··· 88 88 s->received = true; 89 89 trace_migrate_global_state_post_load(runstate); 90 90 91 - r = qapi_enum_parse(RunState_lookup, runstate, -1, &local_err); 91 + r = qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err); 92 92 93 93 if (r == -1) { 94 94 if (local_err) {
+1 -1
net/filter.c
··· 179 179 netfilter_get_netdev_id, netfilter_set_netdev_id, 180 180 NULL); 181 181 object_property_add_enum(obj, "queue", "NetFilterDirection", 182 - NetFilterDirection_lookup, 182 + &NetFilterDirection_lookup, 183 183 netfilter_get_direction, netfilter_set_direction, 184 184 NULL); 185 185 object_property_add_str(obj, "status",
+6 -6
qapi/qapi-util.c
··· 14 14 #include "qapi/error.h" 15 15 #include "qemu-common.h" 16 16 17 - const char *qapi_enum_lookup(const char *const lookup[], int val) 17 + const char *qapi_enum_lookup(const QEnumLookup *lookup, int val) 18 18 { 19 - assert(val >= 0); 19 + assert(val >= 0 && val < lookup->size); 20 20 21 - return lookup[val]; 21 + return lookup->array[val]; 22 22 } 23 23 24 - int qapi_enum_parse(const char * const lookup[], const char *buf, 24 + int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, 25 25 int def, Error **errp) 26 26 { 27 27 int i; ··· 30 30 return def; 31 31 } 32 32 33 - for (i = 0; lookup[i]; i++) { 34 - if (!strcmp(buf, lookup[i])) { 33 + for (i = 0; i < lookup->size; i++) { 34 + if (!strcmp(buf, lookup->array[i])) { 35 35 return i; 36 36 } 37 37 }
+13 -11
qapi/qapi-visit-core.c
··· 333 333 } 334 334 335 335 static void output_type_enum(Visitor *v, const char *name, int *obj, 336 - const char *const strings[], Error **errp) 336 + const QEnumLookup *lookup, Error **errp) 337 337 { 338 - int i = 0; 339 338 int value = *obj; 340 339 char *enum_str; 341 340 342 - while (strings[i++] != NULL); 343 - if (value < 0 || value >= i - 1) { 341 + /* 342 + * TODO why is this an error, not an assertion? If assertion: 343 + * delete, and rely on qapi_enum_lookup() 344 + */ 345 + if (value < 0 || value >= lookup->size) { 344 346 error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null"); 345 347 return; 346 348 } 347 349 348 - enum_str = (char *)qapi_enum_lookup(strings, value); 350 + enum_str = (char *)qapi_enum_lookup(lookup, value); 349 351 visit_type_str(v, name, &enum_str, errp); 350 352 } 351 353 352 354 static void input_type_enum(Visitor *v, const char *name, int *obj, 353 - const char *const strings[], Error **errp) 355 + const QEnumLookup *lookup, Error **errp) 354 356 { 355 357 Error *local_err = NULL; 356 358 int64_t value; ··· 362 364 return; 363 365 } 364 366 365 - value = qapi_enum_parse(strings, enum_str, -1, NULL); 367 + value = qapi_enum_parse(lookup, enum_str, -1, NULL); 366 368 if (value < 0) { 367 369 error_setg(errp, QERR_INVALID_PARAMETER, enum_str); 368 370 g_free(enum_str); ··· 374 376 } 375 377 376 378 void visit_type_enum(Visitor *v, const char *name, int *obj, 377 - const char *const strings[], Error **errp) 379 + const QEnumLookup *lookup, Error **errp) 378 380 { 379 - assert(obj && strings); 381 + assert(obj && lookup); 380 382 trace_visit_type_enum(v, name, obj); 381 383 switch (v->type) { 382 384 case VISITOR_INPUT: 383 - input_type_enum(v, name, obj, strings, errp); 385 + input_type_enum(v, name, obj, lookup, errp); 384 386 break; 385 387 case VISITOR_OUTPUT: 386 - output_type_enum(v, name, obj, strings, errp); 388 + output_type_enum(v, name, obj, lookup, errp); 387 389 break; 388 390 case VISITOR_CLONE: 389 391 /* nothing further to do, scalar value was already copied by
+1 -1
qemu-img.c
··· 3489 3489 image_opts = true; 3490 3490 break; 3491 3491 case OPTION_PREALLOCATION: 3492 - prealloc = qapi_enum_parse(PreallocMode_lookup, optarg, 3492 + prealloc = qapi_enum_parse(&PreallocMode_lookup, optarg, 3493 3493 PREALLOC_MODE__MAX, NULL); 3494 3494 if (prealloc == PREALLOC_MODE__MAX) { 3495 3495 error_report("Invalid preallocation mode '%s'", optarg);
+1 -1
qemu-nbd.c
··· 638 638 break; 639 639 case QEMU_NBD_OPT_DETECT_ZEROES: 640 640 detect_zeroes = 641 - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, 641 + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, 642 642 optarg, 643 643 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, 644 644 &local_err);
+8 -8
qom/object.c
··· 1246 1246 } 1247 1247 1248 1248 typedef struct EnumProperty { 1249 - const char * const *strings; 1249 + const QEnumLookup *lookup; 1250 1250 int (*get)(Object *, Error **); 1251 1251 void (*set)(Object *, int, Error **); 1252 1252 } EnumProperty; ··· 1284 1284 visit_complete(v, &str); 1285 1285 visit_free(v); 1286 1286 v = string_input_visitor_new(str); 1287 - visit_type_enum(v, name, &ret, enumprop->strings, errp); 1287 + visit_type_enum(v, name, &ret, enumprop->lookup, errp); 1288 1288 1289 1289 g_free(str); 1290 1290 visit_free(v); ··· 1950 1950 return; 1951 1951 } 1952 1952 1953 - visit_type_enum(v, name, &value, prop->strings, errp); 1953 + visit_type_enum(v, name, &value, prop->lookup, errp); 1954 1954 } 1955 1955 1956 1956 static void property_set_enum(Object *obj, Visitor *v, const char *name, ··· 1960 1960 int value; 1961 1961 Error *err = NULL; 1962 1962 1963 - visit_type_enum(v, name, &value, prop->strings, &err); 1963 + visit_type_enum(v, name, &value, prop->lookup, &err); 1964 1964 if (err) { 1965 1965 error_propagate(errp, err); 1966 1966 return; ··· 1977 1977 1978 1978 void object_property_add_enum(Object *obj, const char *name, 1979 1979 const char *typename, 1980 - const char * const *strings, 1980 + const QEnumLookup *lookup, 1981 1981 int (*get)(Object *, Error **), 1982 1982 void (*set)(Object *, int, Error **), 1983 1983 Error **errp) ··· 1985 1985 Error *local_err = NULL; 1986 1986 EnumProperty *prop = g_malloc(sizeof(*prop)); 1987 1987 1988 - prop->strings = strings; 1988 + prop->lookup = lookup; 1989 1989 prop->get = get; 1990 1990 prop->set = set; 1991 1991 ··· 2002 2002 2003 2003 void object_class_property_add_enum(ObjectClass *klass, const char *name, 2004 2004 const char *typename, 2005 - const char * const *strings, 2005 + const QEnumLookup *lookup, 2006 2006 int (*get)(Object *, Error **), 2007 2007 void (*set)(Object *, int, Error **), 2008 2008 Error **errp) ··· 2010 2010 Error *local_err = NULL; 2011 2011 EnumProperty *prop = g_malloc(sizeof(*prop)); 2012 2012 2013 - prop->strings = strings; 2013 + prop->lookup = lookup; 2014 2014 prop->get = get; 2015 2015 prop->set = set; 2016 2016
+1 -1
scripts/qapi-visit.py
··· 153 153 void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, Error **errp) 154 154 { 155 155 int value = *obj; 156 - visit_type_enum(v, name, &value, %(c_name)s_lookup, errp); 156 + visit_type_enum(v, name, &value, &%(c_name)s_lookup, errp); 157 157 *obj = value; 158 158 } 159 159 ''',
+8 -5
scripts/qapi.py
··· 1849 1849 def gen_enum_lookup(name, values, prefix=None): 1850 1850 ret = mcgen(''' 1851 1851 1852 - const char *const %(c_name)s_lookup[] = { 1852 + const QEnumLookup %(c_name)s_lookup = { 1853 + .array = (const char *const[]) { 1853 1854 ''', 1854 1855 c_name=c_name(name)) 1855 1856 for value in values: 1856 1857 index = c_enum_const(name, value, prefix) 1857 1858 ret += mcgen(''' 1858 - [%(index)s] = "%(value)s", 1859 + [%(index)s] = "%(value)s", 1859 1860 ''', 1860 1861 index=index, value=value) 1861 1862 1862 1863 max_index = c_enum_const(name, '_MAX', prefix) 1863 1864 ret += mcgen(''' 1864 - [%(max_index)s] = NULL, 1865 + [%(max_index)s] = NULL, 1866 + }, 1867 + .size = %(max_index)s 1865 1868 }; 1866 1869 ''', 1867 1870 max_index=max_index) ··· 1895 1898 ret += mcgen(''' 1896 1899 1897 1900 #define %(c_name)s_str(val) \\ 1898 - qapi_enum_lookup(%(c_name)s_lookup, (val)) 1901 + qapi_enum_lookup(&%(c_name)s_lookup, (val)) 1899 1902 1900 - extern const char *const %(c_name)s_lookup[]; 1903 + extern const QEnumLookup %(c_name)s_lookup; 1901 1904 ''', 1902 1905 c_name=c_name(name)) 1903 1906 return ret
+9 -6
tests/check-qom-proplist.c
··· 46 46 DUMMY_LAST, 47 47 }; 48 48 49 - static const char *const dummy_animal_map[DUMMY_LAST + 1] = { 50 - [DUMMY_FROG] = "frog", 51 - [DUMMY_ALLIGATOR] = "alligator", 52 - [DUMMY_PLATYPUS] = "platypus", 53 - [DUMMY_LAST] = NULL, 49 + const QEnumLookup dummy_animal_map = { 50 + .array = (const char *const[]) { 51 + [DUMMY_FROG] = "frog", 52 + [DUMMY_ALLIGATOR] = "alligator", 53 + [DUMMY_PLATYPUS] = "platypus", 54 + [DUMMY_LAST] = NULL, 55 + }, 56 + .size = DUMMY_LAST 54 57 }; 55 58 56 59 struct DummyObject { ··· 142 145 NULL); 143 146 object_class_property_add_enum(cls, "av", 144 147 "DummyAnimal", 145 - dummy_animal_map, 148 + &dummy_animal_map, 146 149 dummy_get_av, 147 150 dummy_set_av, 148 151 NULL);
+1 -1
tests/qmp-test.c
··· 181 181 g_assert(qdict_haskey(resp, "return")); 182 182 } else { 183 183 g_assert(error); 184 - g_assert_cmpint(qapi_enum_parse(QapiErrorClass_lookup, error_class, 184 + g_assert_cmpint(qapi_enum_parse(&QapiErrorClass_lookup, error_class, 185 185 -1, &error_abort), 186 186 ==, expected_error_class); 187 187 }
+5 -5
tests/test-qapi-util.c
··· 19 19 Error *err = NULL; 20 20 int ret; 21 21 22 - ret = qapi_enum_parse(QType_lookup, NULL, QTYPE_NONE, &error_abort); 22 + ret = qapi_enum_parse(&QType_lookup, NULL, QTYPE_NONE, &error_abort); 23 23 g_assert_cmpint(ret, ==, QTYPE_NONE); 24 24 25 - ret = qapi_enum_parse(QType_lookup, "junk", -1, NULL); 25 + ret = qapi_enum_parse(&QType_lookup, "junk", -1, NULL); 26 26 g_assert_cmpint(ret, ==, -1); 27 27 28 - ret = qapi_enum_parse(QType_lookup, "junk", -1, &err); 28 + ret = qapi_enum_parse(&QType_lookup, "junk", -1, &err); 29 29 error_free_or_abort(&err); 30 30 31 - ret = qapi_enum_parse(QType_lookup, "none", -1, &error_abort); 31 + ret = qapi_enum_parse(&QType_lookup, "none", -1, &error_abort); 32 32 g_assert_cmpint(ret, ==, QTYPE_NONE); 33 33 34 - ret = qapi_enum_parse(QType_lookup, QType_str(QTYPE__MAX - 1), 34 + ret = qapi_enum_parse(&QType_lookup, QType_str(QTYPE__MAX - 1), 35 35 QTYPE__MAX - 1, &error_abort); 36 36 g_assert_cmpint(ret, ==, QTYPE__MAX - 1); 37 37 }
+1 -1
tests/test-qobject-input-visitor.c
··· 1110 1110 error_free_or_abort(&err); 1111 1111 visit_optional(v, "optional", &present); 1112 1112 g_assert(!present); 1113 - visit_type_enum(v, "enum", &en, EnumOne_lookup, &err); 1113 + visit_type_enum(v, "enum", &en, &EnumOne_lookup, &err); 1114 1114 error_free_or_abort(&err); 1115 1115 visit_type_int(v, "i64", &i64, &err); 1116 1116 error_free_or_abort(&err);
+1 -1
tpm.c
··· 33 33 34 34 const TPMDriverOps *tpm_get_backend_driver(const char *type) 35 35 { 36 - int i = qapi_enum_parse(TpmType_lookup, type, -1, NULL); 36 + int i = qapi_enum_parse(&TpmType_lookup, type, -1, NULL); 37 37 38 38 return i >= 0 ? be_drivers[i] : NULL; 39 39 }