Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in qemuMonitorCPUDefs rather then using an array of pointers. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 8 ++++---- src/qemu/qemu_monitor.c | 5 ++--- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 7 +------ tests/qemumonitorjsontest.c | 8 ++++---- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b06e89a9c5..74920901b3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2460,13 +2460,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon) for (i = 0; i < defs->ncpus; i++) { virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN; - if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_YES) + if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES) usable = VIR_DOMCAPS_CPU_USABLE_YES; - else if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_NO) + else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO) usable = VIR_DOMCAPS_CPU_USABLE_NO; - if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i]->name, usable, - &defs->cpus[i]->blockers) < 0) + if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable, + &defs->cpus[i].blockers) < 0) goto error; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 62248f3362..4442ef6cca 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3540,9 +3540,8 @@ qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs) return; for (i = 0; i < defs->ncpus; i++) { - virStringListFree(defs->cpus[i]->blockers); - VIR_FREE(defs->cpus[i]->name); - VIR_FREE(defs->cpus[i]); + virStringListFree(defs->cpus[i].blockers); + VIR_FREE(defs->cpus[i].name); } VIR_FREE(defs->cpus); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index d59bafbeda..7d35c97860 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1105,7 +1105,7 @@ typedef struct _qemuMonitorCPUDefs qemuMonitorCPUDefs; typedef qemuMonitorCPUDefs *qemuMonitorCPUDefsPtr; struct _qemuMonitorCPUDefs { size_t ncpus; - qemuMonitorCPUDefInfoPtr *cpus; + qemuMonitorCPUDefInfoPtr cpus; }; int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 02bbefdc12..c2a2f6eee6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5560,12 +5560,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, for (i = 0; i < defs->ncpus; i++) { virJSONValuePtr child = virJSONValueArrayGet(data, i); const char *tmp; - qemuMonitorCPUDefInfoPtr cpu; - - if (VIR_ALLOC(cpu) < 0) - return -1; - - defs->cpus[i] = cpu; + qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i; if (!(tmp = virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 14d0a4e22f..3413dee701 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -463,16 +463,16 @@ testQemuMonitorJSONGetCPUDefinitions(const void *opaque) #define CHECK_FULL(i, wantname, Usable) \ do { \ - if (STRNEQ(defs->cpus[i]->name, (wantname))) { \ + if (STRNEQ(defs->cpus[i].name, (wantname))) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "name %s is not %s", \ - defs->cpus[i]->name, (wantname)); \ + defs->cpus[i].name, (wantname)); \ return -1; \ } \ - if (defs->cpus[i]->usable != (Usable)) { \ + if (defs->cpus[i].usable != (Usable)) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "%s: expecting usable flag %d, got %d", \ - defs->cpus[i]->name, Usable, defs->cpus[i]->usable); \ + defs->cpus[i].name, Usable, defs->cpus[i].usable); \ return -1; \ } \ } while (0) -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list