diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 63b9ce70f6..033eaf70c4 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -634,6 +634,12 @@ sc_prohibit_attribute_macros: halt='use GLib macros: G_GNUC_ for most' \ $(_sc_search_regexp) +sc_prohibit_non_glib_macros: + @prohibit='ARRAY_CARDINALITY' \ + in_vc_files='\.[ch]$$' \ + halt='use GLib macros: G_N_ELEMENTS' \ + $(_sc_search_regexp) + sc_prohibit_int_index: @prohibit='\<(int|unsigned)\s*\*?index\>(\s|,|;)' \ halt='use different name than 'index' for declaration' \ diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c index 24d9713cfd..31e1787919 100644 --- a/src/access/viraccessmanager.c +++ b/src/access/viraccessmanager.c @@ -118,7 +118,7 @@ static virAccessDriverPtr accessDrivers[] = { static virAccessDriverPtr virAccessManagerFindDriver(const char *name) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(accessDrivers); i++) { + for (i = 0; i < G_N_ELEMENTS(accessDrivers); i++) { if (STREQ(name, accessDrivers[i]->name)) return accessDrivers[i]; } diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index f5571b2188..3a92194602 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -215,7 +215,7 @@ virDomainCapsCPUModelsGet(virDomainCapsCPUModelsPtr cpuModels, #define VIR_DOMAIN_CAPS_ENUM_SET(capsEnum, ...) \ do { \ unsigned int __values[] = {__VA_ARGS__}; \ - size_t __nvalues = ARRAY_CARDINALITY(__values); \ + size_t __nvalues = G_N_ELEMENTS(__values); \ virDomainCapsEnumSet(&(capsEnum), #capsEnum, \ __nvalues, __values); \ } while (0) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c128d34ba2..10d6bf0eea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29809,7 +29809,7 @@ virDomainNetSetModelString(virDomainNetDefPtr net, if (!model) return 0; - for (i = 0; i < ARRAY_CARDINALITY(virDomainNetModelTypeList); i++) { + for (i = 0; i < G_N_ELEMENTS(virDomainNetModelTypeList); i++) { if (STRCASEEQ(virDomainNetModelTypeList[i], model)) { net->model = i; return 0; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fcd1701d37..2658f80e33 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -309,7 +309,7 @@ static virStoragePoolTypeInfoPtr virStoragePoolTypeInfoLookup(int type) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(poolTypeInfo); i++) + for (i = 0; i < G_N_ELEMENTS(poolTypeInfo); i++) if (poolTypeInfo[i].poolType == type) return &poolTypeInfo[i]; diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapshotobjlist.c index 95622f0ba7..910b0714c7 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -131,7 +131,7 @@ virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots, }; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(map); i++) { + for (i = 0; i < G_N_ELEMENTS(map); i++) { if (flags & map[i].snap_flag) { flags &= ~map[i].snap_flag; moment_flags |= map[i].moment_flag; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2278d79a77..40f725fd21 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -57,7 +57,7 @@ cpuGetSubDriver(virArch arch) return NULL; } - for (i = 0; i < ARRAY_CARDINALITY(drivers); i++) { + for (i = 0; i < G_N_ELEMENTS(drivers); i++) { for (j = 0; j < drivers[i]->narch; j++) { if (arch == drivers[i]->arch[j]) return drivers[i]; @@ -76,7 +76,7 @@ cpuGetSubDriverByName(const char *name) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(drivers); i++) { + for (i = 0; i < G_N_ELEMENTS(drivers); i++) { if (STREQ_NULLABLE(name, drivers[i]->name)) return drivers[i]; } diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index d464d7add2..c271e53a90 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -101,7 +101,7 @@ virCPUarmCompare(virCPUDefPtr host G_GNUC_UNUSED, struct cpuArchDriver cpuDriverArm = { .name = "arm", .arch = archs, - .narch = ARRAY_CARDINALITY(archs), + .narch = G_N_ELEMENTS(archs), .compare = virCPUarmCompare, .decode = NULL, .encode = NULL, diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index b11695f24d..1d9d6bca12 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -452,7 +452,7 @@ ppc64Compute(virCPUDefPtr host, if (cpu->arch != VIR_ARCH_NONE) { bool found = false; - for (i = 0; i < ARRAY_CARDINALITY(archs); i++) { + for (i = 0; i < G_N_ELEMENTS(archs); i++) { if (archs[i] == cpu->arch) { found = true; break; @@ -824,7 +824,7 @@ virCPUppc64DriverGetModels(char ***models) struct cpuArchDriver cpuDriverPPC64 = { .name = "ppc64", .arch = archs, - .narch = ARRAY_CARDINALITY(archs), + .narch = G_N_ELEMENTS(archs), .compare = virCPUppc64Compare, .decode = ppc64DriverDecode, .encode = NULL, diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c index 712e249f23..a4a381f4b8 100644 --- a/src/cpu/cpu_s390.c +++ b/src/cpu/cpu_s390.c @@ -114,7 +114,7 @@ virCPUs390ValidateFeatures(virCPUDefPtr cpu) struct cpuArchDriver cpuDriverS390 = { .name = "s390", .arch = archs, - .narch = ARRAY_CARDINALITY(archs), + .narch = G_N_ELEMENTS(archs), .compare = virCPUs390Compare, .decode = NULL, .encode = NULL, diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index b2b16ca512..70159a6613 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -68,7 +68,7 @@ struct _virCPUx86Feature { { \ .name = (char *) Name, \ .data = { \ - .len = ARRAY_CARDINALITY(Name ## _data), \ + .len = G_N_ELEMENTS(Name ## _data), \ .items = Name ## _data, \ } \ } @@ -364,7 +364,7 @@ static virCPUx86FeaturePtr x86FeatureFindInternal(const char *name) { size_t i; - size_t count = ARRAY_CARDINALITY(x86_kvm_features); + size_t count = G_N_ELEMENTS(x86_kvm_features); for (i = 0; i < count; i++) { if (STREQ(x86_kvm_features[i].name, name)) @@ -1757,7 +1757,7 @@ x86Compute(virCPUDefPtr host, if (cpu->arch != VIR_ARCH_NONE) { bool found = false; - for (i = 0; i < ARRAY_CARDINALITY(archs); i++) { + for (i = 0; i < G_N_ELEMENTS(archs); i++) { if (archs[i] == cpu->arch) { found = true; break; @@ -3422,7 +3422,7 @@ virCPUx86FeatureFilterDropMSR(const char *name, struct cpuArchDriver cpuDriverX86 = { .name = "x86", .arch = archs, - .narch = ARRAY_CARDINALITY(archs), + .narch = G_N_ELEMENTS(archs), .compare = virCPUx86Compare, .decode = x86DecodeCPUData, .encode = x86Encode, diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index fc21a7b6eb..004434c454 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -547,7 +547,7 @@ ESX_VI__TEMPLATE__FREE(SharedCURL, if (item->handle) curl_share_cleanup(item->handle); - for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i) + for (i = 0; i < G_N_ELEMENTS(item->locks); ++i) virMutexDestroy(&item->locks[i]); }) @@ -587,7 +587,7 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl) curl_share_setopt(shared->handle, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); - for (i = 0; i < ARRAY_CARDINALITY(shared->locks); ++i) { + for (i = 0; i < G_N_ELEMENTS(shared->locks); ++i) { if (virMutexInit(&shared->locks[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize a CURL (share) mutex")); diff --git a/src/internal.h b/src/internal.h index 59c58a72e1..25df0560af 100644 --- a/src/internal.h +++ b/src/internal.h @@ -91,7 +91,6 @@ ((a) ? !(b) || STRNEQ((a), (b)) : !!(b)) #define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0) -#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array))) /** * G_GNUC_NO_INLINE: diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 6b12ff5a03..68e8ffff3c 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -3323,7 +3323,7 @@ virDomainMigrateUnmanagedProto2(virDomainPtr domain, unsigned long long bandwidth = 0; if (!virTypedParamsCheck(params, nparams, compatParams, - ARRAY_CARDINALITY(compatParams))) { + G_N_ELEMENTS(compatParams))) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("Some parameters are not supported by migration " "protocol 2")); @@ -3372,7 +3372,7 @@ virDomainMigrateUnmanagedProto3(virDomainPtr domain, unsigned long long bandwidth = 0; if (!virTypedParamsCheck(params, nparams, compatParams, - ARRAY_CARDINALITY(compatParams))) { + G_N_ELEMENTS(compatParams))) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("Some parameters are not supported by migration " "protocol 3")); @@ -3933,7 +3933,7 @@ virDomainMigrate3(virDomainPtr domain, } if (!virTypedParamsCheck(params, nparams, compatParams, - ARRAY_CARDINALITY(compatParams))) { + G_N_ELEMENTS(compatParams))) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("Migration APIs with extensible parameters are not " "supported but extended parameters were passed")); diff --git a/src/libvirt-host.c b/src/libvirt-host.c index d7b1b82277..221a1b7a43 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -1551,7 +1551,7 @@ virNodeGetCPUMap(virConnectPtr conn, * Example how to use this API: * * unsigned int pages[] = { 4, 2048, 1048576} - * unsigned int npages = ARRAY_CARDINALITY(pages); + * unsigned int npages = G_N_ELEMENTS(pages); * int startcell = 0; * unsigned int cellcount = 2; * diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 65c68ffb52..54a8c090b0 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -134,11 +134,11 @@ libxlCapsNodeData(virCPUDefPtr cpu, libxl_hwcap hwcap, if (!(cpudata = virCPUDataNew(cpu->arch))) goto error; - ncaps = ARRAY_CARDINALITY(cpuid); + ncaps = G_N_ELEMENTS(cpuid); if (libxlCapsAddCPUID(cpudata, cpuid, ncaps) < 0) goto error; - ncaps = ARRAY_CARDINALITY(cpuid_ver1); + ncaps = G_N_ELEMENTS(cpuid_ver1); if (version > LIBXL_HWCAP_V0 && libxlCapsAddCPUID(cpudata, cpuid_ver1, ncaps) < 0) goto error; @@ -471,7 +471,7 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) } /* Too many arch flavours - highly unlikely ! */ - if (i >= ARRAY_CARDINALITY(guest_archs)) + if (i >= G_N_ELEMENTS(guest_archs)) continue; /* Didn't find a match, so create a new one */ if (i == nr_guest_archs) @@ -500,7 +500,7 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) #ifdef HAVE_XEN_PVH if (hvm && i == nr_guest_archs-1) { /* Ensure we have not exhausted the guest_archs array */ - if (nr_guest_archs >= ARRAY_CARDINALITY(guest_archs)) + if (nr_guest_archs >= G_N_ELEMENTS(guest_archs)) continue; i = nr_guest_archs; nr_guest_archs++; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 7153a82e20..59398a0a4d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5339,7 +5339,7 @@ libxlDiskPathToID(const char *virtpath) fmt = id = -1; /* Find any disk prefixes we know about */ - for (i = 0; i < ARRAY_CARDINALITY(drive_prefix); i++) { + for (i = 0; i < G_N_ELEMENTS(drive_prefix); i++) { if (STRPREFIX(virtpath, drive_prefix[i]) && !virDiskNameParse(virtpath, &disk, &partition)) { fmt = i; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index ea325bf2cb..8a41e9374d 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -860,7 +860,7 @@ static void libxlTunnel3MigrationSrcFunc(void *arg) fds[0].events = POLLIN; fds[0].revents = 0; - ret = poll(fds, ARRAY_CARDINALITY(fds), timeout); + ret = poll(fds, G_N_ELEMENTS(fds), timeout); if (ret < 0) { if (errno == EAGAIN || errno == EINTR) continue; @@ -1138,7 +1138,7 @@ static int virConnectCredType[] = { static virConnectAuth virConnectAuthConfig = { .credtype = virConnectCredType, - .ncredtype = ARRAY_CARDINALITY(virConnectCredType), + .ncredtype = G_N_ELEMENTS(virConnectCredType), }; /* On P2P mode there is only the Perform3 phase and we need to handle diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 015f0aa620..9e3d307078 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -250,7 +250,7 @@ xenTranslateCPUFeature(const char *feature_name, bool from_libxl) }; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(translation_table); i++) + for (i = 0; i < G_N_ELEMENTS(translation_table); i++) if (STREQ(translation_table[i][from_libxl], feature_name)) return translation_table[i][!from_libxl]; return feature_name; diff --git a/src/locking/domain_lock.c b/src/locking/domain_lock.c index d91ac83c45..bc281eac54 100644 --- a/src/locking/domain_lock.c +++ b/src/locking/domain_lock.c @@ -50,7 +50,7 @@ static int virDomainLockManagerAddLease(virLockManagerPtr lock, .value = { .str = lease->lockspace }, }, }; - size_t nparams = ARRAY_CARDINALITY(lparams); + size_t nparams = G_N_ELEMENTS(lparams); if (!lease->lockspace) nparams--; @@ -137,7 +137,7 @@ static virLockManagerPtr virDomainLockManagerNew(virLockManagerPluginPtr plugin, if (!(lock = virLockManagerNew(virLockManagerPluginGetDriver(plugin), VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN, - ARRAY_CARDINALITY(params), + G_N_ELEMENTS(params), params, flags))) goto error; diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 59167d7d31..baffaa6de9 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -314,7 +314,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) } if (!(lockd->dmn = virNetDaemonNewPostExecRestart(child, - ARRAY_CARDINALITY(serverNames), + G_N_ELEMENTS(serverNames), serverNames, virLockDaemonNewServerPostExecRestart, (void*)(intptr_t)(privileged ? 0x1 : 0x0)))) @@ -1317,7 +1317,7 @@ int main(int argc, char **argv) { } if (virSystemdGetActivation(actmap, - ARRAY_CARDINALITY(actmap), + G_N_ELEMENTS(actmap), &act) < 0) { ret = VIR_LOCK_DAEMON_ERR_NETWORK; goto cleanup; diff --git a/src/locking/sanlock_helper.c b/src/locking/sanlock_helper.c index e07db8a6df..50deccfd67 100644 --- a/src/locking/sanlock_helper.c +++ b/src/locking/sanlock_helper.c @@ -63,7 +63,7 @@ main(int argc, char **argv) }; virConnectAuth auth = { .credtype = authTypes, - .ncredtype = ARRAY_CARDINALITY(authTypes), + .ncredtype = G_N_ELEMENTS(authTypes), .cb = authCallback, }; diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index e56dbf2919..c667e31185 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -266,7 +266,7 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged, } if (!(logd->dmn = virNetDaemonNewPostExecRestart(child, - ARRAY_CARDINALITY(serverNames), + G_N_ELEMENTS(serverNames), serverNames, virLogDaemonNewServerPostExecRestart, (void*)(intptr_t)(privileged ? 0x1 : 0x0)))) @@ -1090,7 +1090,7 @@ int main(int argc, char **argv) { } if (virSystemdGetActivation(actmap, - ARRAY_CARDINALITY(actmap), + G_N_ELEMENTS(actmap), &act) < 0) { ret = VIR_LOG_DAEMON_ERR_NETWORK; goto cleanup; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 7fcbbb424a..5002356fe7 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -823,7 +823,7 @@ bool lxcIsBasicMountLocation(const char *path) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(lxcBasicMounts); i++) { + for (i = 0; i < G_N_ELEMENTS(lxcBasicMounts); i++) { if (STREQ(path, lxcBasicMounts[i].dst)) return true; } @@ -900,7 +900,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled, VIR_DEBUG("Mounting basic filesystems"); - for (i = 0; i < ARRAY_CARDINALITY(lxcBasicMounts); i++) { + for (i = 0; i < G_N_ELEMENTS(lxcBasicMounts); i++) { bool bindOverReadonly; virLXCBasicMountInfo const *mnt = &lxcBasicMounts[i]; @@ -1126,7 +1126,7 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths) { "/proc/self/fd", "/dev/fd" }, }; - for (i = 0; i < ARRAY_CARDINALITY(links); i++) { + for (i = 0; i < G_N_ELEMENTS(links); i++) { if (symlink(links[i].src, links[i].dst) < 0) { virReportSystemError(errno, _("Failed to symlink device %s to %s"), diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index a1f4ae8812..3c4e68524c 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1521,7 +1521,7 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) goto cleanup; /* Populate /dev/ with a few important bits */ - for (i = 0; i < ARRAY_CARDINALITY(devs); i++) { + for (i = 0; i < G_N_ELEMENTS(devs); i++) { if (virAsprintf(&path, "/%s/%s.dev/%s", LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0) goto cleanup; diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 4e67e29293..028e401236 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -171,7 +171,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, if (!(mon->program = virNetClientProgramNew(VIR_LXC_MONITOR_PROGRAM, VIR_LXC_MONITOR_PROGRAM_VERSION, virLXCMonitorEvents, - ARRAY_CARDINALITY(virLXCMonitorEvents), + G_N_ELEMENTS(virLXCMonitorEvents), mon))) goto error; diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index b046f03c83..32e99bc830 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -362,7 +362,7 @@ gather_capability(LibHalContext *ctx, const char *udi, { caps_tbl_entry *entry; - entry = bsearch(&cap_name, caps_tbl, ARRAY_CARDINALITY(caps_tbl), + entry = bsearch(&cap_name, caps_tbl, G_N_ELEMENTS(caps_tbl), sizeof(caps_tbl[0]), cmpstringp); if (entry) { @@ -604,7 +604,7 @@ nodeStateInitialize(bool privileged G_GNUC_UNUSED, DBusError err; /* Ensure caps_tbl is sorted by capability name */ - qsort(caps_tbl, ARRAY_CARDINALITY(caps_tbl), sizeof(caps_tbl[0]), + qsort(caps_tbl, G_N_ELEMENTS(caps_tbl), sizeof(caps_tbl[0]), cmpstringp); if (VIR_ALLOC(driver) < 0) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 80d39e9509..75cf576c3c 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1425,7 +1425,7 @@ udevEnumerateAddMatches(struct udev_enumerate *udev_enumerate) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(subsystem_blacklist); i++) { + for (i = 0; i < G_N_ELEMENTS(subsystem_blacklist); i++) { const char *s = subsystem_blacklist[i]; if (udev_enumerate_add_nomatch_subsystem(udev_enumerate, s) < 0) { virReportSystemError(errno, "%s", _("failed to add susbsystem filter")); diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index dae2ad611d..90f3933959 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -1382,7 +1382,7 @@ virNWFilterDHCPSnoopThread(void *req0) virNWFilterSnoopReqLock(req); if (req->binding->portdevname && req->threadkey) { - for (i = 0; i < ARRAY_CARDINALITY(pcapConf); i++) { + for (i = 0; i < G_N_ELEMENTS(pcapConf); i++) { pcapConf[i].handle = virNWFilterSnoopDHCPOpen(req->binding->portdevname, &req->binding->mac, @@ -1419,7 +1419,7 @@ virNWFilterDHCPSnoopThread(void *req0) while (!error) { if (virNWFilterSnoopAdjustPoll(pcapConf, - ARRAY_CARDINALITY(pcapConf), + G_N_ELEMENTS(pcapConf), fds, &pollTo) < 0) { break; } @@ -1428,7 +1428,7 @@ virNWFilterDHCPSnoopThread(void *req0) if (pollTo < 0 || pollTo > SNOOP_POLL_MAX_TIMEOUT_MS) pollTo = SNOOP_POLL_MAX_TIMEOUT_MS; - n = poll(fds, ARRAY_CARDINALITY(fds), pollTo); + n = poll(fds, G_N_ELEMENTS(fds), pollTo); if (n < 0) { if (errno != EAGAIN && errno != EINTR) @@ -1445,7 +1445,7 @@ virNWFilterDHCPSnoopThread(void *req0) req->jobCompletionStatus != 0) goto exit; - for (i = 0; n > 0 && i < ARRAY_CARDINALITY(fds); i++) { + for (i = 0; n > 0 && i < G_N_ELEMENTS(fds); i++) { if (!fds[i].revents) continue; @@ -1567,7 +1567,7 @@ virNWFilterDHCPSnoopThread(void *req0) VIR_FREE(threadkey); - for (i = 0; i < ARRAY_CARDINALITY(pcapConf); i++) { + for (i = 0; i < G_N_ELEMENTS(pcapConf); i++) { if (pcapConf[i].handle) pcap_close(pcapConf[i].handle); } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 36bc3b06da..d7754c0c7a 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -479,7 +479,7 @@ learnIPAddressThread(void *arg) pcap_freecode(&fp); while (req->status == 0 && vmaddr == 0) { - int n = poll(fds, ARRAY_CARDINALITY(fds), PKT_TIMEOUT_MS); + int n = poll(fds, G_N_ELEMENTS(fds), PKT_TIMEOUT_MS); if (threadsTerminate || req->terminate) { req->status = ECANCELED; diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 572ca9e2cb..2b4dd7c9bb 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -127,7 +127,7 @@ waitsocket(int socket_fd, LIBSSH2_SESSION * session) if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) fds[0].events |= POLLOUT; - return poll(fds, ARRAY_CARDINALITY(fds), -1); + return poll(fds, G_N_ELEMENTS(fds), -1); } /* this function is the layer that manipulates the ssh channel itself diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 62edb665a7..9e4b4d802e 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -264,7 +264,7 @@ qemuAgentIOProcessEvent(qemuAgentPtr mon, } /* - for (i = 0; i < ARRAY_CARDINALITY(eventHandlers); i++) { + for (i = 0; i < G_N_ELEMENTS(eventHandlers); i++) { if (STREQ(eventHandlers[i].type, type)) { virJSONValuePtr data = virJSONValueObjectGet(obj, "data"); VIR_DEBUG("handle %s handler=%p data=%p", type, diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index cbd4ebc8ea..efd71d69c5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1313,103 +1313,103 @@ typedef int (*virQEMUCapsObjectTypePropsCB)(qemuMonitorPtr mon, static virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = { { "virtio-blk-pci", virQEMUCapsDevicePropsVirtioBlk, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBlk), -1 }, { "virtio-net-pci", virQEMUCapsDevicePropsVirtioNet, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioNet), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioNet), QEMU_CAPS_DEVICE_VIRTIO_NET }, { "virtio-scsi-pci", virQEMUCapsDevicePropsVirtioSCSI, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioSCSI), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioSCSI), QEMU_CAPS_VIRTIO_SCSI }, { "virtio-blk-ccw", virQEMUCapsDevicePropsVirtioBlk, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBlk), QEMU_CAPS_VIRTIO_CCW }, { "virtio-net-ccw", virQEMUCapsDevicePropsVirtioNet, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioNet), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioNet), QEMU_CAPS_DEVICE_VIRTIO_NET }, { "virtio-scsi-ccw", virQEMUCapsDevicePropsVirtioSCSI, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioSCSI), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioSCSI), QEMU_CAPS_VIRTIO_SCSI }, { "virtio-blk-s390", virQEMUCapsDevicePropsVirtioBlk, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBlk), QEMU_CAPS_VIRTIO_S390 }, { "virtio-net-s390", virQEMUCapsDevicePropsVirtioNet, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioNet), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioNet), QEMU_CAPS_DEVICE_VIRTIO_NET }, { "vfio-pci", virQEMUCapsDevicePropsVfioPCI, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVfioPCI), + G_N_ELEMENTS(virQEMUCapsDevicePropsVfioPCI), QEMU_CAPS_DEVICE_VFIO_PCI }, { "scsi-hd", virQEMUCapsDevicePropsSCSIDisk, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsSCSIDisk), + G_N_ELEMENTS(virQEMUCapsDevicePropsSCSIDisk), -1 }, { "ide-hd", virQEMUCapsDevicePropsIDEDrive, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsIDEDrive), + G_N_ELEMENTS(virQEMUCapsDevicePropsIDEDrive), -1 }, { "PIIX4_PM", virQEMUCapsDevicePropsPiix4PM, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsPiix4PM), + G_N_ELEMENTS(virQEMUCapsDevicePropsPiix4PM), -1 }, { "usb-redir", virQEMUCapsDevicePropsUSBRedir, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsUSBRedir), + G_N_ELEMENTS(virQEMUCapsDevicePropsUSBRedir), QEMU_CAPS_USB_REDIR }, { "i440FX-pcihost", virQEMUCapsDevicePropsI440FXPCIHost, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsI440FXPCIHost), + G_N_ELEMENTS(virQEMUCapsDevicePropsI440FXPCIHost), -1 }, { "q35-pcihost", virQEMUCapsDevicePropsQ35PCIHost, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsQ35PCIHost), + G_N_ELEMENTS(virQEMUCapsDevicePropsQ35PCIHost), -1 }, { "usb-storage", virQEMUCapsDevicePropsUSBStorage, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsUSBStorage), + G_N_ELEMENTS(virQEMUCapsDevicePropsUSBStorage), QEMU_CAPS_DEVICE_USB_STORAGE }, { "kvm-pit", virQEMUCapsDevicePropsKVMPit, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsKVMPit), + G_N_ELEMENTS(virQEMUCapsDevicePropsKVMPit), -1 }, { "VGA", virQEMUCapsDevicePropsVGA, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVGA), + G_N_ELEMENTS(virQEMUCapsDevicePropsVGA), QEMU_CAPS_DEVICE_VGA }, { "vmware-svga", virQEMUCapsDevicePropsVmwareSvga, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVmwareSvga), + G_N_ELEMENTS(virQEMUCapsDevicePropsVmwareSvga), QEMU_CAPS_DEVICE_VMWARE_SVGA }, { "qxl", virQEMUCapsDevicePropsQxl, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsQxl), + G_N_ELEMENTS(virQEMUCapsDevicePropsQxl), QEMU_CAPS_DEVICE_QXL }, { "virtio-gpu-pci", virQEMUCapsDevicePropsVirtioGpu, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioGpu), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioGpu), QEMU_CAPS_DEVICE_VIRTIO_GPU }, { "virtio-gpu-device", virQEMUCapsDevicePropsVirtioGpu, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioGpu), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioGpu), QEMU_CAPS_DEVICE_VIRTIO_GPU }, { "ICH9-LPC", virQEMUCapsDevicePropsICH9, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsICH9), + G_N_ELEMENTS(virQEMUCapsDevicePropsICH9), -1 }, { "virtio-balloon-pci", virQEMUCapsDevicePropsVirtioBalloon, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBalloon), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBalloon), -1 }, { "virtio-balloon-ccw", virQEMUCapsDevicePropsVirtioBalloon, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBalloon), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBalloon), -1 }, { "virtio-balloon-device", virQEMUCapsDevicePropsVirtioBalloon, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBalloon), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioBalloon), -1 }, { "nec-usb-xhci", virQEMUCapsDevicePropsUSBNECXHCI, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsUSBNECXHCI), + G_N_ELEMENTS(virQEMUCapsDevicePropsUSBNECXHCI), QEMU_CAPS_NEC_USB_XHCI }, { "intel-iommu", virQEMUCapsDevicePropsIntelIOMMU, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsIntelIOMMU), + G_N_ELEMENTS(virQEMUCapsDevicePropsIntelIOMMU), QEMU_CAPS_DEVICE_INTEL_IOMMU }, { "spapr-pci-host-bridge", virQEMUCapsDevicePropsSpaprPCIHostBridge, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsSpaprPCIHostBridge), + G_N_ELEMENTS(virQEMUCapsDevicePropsSpaprPCIHostBridge), QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE }, { "virtio-gpu-ccw", virQEMUCapsDevicePropsVirtioGpu, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioGpu), + G_N_ELEMENTS(virQEMUCapsDevicePropsVirtioGpu), QEMU_CAPS_DEVICE_VIRTIO_GPU_CCW }, { "virtual-css-bridge", virQEMUCapsObjectPropsVirtualCSSBridge, - ARRAY_CARDINALITY(virQEMUCapsObjectPropsVirtualCSSBridge), + G_N_ELEMENTS(virQEMUCapsObjectPropsVirtualCSSBridge), QEMU_CAPS_CCW }, { "mch", virQEMUCapsDevicePropsMCH, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsMCH), + G_N_ELEMENTS(virQEMUCapsDevicePropsMCH), QEMU_CAPS_DEVICE_MCH }, { "nvdimm", virQEMUCapsDevicePropsNVDIMM, - ARRAY_CARDINALITY(virQEMUCapsDevicePropsNVDIMM), + G_N_ELEMENTS(virQEMUCapsDevicePropsNVDIMM), QEMU_CAPS_DEVICE_NVDIMM }, }; @@ -1429,13 +1429,13 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsMaxX86CPU[] = { static virQEMUCapsObjectTypeProps virQEMUCapsObjectProps[] = { { "memory-backend-file", virQEMUCapsObjectPropsMemoryBackendFile, - ARRAY_CARDINALITY(virQEMUCapsObjectPropsMemoryBackendFile), + G_N_ELEMENTS(virQEMUCapsObjectPropsMemoryBackendFile), QEMU_CAPS_OBJECT_MEMORY_FILE }, { "memory-backend-memfd", virQEMUCapsObjectPropsMemoryBackendMemfd, - ARRAY_CARDINALITY(virQEMUCapsObjectPropsMemoryBackendMemfd), + G_N_ELEMENTS(virQEMUCapsObjectPropsMemoryBackendMemfd), QEMU_CAPS_OBJECT_MEMORY_MEMFD }, { "max-x86_64-cpu", virQEMUCapsObjectPropsMaxX86CPU, - ARRAY_CARDINALITY(virQEMUCapsObjectPropsMaxX86CPU), + G_N_ELEMENTS(virQEMUCapsObjectPropsMaxX86CPU), QEMU_CAPS_X86_MAX_CPU }, }; @@ -1452,10 +1452,10 @@ static struct virQEMUCapsStringFlags virQEMUCapsMachinePropsVirt[] = { static virQEMUCapsObjectTypeProps virQEMUCapsMachineProps[] = { { "pseries", virQEMUCapsMachinePropsPSeries, - ARRAY_CARDINALITY(virQEMUCapsMachinePropsPSeries), + G_N_ELEMENTS(virQEMUCapsMachinePropsPSeries), -1 }, { "virt", virQEMUCapsMachinePropsVirt, - ARRAY_CARDINALITY(virQEMUCapsMachinePropsVirt), + G_N_ELEMENTS(virQEMUCapsMachinePropsVirt), -1 }, }; @@ -2171,7 +2171,7 @@ virQEMUCapsProbeQMPCommands(virQEMUCapsPtr qemuCaps, return -1; virQEMUCapsProcessStringFlags(qemuCaps, - ARRAY_CARDINALITY(virQEMUCapsCommands), + G_N_ELEMENTS(virQEMUCapsCommands), virQEMUCapsCommands, ncommands, commands); virStringListFreeCount(commands, ncommands); @@ -2201,7 +2201,7 @@ virQEMUCapsProbeQMPEvents(virQEMUCapsPtr qemuCaps, return -1; virQEMUCapsProcessStringFlags(qemuCaps, - ARRAY_CARDINALITY(virQEMUCapsEvents), + G_N_ELEMENTS(virQEMUCapsEvents), virQEMUCapsEvents, nevents, events); virStringListFreeCount(events, nevents); @@ -2249,7 +2249,7 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps, if ((nvalues = qemuMonitorGetObjectTypes(mon, &values)) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, - ARRAY_CARDINALITY(virQEMUCapsObjectTypes), + G_N_ELEMENTS(virQEMUCapsObjectTypes), virQEMUCapsObjectTypes, nvalues, values); virStringListFreeCount(values, nvalues); @@ -2257,7 +2257,7 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps, if (virQEMUCapsProbeQMPGenericProps(qemuCaps, mon, virQEMUCapsDeviceProps, - ARRAY_CARDINALITY(virQEMUCapsDeviceProps), + G_N_ELEMENTS(virQEMUCapsDeviceProps), qemuMonitorGetDeviceProps) < 0) return -1; @@ -2265,7 +2265,7 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps, virQEMUCapsProbeQMPGenericProps(qemuCaps, mon, virQEMUCapsObjectProps, - ARRAY_CARDINALITY(virQEMUCapsObjectProps), + G_N_ELEMENTS(virQEMUCapsObjectProps), qemuMonitorGetObjectProps) < 0) return -1; @@ -2330,7 +2330,7 @@ static const char *preferredMachines[] = "sim", /* VIR_ARCH_XTENSA */ "sim", /* VIR_ARCH_XTENSAEB */ }; -verify(ARRAY_CARDINALITY(preferredMachines) == VIR_ARCH_LAST); +verify(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); static int @@ -2412,7 +2412,7 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps, if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QOM_LIST_PROPERTIES)) return 0; - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsMachineProps); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsMachineProps); i++) { virQEMUCapsObjectTypeProps props = virQEMUCapsMachineProps[i]; const char *canon = virQEMUCapsGetCanonicalMachine(qemuCaps, props.type); VIR_AUTOFREE(char *) type = NULL; @@ -2717,7 +2717,7 @@ virQEMUCapsProbeQMPTPM(virQEMUCapsPtr qemuCaps, return -1; if (nentries > 0) { - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsTPMModelsToCaps); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) { const char *needle = virDomainTPMModelTypeToString( virQEMUCapsTPMModelsToCaps[i].type); if (virStringListHasString((const char **)entries, needle)) @@ -2731,7 +2731,7 @@ virQEMUCapsProbeQMPTPM(virQEMUCapsPtr qemuCaps, return -1; if (nentries > 0) { - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsTPMTypesToCaps); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { const char *needle = virDomainTPMBackendTypeToString( virQEMUCapsTPMTypesToCaps[i].type); if (virStringListHasString((const char **)entries, needle)) @@ -2808,7 +2808,7 @@ virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, char **values; size_t i, j; - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsCommandLine); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsCommandLine); i++) { if ((nvalues = qemuMonitorGetCommandLineOptionParameters(mon, virQEMUCapsCommandLine[i].option, &values, @@ -2841,7 +2841,7 @@ virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCapsPtr qemuCaps, return -1; virQEMUCapsProcessStringFlags(qemuCaps, - ARRAY_CARDINALITY(virQEMUCapsMigration), + G_N_ELEMENTS(virQEMUCapsMigration), virQEMUCapsMigration, ncaps, caps); virStringListFreeCount(caps, ncaps); @@ -4155,7 +4155,7 @@ virQEMUCapsKVMSupportsNesting(void) int rc; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(kmod); i++) { + for (i = 0; i < G_N_ELEMENTS(kmod); i++) { VIR_FREE(value); rc = virFileReadValueString(&value, "/sys/module/%s/parameters/nested", kmod[i]); @@ -4513,7 +4513,7 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCapsPtr qemuCaps, return -1; schemareply = NULL; - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsQMPSchemaQueries); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsQMPSchemaQueries); i++) { entry = virQEMUCapsQMPSchemaQueries + i; if (virQEMUQAPISchemaPathExists(entry->value, schema)) @@ -4521,7 +4521,7 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCapsPtr qemuCaps, } /* probe also for basic event support */ - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsEvents); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsEvents); i++) { entry = virQEMUCapsEvents + i; if (virQEMUQAPISchemaPathExists(entry->value, schema)) @@ -4816,7 +4816,7 @@ struct virQEMUCapsMachineTypeFilter { static const struct virQEMUCapsMachineTypeFilter virQEMUCapsMachineFilter[] = { /* { "blah", virQEMUCapsMachineBLAHFilter, - ARRAY_CARDINALITY(virQEMUCapsMachineBLAHFilter) }, */ + G_N_ELEMENTS(virQEMUCapsMachineBLAHFilter) }, */ { "", NULL, 0 }, }; @@ -4830,7 +4830,7 @@ virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, if (!machineType) return; - for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsMachineFilter); i++) { + for (i = 0; i < G_N_ELEMENTS(virQEMUCapsMachineFilter); i++) { const struct virQEMUCapsMachineTypeFilter *filter = &virQEMUCapsMachineFilter[i]; size_t j; @@ -4977,8 +4977,8 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache, priv->microcodeVersion = virHostCPUGetMicrocodeVersion(); - for (i = 0; i < ARRAY_CARDINALITY(binaryFilters); i++) { - for (j = 0; j < ARRAY_CARDINALITY(archs); j++) { + for (i = 0; i < G_N_ELEMENTS(binaryFilters); i++) { + for (j = 0; j < G_N_ELEMENTS(archs); j++) { struct virQEMUCapsSearchData data = { .arch = archs[j], .binaryFilter = binaryFilters[i], diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d2fc7b6f1e..c2a19689c5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3234,7 +3234,7 @@ qemuBuildControllersCommandLine(virCommandPtr cmd, VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, }; - for (i = 0; i < ARRAY_CARDINALITY(contOrder); i++) { + for (i = 0; i < G_N_ELEMENTS(contOrder); i++) { if (qemuBuildControllersByTypeCommandLine(cmd, def, qemuCaps, contOrder[i]) < 0) return -1; } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 4df0ca78f5..08cd784054 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1280,7 +1280,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) VIR_STRDUP(sm->doi, doi) < 0) return NULL; - for (j = 0; j < ARRAY_CARDINALITY(virtTypes); j++) { + for (j = 0; j < G_N_ELEMENTS(virtTypes); j++) { lbl = qemuSecurityGetBaseLabel(sec_managers[i], virtTypes[j]); type = virDomainVirtTypeToString(virtTypes[j]); if (lbl && diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e11c0c8ea2..c638077aa8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11712,7 +11712,7 @@ ppc64VFIODeviceIsNV2Bridge(const char *device) "ibm,nvlink-speed", "memory-region"}; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(nvlink2Files); i++) { + for (i = 0; i < G_N_ELEMENTS(nvlink2Files); i++) { VIR_AUTOFREE(char *) file = NULL; if ((virAsprintf(&file, "/sys/bus/pci/devices/%s/of_node/%s", diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 59661fd6b0..52ef1874aa 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3149,7 +3149,7 @@ static void qemuMigrationSrcIOFunc(void *arg) fds[0].events = fds[1].events = POLLIN; fds[0].revents = fds[1].revents = 0; - ret = poll(fds, ARRAY_CARDINALITY(fds), timeout); + ret = poll(fds, G_N_ELEMENTS(fds), timeout); if (ret < 0) { if (errno == EAGAIN || errno == EINTR) @@ -4395,7 +4395,7 @@ static int virConnectCredType[] = { static virConnectAuth virConnectAuthConfig = { .credtype = virConnectCredType, - .ncredtype = ARRAY_CARDINALITY(virConnectCredType), + .ncredtype = G_N_ELEMENTS(virConnectCredType), }; diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index e296fc1927..85fa8f8de5 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -214,7 +214,7 @@ static const qemuMigrationParamType qemuMigrationParamTypes[] = { [QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH] = QEMU_MIGRATION_PARAM_TYPE_ULL, [QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS] = QEMU_MIGRATION_PARAM_TYPE_INT, }; -verify(ARRAY_CARDINALITY(qemuMigrationParamTypes) == QEMU_MIGRATION_PARAM_LAST); +verify(G_N_ELEMENTS(qemuMigrationParamTypes) == QEMU_MIGRATION_PARAM_LAST); virBitmapPtr @@ -226,7 +226,7 @@ qemuMigrationParamsGetAlwaysOnCaps(qemuMigrationParty party) if (!(caps = virBitmapNew(QEMU_MIGRATION_CAP_LAST))) return NULL; - for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsAlwaysOn); i++) { + for (i = 0; i < G_N_ELEMENTS(qemuMigrationParamsAlwaysOn); i++) { if (!(qemuMigrationParamsAlwaysOn[i].party & party)) continue; @@ -500,7 +500,7 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params, if (!(migParams = qemuMigrationParamsNew())) return NULL; - for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsFlagMap); i++) { + for (i = 0; i < G_N_ELEMENTS(qemuMigrationParamsFlagMap); i++) { qemuMigrationCapability cap = qemuMigrationParamsFlagMap[i].cap; if (qemuMigrationParamsFlagMap[i].party & party && @@ -511,7 +511,7 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params, } } - for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsTPMap); i++) { + for (i = 0; i < G_N_ELEMENTS(qemuMigrationParamsTPMap); i++) { const qemuMigrationParamsTPMapItem *item = &qemuMigrationParamsTPMap[i]; if (!(item->party & party)) @@ -590,7 +590,7 @@ qemuMigrationParamsDump(qemuMigrationParamsPtr migParams, return -1; } - for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsTPMap); i++) { + for (i = 0; i < G_N_ELEMENTS(qemuMigrationParamsTPMap); i++) { const qemuMigrationParamsTPMapItem *item = &qemuMigrationParamsTPMap[i]; if (!(item->party & QEMU_MIGRATION_DESTINATION)) @@ -1149,7 +1149,7 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver, } } - for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsAlwaysOn); i++) { + for (i = 0; i < G_N_ELEMENTS(qemuMigrationParamsAlwaysOn); i++) { cap = qemuMigrationParamsAlwaysOn[i].cap; if (qemuMigrationParamsAlwaysOn[i].party & party && diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1e55b166fa..d3447dd2f3 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -200,7 +200,7 @@ qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon, qemuMonitorEmitEvent(mon, type, seconds, micros, details); VIR_FREE(details); - handler = bsearch(type, eventHandlers, ARRAY_CARDINALITY(eventHandlers), + handler = bsearch(type, eventHandlers, G_N_ELEMENTS(eventHandlers), sizeof(eventHandlers[0]), qemuMonitorEventCompare); if (handler) { VIR_DEBUG("handle %s handler=%p data=%p", type, diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c index 5101ed6aae..2fc56dcfa4 100644 --- a/src/qemu/qemu_qapi.c +++ b/src/qemu/qemu_qapi.c @@ -357,7 +357,7 @@ virQEMUQAPISchemaTraverse(const char *baseName, if (!(metatype = virJSONValueObjectGetString(cur, "meta-type"))) return -2; - for (i = 0; i < ARRAY_CARDINALITY(traverseMetaType); i++) { + for (i = 0; i < G_N_ELEMENTS(traverseMetaType); i++) { if (STREQ(metatype, traverseMetaType[i].metatype)) return traverseMetaType[i].func(cur, ctxt); } diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 5f50d07002..916b14dc7f 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -419,7 +419,7 @@ daemonSetupNetworking(virNetServerPtr srv, return -1; #endif /* ! WITH_IP */ - if (virSystemdGetActivation(actmap, ARRAY_CARDINALITY(actmap), &act) < 0) + if (virSystemdGetActivation(actmap, G_N_ELEMENTS(actmap), &act) < 0) return -1; #ifdef WITH_IP @@ -955,7 +955,7 @@ daemonUsage(const char *argv0, bool privileged) fprintf(stderr, "\n"); fprintf(stderr, "%s\n", _("Options:")); - for (i = 0; i < ARRAY_CARDINALITY(opthelp); i++) + for (i = 0; i < G_N_ELEMENTS(opthelp); i++) fprintf(stderr, " %-22s %s\n", opthelp[i].opts, _(opthelp[i].help)); fprintf(stderr, "\n"); diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index cd929c36da..9153791b3c 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1493,7 +1493,7 @@ static virConnectDomainEventGenericCallback domainEventCallbacks[] = { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), }; -verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST); +verify(G_N_ELEMENTS(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST); static int remoteRelayNetworkEventLifecycle(virConnectPtr conn, @@ -1536,7 +1536,7 @@ static virConnectNetworkEventGenericCallback networkEventCallbacks[] = { VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventLifecycle), }; -verify(ARRAY_CARDINALITY(networkEventCallbacks) == VIR_NETWORK_EVENT_ID_LAST); +verify(G_N_ELEMENTS(networkEventCallbacks) == VIR_NETWORK_EVENT_ID_LAST); static int remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, @@ -1615,7 +1615,7 @@ static virConnectStoragePoolEventGenericCallback storageEventCallbacks[] = { VIR_STORAGE_POOL_EVENT_CALLBACK(remoteRelayStoragePoolEventRefresh), }; -verify(ARRAY_CARDINALITY(storageEventCallbacks) == VIR_STORAGE_POOL_EVENT_ID_LAST); +verify(G_N_ELEMENTS(storageEventCallbacks) == VIR_STORAGE_POOL_EVENT_ID_LAST); static int remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, @@ -1694,7 +1694,7 @@ static virConnectNodeDeviceEventGenericCallback nodeDeviceEventCallbacks[] = { VIR_NODE_DEVICE_EVENT_CALLBACK(remoteRelayNodeDeviceEventUpdate), }; -verify(ARRAY_CARDINALITY(nodeDeviceEventCallbacks) == VIR_NODE_DEVICE_EVENT_ID_LAST); +verify(G_N_ELEMENTS(nodeDeviceEventCallbacks) == VIR_NODE_DEVICE_EVENT_ID_LAST); static int remoteRelaySecretEventLifecycle(virConnectPtr conn, @@ -1773,7 +1773,7 @@ static virConnectSecretEventGenericCallback secretEventCallbacks[] = { VIR_SECRET_EVENT_CALLBACK(remoteRelaySecretEventValueChanged), }; -verify(ARRAY_CARDINALITY(secretEventCallbacks) == VIR_SECRET_EVENT_ID_LAST); +verify(G_N_ELEMENTS(secretEventCallbacks) == VIR_SECRET_EVENT_ID_LAST); static void remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, @@ -2176,7 +2176,7 @@ remoteDispatchProbeURI(bool readonly, }; ssize_t i; - for (i = 0; i < (ssize_t) ARRAY_CARDINALITY(drivers) && !*probeduri; i++) { + for (i = 0; i < (ssize_t) G_N_ELEMENTS(drivers) && !*probeduri; i++) { VIR_AUTOFREE(char *) daemonname = NULL; VIR_AUTOFREE(char *) daemonpath = NULL; @@ -2222,7 +2222,7 @@ remoteDispatchProbeURI(bool readonly, }; ssize_t i; - for (i = 0; i < (ssize_t) ARRAY_CARDINALITY(drivers) && !*probeduri; i++) { + for (i = 0; i < (ssize_t) G_N_ELEMENTS(drivers) && !*probeduri; i++) { VIR_AUTOFREE(char *) sockname = NULL; if (virAsprintf(&sockname, "%s/libvirt/virt%sd-%s", diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index bd4017c4dc..5251079282 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1313,7 +1313,7 @@ doRemoteOpen(virConnectPtr conn, if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM, REMOTE_PROTOCOL_VERSION, remoteEvents, - ARRAY_CARDINALITY(remoteEvents), + G_N_ELEMENTS(remoteEvents), conn))) goto failed; if (!(priv->lxcProgram = virNetClientProgramNew(LXC_PROGRAM, @@ -1325,7 +1325,7 @@ doRemoteOpen(virConnectPtr conn, if (!(priv->qemuProgram = virNetClientProgramNew(QEMU_PROGRAM, QEMU_PROTOCOL_VERSION, qemuEvents, - ARRAY_CARDINALITY(qemuEvents), + G_N_ELEMENTS(qemuEvents), conn))) goto failed; @@ -6596,7 +6596,7 @@ remoteDomainOpenGraphics(virDomainPtr dom, remote_domain_open_graphics_args args; struct private_data *priv = dom->conn->privateData; int fdin[] = { fd }; - size_t fdinlen = ARRAY_CARDINALITY(fdin); + size_t fdinlen = G_N_ELEMENTS(fdin); remoteDriverLock(priv); diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 5d1583980e..6d9838c398 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1292,7 +1292,7 @@ elsif ($mode eq "server") { print "{ $comment\n ${name},\n $arglen,\n (xdrproc_t)$argfilter,\n $retlen,\n (xdrproc_t)$retfilter,\n true,\n $priority\n},\n"; } print "};\n"; - print "size_t ${structprefix}NProcs = ARRAY_CARDINALITY(${structprefix}Procs);\n"; + print "size_t ${structprefix}NProcs = G_N_ELEMENTS(${structprefix}Procs);\n"; } # Bodies for client functions ("remote_client_bodies.h"). diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 53d8b219ea..1d846cd131 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -368,7 +368,7 @@ virNetClientFindDefaultSshKey(const char *homedir, char **retPath) const char *keys[] = { "identity", "id_dsa", "id_ecdsa", "id_ed25519", "id_rsa" }; - for (i = 0; i < ARRAY_CARDINALITY(keys); ++i) { + for (i = 0; i < G_N_ELEMENTS(keys); ++i) { int ret = virNetClientCheckKeyExists(homedir, keys[i], retPath); if (ret != 0) return ret; @@ -939,7 +939,7 @@ int virNetClientSetTLSSession(virNetClientPtr client, ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); repoll: - ret = poll(fds, ARRAY_CARDINALITY(fds), -1); + ret = poll(fds, G_N_ELEMENTS(fds), -1); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll; @@ -963,7 +963,7 @@ int virNetClientSetTLSSession(virNetClientPtr client, ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); repoll2: - ret = poll(fds, ARRAY_CARDINALITY(fds), -1); + ret = poll(fds, G_N_ELEMENTS(fds), -1); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll2; @@ -1682,7 +1682,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client, ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); repoll: - ret = poll(fds, ARRAY_CARDINALITY(fds), timeout); + ret = poll(fds, G_N_ELEMENTS(fds), timeout); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0f7046ab1c..5d975f5903 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1073,7 +1073,7 @@ virSecurityDACMoveImageMetadataHelper(pid_t pid G_GNUC_UNUSED, virSecurityManagerMetadataLockStatePtr state; int ret; - if (!(state = virSecurityManagerMetadataLock(data->mgr, paths, ARRAY_CARDINALITY(paths)))) + if (!(state = virSecurityManagerMetadataLock(data->mgr, paths, G_N_ELEMENTS(paths)))) return -1; ret = virSecurityMoveRememberedLabel(SECURITY_DAC_NAME, data->src, data->dst); diff --git a/src/security/security_driver.c b/src/security/security_driver.c index bd32a9c207..da3b8c1491 100644 --- a/src/security/security_driver.c +++ b/src/security/security_driver.c @@ -53,7 +53,7 @@ virSecurityDriverPtr virSecurityDriverLookup(const char *name, VIR_DEBUG("name=%s", NULLSTR(name)); - for (i = 0; i < ARRAY_CARDINALITY(security_drivers) && !drv; i++) { + for (i = 0; i < G_N_ELEMENTS(security_drivers) && !drv; i++) { virSecurityDriverPtr tmp = security_drivers[i]; if (name && diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index d59888b228..17d39125bb 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1974,7 +1974,7 @@ virSecuritySELinuxMoveImageMetadataHelper(pid_t pid G_GNUC_UNUSED, virSecurityManagerMetadataLockStatePtr state; int ret; - if (!(state = virSecurityManagerMetadataLock(data->mgr, paths, ARRAY_CARDINALITY(paths)))) + if (!(state = virSecurityManagerMetadataLock(data->mgr, paths, G_N_ELEMENTS(paths)))) return -1; ret = virSecurityMoveRememberedLabel(SECURITY_SELINUX_NAME, data->src, data->dst); diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 6a1aa96078..2ff34dacbd 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -519,9 +519,9 @@ valid_path(const char *path, const bool readonly) "/etc/libvirt-sandbox/services/" /* for virt-sandbox service config */ }; - const int nropaths = ARRAY_CARDINALITY(restricted); - const int nrwpaths = ARRAY_CARDINALITY(restricted_rw); - const int nopaths = ARRAY_CARDINALITY(override); + const int nropaths = G_N_ELEMENTS(restricted); + const int nrwpaths = G_N_ELEMENTS(restricted_rw); + const int nopaths = G_N_ELEMENTS(override); if (path == NULL) { vah_error(NULL, 0, _("bad pathname")); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d2a4e100bb..338d459e14 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -332,7 +332,7 @@ testBuildCapabilities(virConnectPtr conn) goto error; } - for (i = 0; i < ARRAY_CARDINALITY(guest_types); i++) { + for (i = 0; i < G_N_ELEMENTS(guest_types); i++) { if ((guest = virCapabilitiesAddGuest(caps, guest_types[i], VIR_ARCH_I686, diff --git a/src/util/virarch.c b/src/util/virarch.c index 3f5efde8e2..f41e3e86bb 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -81,7 +81,7 @@ static const struct virArchData { { "xtensaeb", 32, VIR_ARCH_BIG_ENDIAN }, }; -verify(ARRAY_CARDINALITY(virArchData) == VIR_ARCH_LAST); +verify(G_N_ELEMENTS(virArchData) == VIR_ARCH_LAST); /** diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 23bc44734e..b54ae1283e 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -133,7 +133,7 @@ void virAuditSend(virLogSourcePtr source, [VIR_AUDIT_RECORD_RESOURCE] = AUDIT_VIRT_RESOURCE, }; - if (type >= ARRAY_CARDINALITY(record_types) || record_types[type] == 0) + if (type >= G_N_ELEMENTS(record_types) || record_types[type] == 0) VIR_WARN("Unknown audit record type %d", type); else if (audit_log_user_message(auditfd, record_types[type], str, NULL, clientaddr, clienttty, success) < 0) { diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 23908d769d..dcf8e3383b 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -555,7 +555,7 @@ virCgroupV1CpuSetInherit(virCgroupPtr parent, }; VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path); - for (i = 0; i < ARRAY_CARDINALITY(inherit_values); i++) { + for (i = 0; i < G_N_ELEMENTS(inherit_values); i++) { VIR_AUTOFREE(char *) value = NULL; if (virCgroupGetValueStr(parent, @@ -1065,7 +1065,7 @@ virCgroupV1GetBlkioIoServiced(virCgroupPtr group, return -1; /* sum up all entries of the same kind, from all devices */ - for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { + for (i = 0; i < G_N_ELEMENTS(value_names); i++) { p1 = str1; p2 = str2; @@ -1171,7 +1171,7 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group, return -1; } - for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { + for (i = 0; i < G_N_ELEMENTS(value_names); i++) { if (!(p1 = strstr(p1, value_names[i]))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte %sstats for block device '%s'"), diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index ce8851f800..5d940b0209 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -730,7 +730,7 @@ virCgroupV2GetBlkioIoServiced(virCgroupPtr group, } /* sum up all entries of the same kind, from all devices */ - for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { + for (i = 0; i < G_N_ELEMENTS(value_names); i++) { p1 = str1; while ((p1 = strstr(p1, value_names[i]))) { @@ -799,7 +799,7 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr group, return -1; } - for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { + for (i = 0; i < G_N_ELEMENTS(value_names); i++) { if (!(p1 = strstr(p1, value_names[i]))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte '%s' stats for block device '%s'"), diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 3a3ea227a5..87fabfbba1 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -47,7 +47,7 @@ struct virHashInfo { }; -verify(ARRAY_CARDINALITY(hashinfo) == VIR_CRYPTO_HASH_LAST); +verify(G_N_ELEMENTS(hashinfo) == VIR_CRYPTO_HASH_LAST); ssize_t virCryptoHashBuf(virCryptoHash hash, diff --git a/src/util/virdbus.c b/src/util/virdbus.c index 1e59294fc3..f423305e11 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -305,7 +305,7 @@ static const char virDBusBasicTypes[] = { static bool virDBusIsBasicType(char c) { - return !!memchr(virDBusBasicTypes, c, ARRAY_CARDINALITY(virDBusBasicTypes)); + return !!memchr(virDBusBasicTypes, c, G_N_ELEMENTS(virDBusBasicTypes)); } /* diff --git a/src/util/virenum.h b/src/util/virenum.h index ab443aa528..d68421b203 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -34,15 +34,15 @@ virEnumToString(const char * const *types, static const char *const name ## TypeList[] = { __VA_ARGS__ }; \ const char *name ## TypeToString(int type) { \ return virEnumToString(name ## TypeList, \ - ARRAY_CARDINALITY(name ## TypeList), \ + G_N_ELEMENTS(name ## TypeList), \ type); \ } \ int name ## TypeFromString(const char *type) { \ return virEnumFromString(name ## TypeList, \ - ARRAY_CARDINALITY(name ## TypeList), \ + G_N_ELEMENTS(name ## TypeList), \ type); \ } \ - verify(ARRAY_CARDINALITY(name ## TypeList) == lastVal) + verify(G_N_ELEMENTS(name ## TypeList) == lastVal) #define VIR_ENUM_DECL(name) \ const char *name ## TypeToString(int type); \ diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index f6344b631c..0d4bfae8f8 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -178,7 +178,7 @@ virFirewallValidateBackend(virFirewallBackend backend) }; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(commands); i++) { + for (i = 0; i < G_N_ELEMENTS(commands); i++) { if (!virFileIsExecutable(commands[i])) { virReportSystemError(errno, _("direct firewall backend requested, but %s is not available"), diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 952766dc3a..d544d36c61 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -168,7 +168,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum, } param->value = 0; - for (j = 0; j < ARRAY_CARDINALITY(cpu_map[i].idx); j++) + for (j = 0; j < G_N_ELEMENTS(cpu_map[i].idx); j++) param->value += cpu_times[offset + cpu_map[i].idx[j]] * TICK_TO_NSEC; } diff --git a/src/util/viriptables.c b/src/util/viriptables.c index 0e3c0ad73a..e1b876d36c 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -144,11 +144,11 @@ iptablesSetupPrivateChains(virFirewallLayer layer) bool changed = false; iptablesGlobalChainData data[] = { { layer, "filter", - filter_chains, ARRAY_CARDINALITY(filter_chains), &changed }, + filter_chains, G_N_ELEMENTS(filter_chains), &changed }, { layer, "nat", - natmangle_chains, ARRAY_CARDINALITY(natmangle_chains), &changed }, + natmangle_chains, G_N_ELEMENTS(natmangle_chains), &changed }, { layer, "mangle", - natmangle_chains, ARRAY_CARDINALITY(natmangle_chains), &changed }, + natmangle_chains, G_N_ELEMENTS(natmangle_chains), &changed }, }; size_t i; @@ -156,7 +156,7 @@ iptablesSetupPrivateChains(virFirewallLayer layer) virFirewallStartTransaction(fw, 0); - for (i = 0; i < ARRAY_CARDINALITY(data); i++) + for (i = 0; i < G_N_ELEMENTS(data); i++) virFirewallAddRuleFull(fw, data[i].layer, false, iptablesPrivateChainCreate, &(data[i]), "--table", data[i].table, diff --git a/src/util/virkeycode.c b/src/util/virkeycode.c index 336443e01d..1a0a94e3ab 100644 --- a/src/util/virkeycode.c +++ b/src/util/virkeycode.c @@ -54,19 +54,19 @@ static const unsigned short *virKeymapValues[VIR_KEYCODE_SET_LAST] = { [VIR_KEYCODE_SET_QNUM] = virKeyCodeTable_qnum, }; -#define VIR_KEYMAP_ENTRY_MAX ARRAY_CARDINALITY(virKeyCodeTable_linux) +#define VIR_KEYMAP_ENTRY_MAX G_N_ELEMENTS(virKeyCodeTable_linux) -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset1)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset2)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset3)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_osx)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_xtkbd)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_usb)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_win32)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_qnum)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_linux)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_osx)); -verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_win32)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_atset1)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_atset2)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_atset3)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_osx)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_xtkbd)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_usb)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_win32)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyCodeTable_qnum)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyNameTable_linux)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyNameTable_osx)); +verify(VIR_KEYMAP_ENTRY_MAX == G_N_ELEMENTS(virKeyNameTable_win32)); VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST, diff --git a/src/util/virlog.c b/src/util/virlog.c index 4414a8fa63..5881a59cc5 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -702,7 +702,7 @@ virLogStackTraceToFd(int fd) const char *msg = "Stack trace not available on this platform\n"; #define STRIP_DEPTH 3 - size = backtrace(array, ARRAY_CARDINALITY(array)); + size = backtrace(array, G_N_ELEMENTS(array)); if (size) { backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH, fd); ignore_value(safewrite(fd, "\n", 1)); @@ -1004,9 +1004,9 @@ virLogOutputToJournald(virLogSourcePtr source, struct journalState state; state.iov = iov; - state.iov_end = iov + ARRAY_CARDINALITY(iov); + state.iov_end = iov + G_N_ELEMENTS(iov); state.bufs = iov_bufs; - state.bufs_end = iov_bufs + ARRAY_CARDINALITY(iov_bufs); + state.bufs_end = iov_bufs + G_N_ELEMENTS(iov_bufs); journalAddString(&state, "MESSAGE", rawstr); journalAddInt(&state, "PRIORITY", diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index d3f1595ae4..894ae86a16 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3050,7 +3050,7 @@ virNetDevGetEthtoolFeatures(virBitmapPtr bitmap, }; # endif - for (i = 0; i < ARRAY_CARDINALITY(ethtool_cmds); i++) { + for (i = 0; i < G_N_ELEMENTS(ethtool_cmds); i++) { cmd.cmd = ethtool_cmds[i].cmd; if (virNetDevFeatureAvailable(fd, ifr, &cmd)) ignore_value(virBitmapSetBit(bitmap, ethtool_cmds[i].feat)); @@ -3059,7 +3059,7 @@ virNetDevGetEthtoolFeatures(virBitmapPtr bitmap, # if HAVE_DECL_ETHTOOL_GFLAGS cmd.cmd = ETHTOOL_GFLAGS; if (virNetDevFeatureAvailable(fd, ifr, &cmd)) { - for (i = 0; i < ARRAY_CARDINALITY(flags); i++) { + for (i = 0; i < G_N_ELEMENTS(flags); i++) { if (cmd.data & flags[i].cmd) ignore_value(virBitmapSetBit(bitmap, flags[i].feat)); } diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 0b1f3262f4..f07eb2f2e2 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -253,7 +253,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid, fds[0].fd = fd; fds[0].events = POLLIN; - n = poll(fds, ARRAY_CARDINALITY(fds), NETLINK_ACK_TIMEOUT_S); + n = poll(fds, G_N_ELEMENTS(fds), NETLINK_ACK_TIMEOUT_S); if (n <= 0) { if (n < 0) virReportSystemError(errno, "%s", diff --git a/src/util/virperf.c b/src/util/virperf.c index 7714d57f6b..e334d415e4 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -168,7 +168,7 @@ static struct virPerfEventAttr attrs[] = { .attrConfig = PERF_COUNT_SW_EMULATION_FAULTS }, }; -verify(ARRAY_CARDINALITY(attrs) == VIR_PERF_EVENT_LAST); +verify(G_N_ELEMENTS(attrs) == VIR_PERF_EVENT_LAST); typedef struct virPerfEventAttr *virPerfEventAttrPtr; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index c91301e525..e8d4ba08b4 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -628,7 +628,7 @@ int virProcessGetNamespaces(pid_t pid, *nfdlist = 0; *fdlist = NULL; - for (i = 0; i < ARRAY_CARDINALITY(ns); i++) { + for (i = 0; i < G_N_ELEMENTS(ns); i++) { int fd; VIR_AUTOFREE(char *) nsfile = NULL; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index ef6d7f3ba5..6c2693fec9 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -387,7 +387,7 @@ static struct FileTypeInfo const fileTypeInfo[] = { 4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL }, }; -verify(ARRAY_CARDINALITY(fileTypeInfo) == VIR_STORAGE_FILE_LAST); +verify(G_N_ELEMENTS(fileTypeInfo) == VIR_STORAGE_FILE_LAST); /* qcow2 compatible features in the order they appear on-disk */ @@ -401,7 +401,7 @@ enum qcow2CompatibleFeature { static const int qcow2CompatibleFeatureArray[] = { VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS, }; -verify(ARRAY_CARDINALITY(qcow2CompatibleFeatureArray) == +verify(G_N_ELEMENTS(qcow2CompatibleFeatureArray) == QCOW2_COMPATIBLE_FEATURE_LAST); static int @@ -3640,7 +3640,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, return -1; } - for (i = 0; i < ARRAY_CARDINALITY(jsonParsers); i++) { + for (i = 0; i < G_N_ELEMENTS(jsonParsers); i++) { if (STREQ(drvname, jsonParsers[i].drvname)) return jsonParsers[i].func(src, file, jsonParsers[i].opaque); } diff --git a/src/util/virtpm.c b/src/util/virtpm.c index b5d5cb7236..26056bf503 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -64,7 +64,7 @@ virTPMCreateCancelPath(const char *devpath) dev = strrchr(devpath, '/'); if (dev) { dev++; - for (i = 0; i < ARRAY_CARDINALITY(prefix); i++) { + for (i = 0; i < G_N_ELEMENTS(prefix); i++) { if (virAsprintf(&path, "/sys/class/%s%s/device/cancel", prefix[i], dev) < 0) goto cleanup; @@ -290,7 +290,7 @@ virTPMEmulatorInit(void) virMutexLock(&swtpm_tools_lock); - for (i = 0; i < ARRAY_CARDINALITY(prgs); i++) { + for (i = 0; i < G_N_ELEMENTS(prgs); i++) { VIR_AUTOFREE(char *) path = NULL; bool findit = *prgs[i].path == NULL; struct stat statbuf; diff --git a/src/util/virutil.c b/src/util/virutil.c index aae07d48e6..940c6d70e1 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -386,7 +386,7 @@ int virDiskNameParse(const char *name, int *disk, int *partition) static char const* const drive_prefix[] = {"fd", "hd", "vd", "sd", "xvd", "ubd"}; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(drive_prefix); i++) { + for (i = 0; i < G_N_ELEMENTS(drive_prefix); i++) { if (STRPREFIX(name, drive_prefix[i])) { ptr = name + strlen(drive_prefix[i]); break; @@ -1108,7 +1108,7 @@ virGetWin32DirectoryRoot(char **path) *path = NULL; - if (GetWindowsDirectory(windowsdir, ARRAY_CARDINALITY(windowsdir))) { + if (GetWindowsDirectory(windowsdir, G_N_ELEMENTS(windowsdir))) { const char *tmp; /* Usually X:\Windows, but in terminal server environments * might be an UNC path, AFAIK. diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index 72ae49b6b2..9310cace3e 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -205,7 +205,7 @@ VBoxCGlueInit(unsigned int *version) } /* Try the known locations. */ - for (i = 0; i < ARRAY_CARDINALITY(knownDirs); ++i) { + for (i = 0; i < G_N_ELEMENTS(knownDirs); ++i) { if (tryLoadOne(knownDirs[i], true, true, version) >= 0) return 0; } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 08fc84e002..7243453307 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -182,7 +182,7 @@ vmwareConnectOpen(virConnectPtr conn, * the VMware hypervisor. We look this up first since we use it * for auto detection of the backend */ - for (i = 0; i < ARRAY_CARDINALITY(vmrun_candidates); i++) { + for (i = 0; i < G_N_ELEMENTS(vmrun_candidates); i++) { vmrun = virFindFileInPath(vmrun_candidates[i]); if (vmrun == NULL) continue; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index c5fe59376e..917acdae57 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -122,11 +122,11 @@ vzBuildCapabilities(void) if (virCapabilitiesInitCaches(caps) < 0) goto error; - verify(ARRAY_CARDINALITY(archs) == ARRAY_CARDINALITY(emulators)); + verify(G_N_ELEMENTS(archs) == G_N_ELEMENTS(emulators)); - for (i = 0; i < ARRAY_CARDINALITY(ostypes); i++) - for (j = 0; j < ARRAY_CARDINALITY(archs); j++) - for (k = 0; k < ARRAY_CARDINALITY(emulators); k++) + for (i = 0; i < G_N_ELEMENTS(ostypes); i++) + for (j = 0; j < G_N_ELEMENTS(archs); j++) + for (k = 0; k < G_N_ELEMENTS(emulators); k++) if (vzCapsAddGuestDomain(caps, ostypes[i], archs[j], emulators[k], virt_types[k]) < 0) goto error; diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 872564b144..77cbcd4680 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -219,7 +219,7 @@ int main(int argc, char **argv) { ret = EXIT_SUCCESS; cleanup: - for (i = 0; i < ARRAY_CARDINALITY(buffers); i++) + for (i = 0; i < G_N_ELEMENTS(buffers); i++) free(buffers[i]); fclose(log); free(newenv); diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index 49a159a2be..2e2020006e 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -41,7 +41,7 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED) char *directoryName = NULL; char *directoryAndFileName = NULL; - for (i = 0; i < ARRAY_CARDINALITY(paths); ++i) { + for (i = 0; i < G_N_ELEMENTS(paths); ++i) { VIR_FREE(datastoreName); VIR_FREE(directoryName); VIR_FREE(directoryAndFileName); @@ -127,7 +127,7 @@ testConvertDateTimeToCalendarTime(const void *data G_GNUC_UNUSED) esxVI_DateTime dateTime; long long calendarTime; - for (i = 0; i < ARRAY_CARDINALITY(times); ++i) { + for (i = 0; i < G_N_ELEMENTS(times); ++i) { dateTime.value = (char *)times[i].dateTime; if (esxVI_DateTime_ConvertToCalendarTime(&dateTime, @@ -177,7 +177,7 @@ testEscapeDatastoreItem(const void *data G_GNUC_UNUSED) size_t i; char *escaped = NULL; - for (i = 0; i < ARRAY_CARDINALITY(datastoreItems); ++i) { + for (i = 0; i < G_N_ELEMENTS(datastoreItems); ++i) { VIR_FREE(escaped); escaped = esxUtil_EscapeDatastoreItem(datastoreItems[i].string); @@ -217,7 +217,7 @@ testConvertWindows1252ToUTF8(const void *data G_GNUC_UNUSED) size_t i; char *utf8 = NULL; - for (i = 0; i < ARRAY_CARDINALITY(windows1252ToUTF8); ++i) { + for (i = 0; i < G_N_ELEMENTS(windows1252ToUTF8); ++i) { VIR_FREE(utf8); utf8 = virVMXConvertToUTF8("Windows-1252", diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index bea267f0fc..bef3790da2 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -313,7 +313,7 @@ static void testRemoveCommonRules(char *rules) size_t i; char *offset = rules; - for (i = 0; i < ARRAY_CARDINALITY(commonRules); i++) { + for (i = 0; i < G_N_ELEMENTS(commonRules); i++) { char *tmp = strstr(offset, commonRules[i]); size_t len = strlen(commonRules[i]); if (tmp) { diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index b5e23d4d8d..1fcd4d2caa 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -43,7 +43,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) return -1; - for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) { + for (i = 0; i < G_N_ELEMENTS(configParams); ++i) { if (openvzReadConfigParam(conf, configParams[i].param, &value) != configParams[i].ret) { goto cleanup; diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index 14710b11f3..e4d867c1b2 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -68,7 +68,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED) PREFIX "/share/qemu/firmware/61-ovmf.json", PREFIX "/share/qemu/firmware/70-aavmf.json", }; - const size_t nexpected = ARRAY_CARDINALITY(expected); + const size_t nexpected = G_N_ELEMENTS(expected); if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0) return -1; @@ -236,7 +236,7 @@ mymain(void) do { \ unsigned int interfaces[] = {__VA_ARGS__}; \ struct supportedData data = {machine, arch, secure, fwlist, \ - interfaces, ARRAY_CARDINALITY(interfaces)}; \ + interfaces, G_N_ELEMENTS(interfaces)}; \ if (virTestRun("QEMU FW SUPPORTED " machine " " #arch, \ testSupportedFW, &data) < 0) \ ret = -1; \ diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 8179e802c1..1248db59f2 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2320,7 +2320,7 @@ testQemuMonitorJSONqemuMonitorJSONSendKey(const void *opaque) return -1; if (qemuMonitorJSONSendKey(qemuMonitorTestGetMonitor(test), - 0, keycodes, ARRAY_CARDINALITY(keycodes)) < 0) + 0, keycodes, G_N_ELEMENTS(keycodes)) < 0) return -1; return 0; @@ -2349,7 +2349,7 @@ testQemuMonitorJSONqemuMonitorJSONSendKeyHoldtime(const void *opaque) if (qemuMonitorJSONSendKey(qemuMonitorTestGetMonitor(test), 31337, keycodes, - ARRAY_CARDINALITY(keycodes)) < 0) + G_N_ELEMENTS(keycodes)) < 0) return -1; return 0; diff --git a/tests/qemuvhostusertest.c b/tests/qemuvhostusertest.c index 691c94b8fa..b5a7d9bbd2 100644 --- a/tests/qemuvhostusertest.c +++ b/tests/qemuvhostusertest.c @@ -66,7 +66,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED) SYSCONFDIR "/qemu/vhost-user/40-gpu.json", PREFIX "/share/qemu/vhost-user/60-gpu.json", }; - const size_t nexpected = ARRAY_CARDINALITY(expected); + const size_t nexpected = G_N_ELEMENTS(expected); if (VIR_STRDUP(fakehome, abs_srcdir "/qemuvhostuserdata/home/user/.config") < 0) return -1; diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 4c114212e9..cc9a3ccbff 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -214,7 +214,7 @@ virCommandPassFD(virCommandPtr cmd, { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(testCommandPassSafeFDs); i++) { + for (i = 0; i < G_N_ELEMENTS(testCommandPassSafeFDs); i++) { if (testCommandPassSafeFDs[i] == fd) { if (!real_virCommandPassFD) VIR_MOCK_REAL_INIT(virCommandPassFD); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a84ea0954d..5212ce50bd 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -316,43 +316,43 @@ testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy) if (ARCH_IS_X86(arch)) { if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, x86Models, - ARRAY_CARDINALITY(x86Models), + G_N_ELEMENTS(x86Models), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 || virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, x86Models, - ARRAY_CARDINALITY(x86Models), + G_N_ELEMENTS(x86Models), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0) return -1; if (!skipLegacy) { if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, x86LegacyModels, - ARRAY_CARDINALITY(x86LegacyModels), + G_N_ELEMENTS(x86LegacyModels), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 || virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, x86LegacyModels, - ARRAY_CARDINALITY(x86LegacyModels), + G_N_ELEMENTS(x86LegacyModels), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0) return -1; } } else if (ARCH_IS_ARM(arch)) { if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, armModels, - ARRAY_CARDINALITY(armModels), + G_N_ELEMENTS(armModels), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 || virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, armModels, - ARRAY_CARDINALITY(armModels), + G_N_ELEMENTS(armModels), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0) return -1; } else if (ARCH_IS_PPC64(arch)) { if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, ppc64Models, - ARRAY_CARDINALITY(ppc64Models), + G_N_ELEMENTS(ppc64Models), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 || virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, ppc64Models, - ARRAY_CARDINALITY(ppc64Models), + G_N_ELEMENTS(ppc64Models), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0) return -1; } else if (ARCH_IS_S390(arch)) { if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, s390xModels, - ARRAY_CARDINALITY(s390xModels), + G_N_ELEMENTS(s390xModels), VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0) return -1; } diff --git a/tests/testutils.c b/tests/testutils.c index 80b7b083ff..8997274621 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1193,7 +1193,7 @@ virTestCounterReset(const char *prefix) const char *virTestCounterNext(void) { - size_t len = ARRAY_CARDINALITY(virtTestCounterStr); + size_t len = G_N_ELEMENTS(virtTestCounterStr); /* calculate length of the rest of the string */ len -= (virtTestCounterPrefixEndOffset - virtTestCounterStr); diff --git a/tests/testutilshostcpus.h b/tests/testutilshostcpus.h index a8c34cfc4a..a54b181c09 100644 --- a/tests/testutilshostcpus.h +++ b/tests/testutilshostcpus.h @@ -43,8 +43,8 @@ static virCPUDef cpuDefaultData = { .sockets = 1, .cores = 2, .threads = 1, - .nfeatures = ARRAY_CARDINALITY(cpuDefaultFeatures), - .nfeatures_max = ARRAY_CARDINALITY(cpuDefaultFeatures), + .nfeatures = G_N_ELEMENTS(cpuDefaultFeatures), + .nfeatures_max = G_N_ELEMENTS(cpuDefaultFeatures), .features = cpuDefaultFeatures, }; @@ -82,8 +82,8 @@ static virCPUDef cpuHaswellData = { .sockets = 1, .cores = 2, .threads = 2, - .nfeatures = ARRAY_CARDINALITY(cpuHaswellFeatures), - .nfeatures_max = ARRAY_CARDINALITY(cpuHaswellFeatures), + .nfeatures = G_N_ELEMENTS(cpuHaswellFeatures), + .nfeatures_max = G_N_ELEMENTS(cpuHaswellFeatures), .features = cpuHaswellFeatures, }; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 265107fb5e..68a0b15cd0 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -53,11 +53,11 @@ static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines) }; machines = virCapabilitiesAllocMachines(x86_machines, - ARRAY_CARDINALITY(x86_machines)); + G_N_ELEMENTS(x86_machines)); if (machines == NULL) return NULL; - *nmachines = ARRAY_CARDINALITY(x86_machines); + *nmachines = G_N_ELEMENTS(x86_machines); return machines; } @@ -78,7 +78,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines) return NULL; machines = virCapabilitiesAllocMachines(x86_machines, - ARRAY_CARDINALITY(x86_machines)); + G_N_ELEMENTS(x86_machines)); if (machines == NULL) { VIR_FREE(canonical); return NULL; @@ -86,7 +86,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines) machines[1]->canonical = canonical; - *nmachines = ARRAY_CARDINALITY(x86_machines); + *nmachines = G_N_ELEMENTS(x86_machines); return machines; } @@ -304,7 +304,7 @@ static int testQemuAddRISCV32Guest(virCapsPtr caps) "sifive_e", "virt", "sifive_u" }; - static const int nmachines = ARRAY_CARDINALITY(names); + static const int nmachines = G_N_ELEMENTS(names); virCapsGuestMachinePtr *machines = NULL; virCapsGuestPtr guest; @@ -335,7 +335,7 @@ static int testQemuAddRISCV64Guest(virCapsPtr caps) "sifive_e", "virt", "sifive_u" }; - static const int nmachines = ARRAY_CARDINALITY(names); + static const int nmachines = G_N_ELEMENTS(names); virCapsGuestMachinePtr *machines = NULL; virCapsGuestPtr guest; @@ -367,14 +367,14 @@ static int testQemuAddS390Guest(virCapsPtr caps) virCapsGuestPtr guest; machines = virCapabilitiesAllocMachines(s390_machines, - ARRAY_CARDINALITY(s390_machines)); + G_N_ELEMENTS(s390_machines)); if (!machines) goto error; guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X, QEMUBinList[TEST_UTILS_QEMU_BIN_S390X], NULL, - ARRAY_CARDINALITY(s390_machines), + G_N_ELEMENTS(s390_machines), machines); if (!guest) goto error; @@ -388,7 +388,7 @@ static int testQemuAddS390Guest(virCapsPtr caps) return 0; error: - virCapabilitiesFreeMachines(machines, ARRAY_CARDINALITY(s390_machines)); + virCapabilitiesFreeMachines(machines, G_N_ELEMENTS(s390_machines)); return -1; } @@ -399,14 +399,14 @@ static int testQemuAddArm6Guest(virCapsPtr caps) virCapsGuestPtr guest; capsmachines = virCapabilitiesAllocMachines(machines, - ARRAY_CARDINALITY(machines)); + G_N_ELEMENTS(machines)); if (!capsmachines) goto error; guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV6L, QEMUBinList[TEST_UTILS_QEMU_BIN_ARM], NULL, - ARRAY_CARDINALITY(machines), + G_N_ELEMENTS(machines), capsmachines); if (!guest) goto error; @@ -420,7 +420,7 @@ static int testQemuAddArm6Guest(virCapsPtr caps) return 0; error: - virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines)); + virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); return -1; } @@ -433,14 +433,14 @@ static int testQemuAddArm7Guest(virCapsPtr caps) virCapsGuestPtr guest; capsmachines = virCapabilitiesAllocMachines(machines, - ARRAY_CARDINALITY(machines)); + G_N_ELEMENTS(machines)); if (!capsmachines) goto error; guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_ARMV7L, QEMUBinList[TEST_UTILS_QEMU_BIN_ARM], NULL, - ARRAY_CARDINALITY(machines), + G_N_ELEMENTS(machines), capsmachines); if (!guest) goto error; @@ -454,7 +454,7 @@ static int testQemuAddArm7Guest(virCapsPtr caps) return 0; error: - virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines)); + virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); return -1; } @@ -465,14 +465,14 @@ static int testQemuAddAARCH64Guest(virCapsPtr caps) virCapsGuestPtr guest; capsmachines = virCapabilitiesAllocMachines(machines, - ARRAY_CARDINALITY(machines)); + G_N_ELEMENTS(machines)); if (!capsmachines) goto error; guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64, QEMUBinList[TEST_UTILS_QEMU_BIN_AARCH64], NULL, - ARRAY_CARDINALITY(machines), + G_N_ELEMENTS(machines), capsmachines); if (!guest) goto error; @@ -486,7 +486,7 @@ static int testQemuAddAARCH64Guest(virCapsPtr caps) return 0; error: - virCapabilitiesFreeMachines(capsmachines, ARRAY_CARDINALITY(machines)); + virCapabilitiesFreeMachines(capsmachines, G_N_ELEMENTS(machines)); return -1; } @@ -669,7 +669,7 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache, return -ENOMEM; } - for (i = 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) { + for (i = 0; i < G_N_ELEMENTS(QEMUBinList); i++) { virObjectRef(tmpCaps); if (virFileCacheInsertData(cache, QEMUBinList[i], tmpCaps) < 0) { virObjectUnref(tmpCaps); @@ -884,7 +884,7 @@ testQemuGetLatestCaps(void) VIR_TEST_VERBOSE(""); - for (i = 0; i < ARRAY_CARDINALITY(archs); ++i) { + for (i = 0; i < G_N_ELEMENTS(archs); ++i) { char *cap = testQemuGetLatestCapsForArch(archs[i], "xml"); if (!cap || virHashAddEntry(capslatest, archs[i], cap) < 0) diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 2c347a7f3f..314d96abe8 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -29,7 +29,7 @@ testXLInitCaps(void) caps->host.cpu = virCPUDefCopy(&cpuDefaultData); - nmachines = ARRAY_CARDINALITY(x86_machines); + nmachines = G_N_ELEMENTS(x86_machines); if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, @@ -42,7 +42,7 @@ testXLInitCaps(void) if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL, NULL, 0, NULL) == NULL) goto cleanup; - nmachines = ARRAY_CARDINALITY(xen_machines); + nmachines = G_N_ELEMENTS(xen_machines); if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL) goto cleanup; @@ -57,7 +57,7 @@ testXLInitCaps(void) if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL, NULL, 0, NULL) == NULL) goto cleanup; - nmachines = ARRAY_CARDINALITY(pvh_machines); + nmachines = G_N_ELEMENTS(pvh_machines); if ((machines = virCapabilitiesAllocMachines(pvh_machines, nmachines)) == NULL) goto cleanup; diff --git a/tests/utiltest.c b/tests/utiltest.c index 176e6ca20a..5ae04585cb 100644 --- a/tests/utiltest.c +++ b/tests/utiltest.c @@ -44,7 +44,7 @@ testIndexToDiskName(const void *data G_GNUC_UNUSED) size_t i; char *diskName = NULL; - for (i = 0; i < ARRAY_CARDINALITY(diskNames); ++i) { + for (i = 0; i < G_N_ELEMENTS(diskNames); ++i) { VIR_FREE(diskName); diskName = virIndexToDiskName(i, "sd"); @@ -102,7 +102,7 @@ testDiskNameParse(const void *data G_GNUC_UNUSED) int partition; struct testDiskName *disk = NULL; - for (i = 0; i < ARRAY_CARDINALITY(diskNamesPart); ++i) { + for (i = 0; i < G_N_ELEMENTS(diskNamesPart); ++i) { disk = &diskNamesPart[i]; if (virDiskNameParse(disk->name, &idx, &partition)) return -1; @@ -120,7 +120,7 @@ testDiskNameParse(const void *data G_GNUC_UNUSED) } } - for (i = 0; i < ARRAY_CARDINALITY(diskNamesInvalid); ++i) { + for (i = 0; i < G_N_ELEMENTS(diskNamesInvalid); ++i) { if (!virDiskNameParse(diskNamesInvalid[i], &idx, &partition)) { VIR_TEST_DEBUG("Should Fail [%s]", diskNamesInvalid[i]); return -1; @@ -161,7 +161,7 @@ testParseVersionString(const void *data G_GNUC_UNUSED) size_t i; unsigned long version; - for (i = 0; i < ARRAY_CARDINALITY(versions); ++i) { + for (i = 0; i < G_N_ELEMENTS(versions); ++i) { result = virParseVersionString(versions[i].string, &version, versions[i].allowMissing); @@ -210,7 +210,7 @@ testRoundValueToPowerOfTwo(const void *data G_GNUC_UNUSED) unsigned int result; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(roundData); i++) { + for (i = 0; i < G_N_ELEMENTS(roundData); i++) { result = VIR_ROUND_UP_POWER_OF_TWO(roundData[i].input); if (roundData[i].output != result) { VIR_TEST_DEBUG("\nInput number [%u]", roundData[i].input); diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 9fec1fcc6e..ff6b506b7d 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -188,7 +188,7 @@ test4(const void *data G_GNUC_UNUSED) virBitmapPtr bitmap = NULL; ssize_t i, j; - if (ARRAY_CARDINALITY(bitsPos) + ARRAY_CARDINALITY(bitsPosInv) != size) + if (G_N_ELEMENTS(bitsPos) + G_N_ELEMENTS(bitsPosInv) != size) goto error; /* 0. empty set */ @@ -243,7 +243,7 @@ test4(const void *data G_GNUC_UNUSED) j = 0; i = -1; - while (j < ARRAY_CARDINALITY(bitsPos)) { + while (j < G_N_ELEMENTS(bitsPos)) { i = virBitmapNextSetBit(bitmap, i); if (i != bitsPos[j++]) goto error; @@ -260,7 +260,7 @@ test4(const void *data G_GNUC_UNUSED) j = 0; i = -1; - while (j < ARRAY_CARDINALITY(bitsPosInv)) { + while (j < G_N_ELEMENTS(bitsPosInv)) { i = virBitmapNextClearBit(bitmap, i); if (i != bitsPosInv[j++]) goto error; @@ -680,7 +680,7 @@ test13(const void *opaque G_GNUC_UNUSED) size_t i = 0; int ret = -1; - for (i = 0; i < ARRAY_CARDINALITY(strings); i++) { + for (i = 0; i < G_N_ELEMENTS(strings); i++) { map = virBitmapNewString(strings[i]); str = virBitmapToString(map, false, true); diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index ec58d71a63..cecb15ae5b 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -825,7 +825,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) "inactive_file", "unevictable" }; - unsigned long long values[ARRAY_CARDINALITY(expected_values)]; + unsigned long long values[G_N_ELEMENTS(expected_values)]; if ((rv = virCgroupNewPartition("/virtualmachines", true, (1 << VIR_CGROUP_CONTROLLER_MEMORY), @@ -842,7 +842,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED) goto cleanup; } - for (i = 0; i < ARRAY_CARDINALITY(expected_values); i++) { + for (i = 0; i < G_N_ELEMENTS(expected_values); i++) { /* NB: virCgroupGetMemoryStat returns a KiB scaled value */ if ((expected_values[i] >> 10) != values[i]) { fprintf(stderr, @@ -879,7 +879,7 @@ static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED) "requests read", "requests written" }; - long long values[ARRAY_CARDINALITY(expected_values)]; + long long values[G_N_ELEMENTS(expected_values)]; if ((rv = virCgroupNewPartition("/virtualmachines", true, (1 << VIR_CGROUP_CONTROLLER_BLKIO), @@ -895,7 +895,7 @@ static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED) goto cleanup; } - for (i = 0; i < ARRAY_CARDINALITY(expected_values); i++) { + for (i = 0; i < G_N_ELEMENTS(expected_values); i++) { if (expected_values[i] != values[i]) { fprintf(stderr, "Wrong value for %s from virCgroupBlkioIoServiced (expected %lld)\n", @@ -934,7 +934,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED) "requests read", "requests written" }; - long long values[ARRAY_CARDINALITY(expected_values0)]; + long long values[G_N_ELEMENTS(expected_values0)]; if ((rv = virCgroupNewPartition("/virtualmachines", true, (1 << VIR_CGROUP_CONTROLLER_BLKIO), @@ -951,7 +951,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED) goto cleanup; } - for (i = 0; i < ARRAY_CARDINALITY(expected_values0); i++) { + for (i = 0; i < G_N_ELEMENTS(expected_values0); i++) { if (expected_values0[i] != values[i]) { fprintf(stderr, "Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n", @@ -968,7 +968,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED) goto cleanup; } - for (i = 0; i < ARRAY_CARDINALITY(expected_values1); i++) { + for (i = 0; i < G_N_ELEMENTS(expected_values1); i++) { if (expected_values1[i] != values[i]) { fprintf(stderr, "Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n", diff --git a/tests/virfiletest.c b/tests/virfiletest.c index cda29bb735..ed0daf8478 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -376,7 +376,7 @@ mymain(void) # define DO_TEST_MOUNT_SUBTREE(name, path, prefix, mounts, rev) \ do { \ struct testFileGetMountSubtreeData data = { \ - path, prefix, mounts, ARRAY_CARDINALITY(mounts), rev \ + path, prefix, mounts, G_N_ELEMENTS(mounts), rev \ }; \ if (virTestRun(name, testFileGetMountSubtree, &data) < 0) \ ret = -1; \ diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 3325986b2d..824e9f46c2 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -991,7 +991,7 @@ testFirewallQueryCallback(virFirewallPtr fw, "--jump", "REJECT", NULL); for (i = 0; lines[i] != NULL; i++) { - if (expectedLineNum >= ARRAY_CARDINALITY(expectedLines)) { + if (expectedLineNum >= G_N_ELEMENTS(expectedLines)) { expectedLineError = true; break; } diff --git a/tests/virhashtest.c b/tests/virhashtest.c index 1e9098e0e6..3132095463 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -26,7 +26,7 @@ testHashInit(int size) /* entries are added in reverse order so that they will be linked in * collision list in the same order as in the uuids array */ - for (i = ARRAY_CARDINALITY(uuids) - 1; i >= 0; i--) { + for (i = G_N_ELEMENTS(uuids) - 1; i >= 0; i--) { ssize_t oldsize = virHashTableSize(hash); if (virHashAddEntry(hash, uuids[i], (void *) uuids[i]) < 0) { virHashFree(hash); @@ -39,7 +39,7 @@ testHashInit(int size) } } - for (i = 0; i < ARRAY_CARDINALITY(uuids); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids); i++) { if (!virHashLookup(hash, uuids[i])) { VIR_TEST_VERBOSE("\nentry \"%s\" could not be found", uuids[i]); virHashFree(hash); @@ -98,7 +98,7 @@ testHashGrow(const void *data) if (!(hash = testHashInit(info->count))) return -1; - if (testHashCheckCount(hash, ARRAY_CARDINALITY(uuids)) < 0) + if (testHashCheckCount(hash, G_N_ELEMENTS(uuids)) < 0) goto cleanup; ret = 0; @@ -112,7 +112,7 @@ testHashGrow(const void *data) static int testHashUpdate(const void *data G_GNUC_UNUSED) { - int count = ARRAY_CARDINALITY(uuids) + ARRAY_CARDINALITY(uuids_new); + int count = G_N_ELEMENTS(uuids) + G_N_ELEMENTS(uuids_new); virHashTablePtr hash; size_t i; int ret = -1; @@ -120,7 +120,7 @@ testHashUpdate(const void *data G_GNUC_UNUSED) if (!(hash = testHashInit(0))) return -1; - for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_subset); i++) { if (virHashUpdateEntry(hash, uuids_subset[i], (void *) 1) < 0) { VIR_TEST_VERBOSE("\nentry \"%s\" could not be updated", uuids_subset[i]); @@ -128,7 +128,7 @@ testHashUpdate(const void *data G_GNUC_UNUSED) } } - for (i = 0; i < ARRAY_CARDINALITY(uuids_new); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_new); i++) { if (virHashUpdateEntry(hash, uuids_new[i], (void *) 1) < 0) { VIR_TEST_VERBOSE("\nnew entry \"%s\" could not be updated", uuids_new[i]); @@ -150,7 +150,7 @@ testHashUpdate(const void *data G_GNUC_UNUSED) static int testHashRemove(const void *data G_GNUC_UNUSED) { - int count = ARRAY_CARDINALITY(uuids) - ARRAY_CARDINALITY(uuids_subset); + int count = G_N_ELEMENTS(uuids) - G_N_ELEMENTS(uuids_subset); virHashTablePtr hash; size_t i; int ret = -1; @@ -158,7 +158,7 @@ testHashRemove(const void *data G_GNUC_UNUSED) if (!(hash = testHashInit(0))) return -1; - for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_subset); i++) { if (virHashRemoveEntry(hash, uuids_subset[i]) < 0) { VIR_TEST_VERBOSE("\nentry \"%s\" could not be removed", uuids_subset[i]); @@ -178,7 +178,7 @@ testHashRemove(const void *data G_GNUC_UNUSED) const int testHashCountRemoveForEachSome = - ARRAY_CARDINALITY(uuids) - ARRAY_CARDINALITY(uuids_subset); + G_N_ELEMENTS(uuids) - G_N_ELEMENTS(uuids_subset); static int testHashRemoveForEachSome(void *payload G_GNUC_UNUSED, @@ -188,7 +188,7 @@ testHashRemoveForEachSome(void *payload G_GNUC_UNUSED, virHashTablePtr hash = data; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_subset); i++) { if (STREQ(uuids_subset[i], name)) { if (virHashRemoveEntry(hash, name) < 0) { VIR_TEST_VERBOSE("\nentry \"%s\" could not be removed", @@ -244,7 +244,7 @@ testHashRemoveForEach(const void *data) static int testHashSteal(const void *data G_GNUC_UNUSED) { - int count = ARRAY_CARDINALITY(uuids) - ARRAY_CARDINALITY(uuids_subset); + int count = G_N_ELEMENTS(uuids) - G_N_ELEMENTS(uuids_subset); virHashTablePtr hash; size_t i; int ret = -1; @@ -252,7 +252,7 @@ testHashSteal(const void *data G_GNUC_UNUSED) if (!(hash = testHashInit(0))) return -1; - for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_subset); i++) { if (!virHashSteal(hash, uuids_subset[i])) { VIR_TEST_VERBOSE("\nentry \"%s\" could not be stolen", uuids_subset[i]); @@ -280,7 +280,7 @@ testHashRemoveSetIter(const void *payload G_GNUC_UNUSED, bool rem = false; size_t i; - for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) { + for (i = 0; i < G_N_ELEMENTS(uuids_subset); i++) { if (STREQ(uuids_subset[i], name)) { rem = true; break; @@ -318,7 +318,7 @@ testHashRemoveSet(const void *data G_GNUC_UNUSED) goto cleanup; } - if (testHashCheckCount(hash, ARRAY_CARDINALITY(uuids) - count) < 0) + if (testHashCheckCount(hash, G_N_ELEMENTS(uuids) - count) < 0) goto cleanup; ret = 0; @@ -329,7 +329,7 @@ testHashRemoveSet(const void *data G_GNUC_UNUSED) } -const int testSearchIndex = ARRAY_CARDINALITY(uuids_subset) / 2; +const int testSearchIndex = G_N_ELEMENTS(uuids_subset) / 2; static int testHashSearchIter(const void *payload G_GNUC_UNUSED, @@ -357,7 +357,7 @@ testHashSearch(const void *data G_GNUC_UNUSED) goto cleanup; } - if (testHashCheckCount(hash, ARRAY_CARDINALITY(uuids)) < 0) + if (testHashCheckCount(hash, G_N_ELEMENTS(uuids)) < 0) goto cleanup; ret = 0; diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index d9bdef701d..81a126ff73 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -260,7 +260,7 @@ mymain(void) if (virInitialize() < 0) return EXIT_FAILURE; - for (i = 0; i < ARRAY_CARDINALITY(nodeData); i++) + for (i = 0; i < G_N_ELEMENTS(nodeData); i++) if (virTestRun(nodeData[i].testName, linuxTestHostCPU, &nodeData[i]) != 0) ret = -1; diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 6ebe404762..4722591b86 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -343,7 +343,7 @@ mymain(void) .fake_cmd_output = "iscsiadm_sendtargets", .portal = "10.20.30.40:3260,1", .expected_targets = targets, - .nexpected = ARRAY_CARDINALITY(targets), + .nexpected = G_N_ELEMENTS(targets), }; if (virTestRun("ISCSI scan targets", testISCSIScanTargets, &infoTargets) < 0) rv = -1; diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 3251df8873..53544abbdb 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -61,7 +61,7 @@ static int testMessageHeaderEncode(const void *args G_GNUC_UNUSED) if (virNetMessageEncodeHeader(msg) < 0) goto cleanup; - if (ARRAY_CARDINALITY(expect) != msg->bufferOffset) { + if (G_N_ELEMENTS(expect) != msg->bufferOffset) { VIR_DEBUG("Expect message offset %zu got %zu", sizeof(expect), msg->bufferOffset); goto cleanup; @@ -253,7 +253,7 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) if (virNetMessageEncodePayload(msg, (xdrproc_t)xdr_virNetMessageError, &err) < 0) goto cleanup; - if (ARRAY_CARDINALITY(expect) != msg->bufferLength) { + if (G_N_ELEMENTS(expect) != msg->bufferLength) { VIR_DEBUG("Expect message length %zu got %zu", sizeof(expect), msg->bufferLength); goto cleanup; @@ -495,7 +495,7 @@ static int testMessagePayloadStreamEncode(const void *args G_GNUC_UNUSED) if (virNetMessageEncodePayloadRaw(msg, stream, strlen(stream)) < 0) goto cleanup; - if (ARRAY_CARDINALITY(expect) != msg->bufferLength) { + if (G_N_ELEMENTS(expect) != msg->bufferLength) { VIR_DEBUG("Expect message length %zu got %zu", sizeof(expect), msg->bufferLength); goto cleanup; diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index 9a0d947c1b..6c01336420 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -562,7 +562,7 @@ mymain(void) testTLSWriteCertChain("cacertchain-ctx.pem", certchain, - ARRAY_CARDINALITY(certchain)); + G_N_ELEMENTS(certchain)); DO_CTX_TEST(true, "cacertchain-ctx.pem", servercertlevel3areq.filename, false); DO_CTX_TEST(false, "cacertchain-ctx.pem", clientcertlevel2breq.filename, false); diff --git a/tests/virnettlssessiontest.c b/tests/virnettlssessiontest.c index 8d89b16814..997cf5a372 100644 --- a/tests/virnettlssessiontest.c +++ b/tests/virnettlssessiontest.c @@ -456,7 +456,7 @@ mymain(void) testTLSWriteCertChain("cacertchain-sess.pem", certchain, - ARRAY_CARDINALITY(certchain)); + G_N_ELEMENTS(certchain)); DO_SESS_TEST("cacertchain-sess.pem", servercertlevel3areq.filename, clientcertlevel2breq.filename, false, false, "libvirt.org", NULL); diff --git a/tests/virnumamock.c b/tests/virnumamock.c index fe5e9b4940..3eefb7ccee 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -130,7 +130,7 @@ virNumaGetPages(int node, size_t *npages) { const int pages_def[] = { 4, 2 * 1024, 1 * 1024 * 1024}; - const int npages_def = ARRAY_CARDINALITY(pages_def); + const int npages_def = G_N_ELEMENTS(pages_def); size_t i = 0; if (pages_size) diff --git a/tests/virpcitest.c b/tests/virpcitest.c index de96e6eb7e..4078dc4c69 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -91,7 +91,7 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED) { int ret = -1; virPCIDevicePtr dev[] = {NULL, NULL, NULL}; - size_t i, nDev = ARRAY_CARDINALITY(dev); + size_t i, nDev = G_N_ELEMENTS(dev); virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL; int count; @@ -132,7 +132,7 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) { int ret = -1; virPCIDevicePtr dev[] = {NULL, NULL, NULL}; - size_t i, nDev = ARRAY_CARDINALITY(dev); + size_t i, nDev = G_N_ELEMENTS(dev); virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL; int count; @@ -167,7 +167,7 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) { int ret = -1; virPCIDevicePtr dev[] = {NULL, NULL, NULL}; - size_t i, nDev = ARRAY_CARDINALITY(dev); + size_t i, nDev = G_N_ELEMENTS(dev); virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL; int count; diff --git a/tests/virpolkittest.c b/tests/virpolkittest.c index e80ccfedb7..97fa877445 100644 --- a/tests/virpolkittest.c +++ b/tests/virpolkittest.c @@ -96,7 +96,7 @@ VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block, is_authorized = 0; is_challenge = 0; retdetails = retdetailscancelled; - retdetailslen = ARRAY_CARDINALITY(retdetailscancelled) / 2; + retdetailslen = G_N_ELEMENTS(retdetailscancelled) / 2; } else if (STREQ(actionid, "org.libvirt.test.details")) { size_t i; is_authorized = 0; diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c index 3ccd9a8535..df392f374e 100644 --- a/tests/virrotatingfiletest.c +++ b/tests/virrotatingfiletest.c @@ -85,7 +85,7 @@ static int testRotatingFileReaderAssertBufferContent(const char *buf, char bytes[] = { FILEBYTE, FILEBYTE0, FILEBYTE1 }; size_t total = 0; - if (nregions > ARRAY_CARDINALITY(bytes)) { + if (nregions > G_N_ELEMENTS(bytes)) { fprintf(stderr, "Too many regions %zu\n", nregions); return -1; } @@ -573,7 +573,7 @@ static int testRotatingFileReaderOne(const void *data G_GNUC_UNUSED) goto cleanup; if (testRotatingFileReaderAssertBufferContent(buf, got, - ARRAY_CARDINALITY(regions), + G_N_ELEMENTS(regions), regions) < 0) goto cleanup; @@ -605,7 +605,7 @@ static int testRotatingFileReaderAll(const void *data G_GNUC_UNUSED) goto cleanup; if (testRotatingFileReaderAssertBufferContent(buf, got, - ARRAY_CARDINALITY(regions), + G_N_ELEMENTS(regions), regions) < 0) goto cleanup; @@ -637,7 +637,7 @@ static int testRotatingFileReaderPartial(const void *data G_GNUC_UNUSED) goto cleanup; if (testRotatingFileReaderAssertBufferContent(buf, got, - ARRAY_CARDINALITY(regions), + G_N_ELEMENTS(regions), regions) < 0) goto cleanup; @@ -678,7 +678,7 @@ static int testRotatingFileReaderSeek(const void *data G_GNUC_UNUSED) goto cleanup; if (testRotatingFileReaderAssertBufferContent(buf, got, - ARRAY_CARDINALITY(regions), + G_N_ELEMENTS(regions), regions) < 0) goto cleanup; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 77e8e0e404..20e407448f 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -478,7 +478,7 @@ testPathCanonicalizeReadlink(const char *path, *linkpath = NULL; - for (i = 0; i < ARRAY_CARDINALITY(testPathCanonicalizeSymlinks); i++) { + for (i = 0; i < G_N_ELEMENTS(testPathCanonicalizeSymlinks); i++) { if (STREQ(path, testPathCanonicalizeSymlinks[i][0])) { if (VIR_STRDUP(*linkpath, testPathCanonicalizeSymlinks[i][1]) < 0) return -1; @@ -519,9 +519,9 @@ testPathRelativePrepare(void) { size_t i; - for (i = 0; i < ARRAY_CARDINALITY(backingchain); i++) { + for (i = 0; i < G_N_ELEMENTS(backingchain); i++) { backingchain[i].type = VIR_STORAGE_TYPE_FILE; - if (i < ARRAY_CARDINALITY(backingchain) - 1) + if (i < G_N_ELEMENTS(backingchain) - 1) backingchain[i].backingStore = &backingchain[i + 1]; else backingchain[i].backingStore = NULL; @@ -681,7 +681,7 @@ mymain(void) data = (struct testChainData){ \ start, format, { __VA_ARGS__ }, 0, flags, \ }; \ - for (i = 0; i < ARRAY_CARDINALITY(data.files); i++) \ + for (i = 0; i < G_N_ELEMENTS(data.files); i++) \ if (data.files[i]) \ data.nfiles++; \ if (virTestRun(virTestCounterNext(), \ diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 12dab85ab8..43c76ccda0 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -325,7 +325,7 @@ testStrdup(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - for (i = 0; i < ARRAY_CARDINALITY(array); i++) + for (i = 0; i < G_N_ELEMENTS(array); i++) VIR_FREE(array[i]); return ret; } @@ -384,12 +384,12 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED) int ret = -1; size_t i; - qsort(randlist, ARRAY_CARDINALITY(randlist), sizeof(randlist[0]), + qsort(randlist, G_N_ELEMENTS(randlist), sizeof(randlist[0]), virStringSortCompare); - qsort(randrlist, ARRAY_CARDINALITY(randrlist), sizeof(randrlist[0]), + qsort(randrlist, G_N_ELEMENTS(randrlist), sizeof(randrlist[0]), virStringSortRevCompare); - for (i = 0; i < ARRAY_CARDINALITY(randlist); i++) { + for (i = 0; i < G_N_ELEMENTS(randlist); i++) { if (STRNEQ(randlist[i], sortlist[i])) { fprintf(stderr, "sortlist[%zu] '%s' != randlist[%zu] '%s'\n", i, sortlist[i], i, randlist[i]); diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 0a97443779..8aaac097e9 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -340,7 +340,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_UNUSED) int nicindexes[] = { 2, 1729, 87539319, }; - size_t nnicindexes = ARRAY_CARDINALITY(nicindexes); + size_t nnicindexes = G_N_ELEMENTS(nicindexes); if (virSystemdCreateMachine("demo", "lxc", uuid, @@ -586,7 +586,7 @@ testActivation(bool useNames) map[1].family = AF_INET; map[1].port = virNetSocketGetPort(sockIP[0]); - if (virSystemdGetActivation(map, ARRAY_CARDINALITY(map), &act) < 0) + if (virSystemdGetActivation(map, G_N_ELEMENTS(map), &act) < 0) goto cleanup; if (act == NULL) { diff --git a/tests/virtypedparamtest.c b/tests/virtypedparamtest.c index 9714a0a4c6..87b47ba86e 100644 --- a/tests/virtypedparamtest.c +++ b/tests/virtypedparamtest.c @@ -74,7 +74,7 @@ testTypedParamsValidate(const void *opaque) } #define PARAMS_ARRAY(...) ((virTypedParameter[]){ __VA_ARGS__ }) -#define PARAMS_SIZE(...) ARRAY_CARDINALITY(PARAMS_ARRAY(__VA_ARGS__)) +#define PARAMS_SIZE(...) G_N_ELEMENTS(PARAMS_ARRAY(__VA_ARGS__)) #define PARAMS(...) \ .params = PARAMS_ARRAY(__VA_ARGS__), \ @@ -96,7 +96,7 @@ testTypedParamsFilter(const void *opaque G_GNUC_UNUSED) virTypedParameterPtr *filtered = NULL; - nfiltered = virTypedParamsFilter(params, ARRAY_CARDINALITY(params), + nfiltered = virTypedParamsFilter(params, G_N_ELEMENTS(params), "foo", &filtered); if (nfiltered != 3) goto cleanup; @@ -108,7 +108,7 @@ testTypedParamsFilter(const void *opaque G_GNUC_UNUSED) VIR_FREE(filtered); filtered = NULL; - nfiltered = virTypedParamsFilter(params, ARRAY_CARDINALITY(params), + nfiltered = virTypedParamsFilter(params, G_N_ELEMENTS(params), "bar", &filtered); if (nfiltered != 2) @@ -175,7 +175,7 @@ testTypedParamsGetStringList(const void *opaque G_GNUC_UNUSED) }; picked = virTypedParamsGetStringList(params, - ARRAY_CARDINALITY(params), + G_N_ELEMENTS(params), "bar", &strings); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5c0aa0e588..a83c47a162 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13467,7 +13467,7 @@ virshDomainEventCallback virshDomainEventCallbacks[] = { { "block-threshold", VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, }; -verify(VIR_DOMAIN_EVENT_ID_LAST == ARRAY_CARDINALITY(virshDomainEventCallbacks)); +verify(VIR_DOMAIN_EVENT_ID_LAST == G_N_ELEMENTS(virshDomainEventCallbacks)); static const vshCmdInfo info_event[] = { {.name = "help", diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 163cf21af9..3589d84116 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1242,7 +1242,7 @@ virshNetworkEventCallback virshNetworkEventCallbacks[] = { { "lifecycle", VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint), }, }; -verify(VIR_NETWORK_EVENT_ID_LAST == ARRAY_CARDINALITY(virshNetworkEventCallbacks)); +verify(VIR_NETWORK_EVENT_ID_LAST == G_N_ELEMENTS(virshNetworkEventCallbacks)); static const vshCmdInfo info_network_event[] = { {.name = "help", diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 9236d159ed..455ddedc2d 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -846,7 +846,7 @@ virshNodeDeviceEventCallback virshNodeDeviceEventCallbacks[] = { VIR_NODE_DEVICE_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "update", vshEventGenericPrint, } }; -verify(VIR_NODE_DEVICE_EVENT_ID_LAST == ARRAY_CARDINALITY(virshNodeDeviceEventCallbacks)); +verify(VIR_NODE_DEVICE_EVENT_ID_LAST == G_N_ELEMENTS(virshNodeDeviceEventCallbacks)); static const vshCmdInfo info_node_device_event[] = { diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 55af2e4e4e..b01186f339 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1986,7 +1986,7 @@ virshPoolEventCallback virshPoolEventCallbacks[] = { VIR_STORAGE_POOL_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "refresh", vshEventGenericPrint, } }; -verify(VIR_STORAGE_POOL_EVENT_ID_LAST == ARRAY_CARDINALITY(virshPoolEventCallbacks)); +verify(VIR_STORAGE_POOL_EVENT_ID_LAST == G_N_ELEMENTS(virshPoolEventCallbacks)); static const vshCmdInfo info_pool_event[] = { diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 7558c4c476..f0446c83ae 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -649,7 +649,7 @@ virshSecretEventCallback virshSecretEventCallbacks[] = { VIR_SECRET_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "value-changed", vshEventGenericPrint, }, }; -verify(VIR_SECRET_EVENT_ID_LAST == ARRAY_CARDINALITY(virshSecretEventCallbacks)); +verify(VIR_SECRET_EVENT_ID_LAST == G_N_ELEMENTS(virshSecretEventCallbacks)); static const vshCmdInfo info_secret_event[] = { {.name = "help", diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c index 7fb1335194..daeb2f0e1c 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -99,7 +99,7 @@ static const char * failMessages[] = { N_("NOTE"), }; -verify(ARRAY_CARDINALITY(failMessages) == VIR_HOST_VALIDATE_LAST); +verify(G_N_ELEMENTS(failMessages) == VIR_HOST_VALIDATE_LAST); static const char *failEscapeCodes[] = { "\033[31m", @@ -107,7 +107,7 @@ static const char *failEscapeCodes[] = { "\033[34m", }; -verify(ARRAY_CARDINALITY(failEscapeCodes) == VIR_HOST_VALIDATE_LAST); +verify(G_N_ELEMENTS(failEscapeCodes) == VIR_HOST_VALIDATE_LAST); void virHostMsgFail(virHostValidateLevel level, const char *format,