From nobody Sun May 5 16:02:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1625837064; cv=none; d=zohomail.com; s=zohoarc; b=Fadh0Llt6c+ZaF0O6LIvfPmVq9FAkgKLn6VS7LIjZDGjvT/HjBvP91YXghrpJpznuAWHnDyYnPYp025raIuXWjNGWpt6oqmtY3eMpMpwWBPO7o74QGAOi67n49GHloDVQimiaSgoPJTCYbgE/R192qSwCCoYs9kNSPjrWZ5KQ38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625837064; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wYnukFz196VIlxaoZIagi+KLH781pE5MwNJ6yJym5hg=; b=cZufFoYcALfyS+OSBQJfCW2bpQQKRWg9rQlG6pLFrEYi9BnZCKwy8VvKPRDdY0QwPBBPw05eEUHY5JyYlUgklXpAYGeuGgJJjwLxPrV/68ufEdxCt/spfFPhzkj/10oNhtzc2e/F+XAcJg2zfduC/WRiX7dNiFVHk3rYM1vcUZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16258370647451002.8138338068349; Fri, 9 Jul 2021 06:24:24 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-597-PNLY4lzgOpa2Kqt8K-bfng-1; Fri, 09 Jul 2021 09:24:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C59B106B7D7; Fri, 9 Jul 2021 13:24:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF06560853; Fri, 9 Jul 2021 13:24:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 52DD918095C2; Fri, 9 Jul 2021 13:24:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 169DO08n030491 for ; Fri, 9 Jul 2021 09:24:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id E650F5C1CF; Fri, 9 Jul 2021 13:24:00 +0000 (UTC) Received: from work.redhat.com (ovpn-113-189.ams2.redhat.com [10.36.113.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id C64DE5C1A3; Fri, 9 Jul 2021 13:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625837063; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wYnukFz196VIlxaoZIagi+KLH781pE5MwNJ6yJym5hg=; b=KSL+SRu1hYEf3kIDUDfh08S9UDRrDbU1OrjCO3FGEC6Dbs/UpXPLbltc3lDE6Wg6Wij53X dru95Ywk2Zmm1RrD8XvJ1gQ2baZ2FL5jH1Ht/6gClx/neOWcVpQmTD5Bsw8EjGFLSDQuOJ p6E8dUBlR7hzNwOHz/GEZ5So+U3o5lI= X-MC-Unique: PNLY4lzgOpa2Kqt8K-bfng-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] virQEMUCapsGetMachineTypesCaps: Use GPtrArray Date: Fri, 9 Jul 2021 15:23:52 +0200 Message-Id: <20210709132353.80203-2-twiederh@redhat.com> In-Reply-To: <20210709132353.80203-1-twiederh@redhat.com> References: <20210709132353.80203-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1625837065695100001 Content-Type: text/plain; charset="utf-8" This simplyfies the code a bit and removes one "goto", one "VIR_FREE", and one "VIR_INSERT_ELEMENT_COPY". Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 37 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d1cd8f11ac..d9e1082d4e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -942,6 +942,7 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCaps *qemuCaps, { size_t i; virQEMUCapsAccel *accel; + g_autoptr(GPtrArray) array =3D NULL; =20 /* Guest capabilities do not report TCG vs. KVM caps separately. We ju= st * take the set of machine types we probed first. */ @@ -953,13 +954,13 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCaps *qemuCaps, *machines =3D NULL; *nmachines =3D accel->nmachineTypes; =20 - if (*nmachines) - *machines =3D g_new0(virCapsGuestMachine *, accel->nmachineTypes); + if (*nmachines =3D=3D 0) + return 0; + + array =3D g_ptr_array_sized_new(*nmachines); =20 for (i =3D 0; i < accel->nmachineTypes; i++) { - virCapsGuestMachine *mach; - mach =3D g_new0(virCapsGuestMachine, 1); - (*machines)[i] =3D mach; + virCapsGuestMachine *mach =3D g_new0(virCapsGuestMachine, 1); if (accel->machineTypes[i].alias) { mach->name =3D g_strdup(accel->machineTypes[i].alias); mach->canonical =3D g_strdup(accel->machineTypes[i].name); @@ -968,6 +969,7 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCaps *qemuCaps, } mach->maxCpus =3D accel->machineTypes[i].maxCpus; mach->deprecated =3D accel->machineTypes[i].deprecated; + g_ptr_array_add(array, mach); } =20 /* Make sure all canonical machine types also have their own entry so = that @@ -975,18 +977,19 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCaps *qemuCaps, * supported machine types. */ i =3D 0; - while (i < *nmachines) { + while (i < array->len) { size_t j; bool found =3D false; - virCapsGuestMachine *machine =3D (*machines)[i]; + virCapsGuestMachine *machine =3D g_ptr_array_index(array, i); =20 if (!machine->canonical) { i++; continue; } =20 - for (j =3D 0; j < *nmachines; j++) { - if (STREQ(machine->canonical, (*machines)[j]->name)) { + for (j =3D 0; j < array->len; j++) { + virCapsGuestMachine *mach =3D g_ptr_array_index(array, j); + if (STREQ(machine->canonical, mach->name)) { found =3D true; break; } @@ -995,25 +998,21 @@ virQEMUCapsGetMachineTypesCaps(virQEMUCaps *qemuCaps, if (!found) { virCapsGuestMachine *mach; mach =3D g_new0(virCapsGuestMachine, 1); - if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < = 0) { - VIR_FREE(mach); - goto error; - } mach->name =3D g_strdup(machine->canonical); mach->maxCpus =3D machine->maxCpus; mach->deprecated =3D machine->deprecated; + g_ptr_array_insert(array, i, mach); i++; } i++; } =20 - return 0; + *nmachines =3D array->len; + *machines =3D g_new0(virCapsGuestMachine *, array->len); + for (i =3D 0; i < array->len; ++i) + (*machines)[i] =3D g_ptr_array_index(array, i); =20 - error: - virCapabilitiesFreeMachines(*machines, *nmachines); - *nmachines =3D 0; - *machines =3D NULL; - return -1; + return 0; } =20 =20 --=20 2.31.1 From nobody Sun May 5 16:02:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1625837091; cv=none; d=zohomail.com; s=zohoarc; b=IAX+Z/u80bom+k7B4J9aqTZgEEes8wU3S1V91OirDEftwyW5Tm7EkVwiZvTHCjw8Ly5gZ4JiWtATmCFVHS+9s4CkKOSloJqpS50Sgzbz7mPQhc5mdtVJhdMN0fcxFwWhilpFG2KXFQkgvfiomyPyWw/uqHA+czs9e+lWz5ucM9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625837091; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wOuJX4KIXFBN4a7eOVrqUKm7M6P8i8D4513RQPCw+NY=; b=DXSkSeaEpPtVkbaZ0gxnd1rRTQyKx1K/dGRKUD9pUi4tcfPUmvfTkLi1ZgqMuMDZKiHwLn48E3tPUAcl9DFjfocBlRFK4PlIpuoLHLMyGR0KWGfqVXU07C5tCgqJSam3+g60yeujYJOzMDZK7e+H9n9EToU3FhCr4ardzP0Yuro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1625837091493335.65004203966566; Fri, 9 Jul 2021 06:24:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-602-mW52uq1LP72jGayrgL27Ew-1; Fri, 09 Jul 2021 09:24:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C19F610C1ADC; Fri, 9 Jul 2021 13:24:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0D0D5C1CF; Fri, 9 Jul 2021 13:24:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 662324EA2A; Fri, 9 Jul 2021 13:24:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 169DOflw030542 for ; Fri, 9 Jul 2021 09:24:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 674CF5C23A; Fri, 9 Jul 2021 13:24:41 +0000 (UTC) Received: from work.redhat.com (ovpn-113-189.ams2.redhat.com [10.36.113.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id B50D55C1CF; Fri, 9 Jul 2021 13:24:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625837090; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wOuJX4KIXFBN4a7eOVrqUKm7M6P8i8D4513RQPCw+NY=; b=c2EiagDRiMVLIdnfjW74pq/3uFWFJaHATLI6snywwva7KOzmISmXaDcdjbNA1Dmzc/Xsls lcEhKf6wkDl7wB1VhhkzthsrasTB2+zwaYhVs8+arW26N1YyEBPdOB7+DJULq23q6OKPXi Q8ybB4MacERcUiNWyhcCOJNB8v5UGRI= X-MC-Unique: mW52uq1LP72jGayrgL27Ew-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] viralloc: Delete VIR_INSERT_ELEMENT_COPY and VIR_INSERT_ELEMENT_COPY_INPLACE Date: Fri, 9 Jul 2021 15:23:53 +0200 Message-Id: <20210709132353.80203-3-twiederh@redhat.com> In-Reply-To: <20210709132353.80203-1-twiederh@redhat.com> References: <20210709132353.80203-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1625837092574100001 Content-Type: text/plain; charset="utf-8" There are no users left. Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/util/viralloc.h | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 553d2951cf..72e8f13bef 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -165,7 +165,7 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_= t at, size_t *countptr, sizeof(char[2 * (sizeof(*(a) =3D *(b)) =3D=3D sizeof(*(b))) - 1]) =20 /** - * VIR_INSERT_ELEMENT: + * VIR_INSERT_ELEMENT, VIR_INSERT_ELEMENT_INPLACE: * @ptr: pointer to array of objects (*not* ptr to ptr) * @at: index within array where new elements should be added * @count: variable tracking number of elements currently allocated @@ -179,18 +179,10 @@ int virDeleteElementsN(void *ptrptr, size_t size, siz= e_t at, size_t *countptr, * item 'newelem' into ptr[at], then store the address of * allocated memory in 'ptr' and the new size in 'count'. * - * VIR_INSERT_ELEMENT_COPY is identical, but doesn't clear out the - * original element to 0 on success, so there are two copies of the - * element. This is useful if the "element" is actually just a - * pointer to the real data, and you want to maintain a reference to - * it for use after the insert is completed; but if the "element" is - * an object that points to other allocated memory, having multiple - * copies can cause problems (e.g. double free). + * VIR_INSERT_ELEMENT_INPLACE is identical, but assumes any necessary + * memory re-allocation has already been done. * - * VIR_INSERT_ELEMENT_*INPLACE are identical, but assume any necessary - * memory re-allocation has already been done. - * - * VIR_INSERT_ELEMENT_* all need to send "1" as the "add" argument to + * Both functions need to send "1" as the "add" argument to * virInsertElementsN (which has the currently-unused capability of * inserting multiple items at once). We use this to our advantage by * replacing it with VIR_TYPECHECK(ptr, &newelem) so that we can be @@ -203,15 +195,9 @@ int virDeleteElementsN(void *ptrptr, size_t size, size= _t at, size_t *countptr, #define VIR_INSERT_ELEMENT(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, f= alse) -#define VIR_INSERT_ELEMENT_COPY(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = false) #define VIR_INSERT_ELEMENT_INPLACE(ptr, at, count, newelem) \ virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), true, t= rue) -#define VIR_INSERT_ELEMENT_COPY_INPLACE(ptr, at, count, newelem) \ - virInsertElementsN(&(ptr), sizeof(*(ptr)), at, &(count), \ - VIR_TYPEMATCH(ptr, &(newelem)), &(newelem), false, = true) =20 /** * VIR_APPEND_ELEMENT: --=20 2.31.1