From nobody Wed May 8 19:50:46 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=1625754532; cv=none; d=zohomail.com; s=zohoarc; b=lwm2uDWMowi10MRnb4SKqY7DuciQZpNV7nLAeVoOP1s0BrnSxAvArBqOJstMTFIQS0bHyF2oteIMGmUt7beVZ/a1oA6IIc5EGerife8fpjQReLVNObVeMnc0S3Lb8OcMVdVyVwqd0j/eAVcrOPnMYBNHE/nle/kVLkYSD9VKQMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625754532; 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=ApAsck3YWQKwoNhk3qyhI9s39x3aof/JQISyqtz+EZY=; b=MLOYE8ZJsij6hEvzjsbL5K08dhFcnyJ3NwU82qwmgcoh/N1RSUorz+88Fr8gTSWZQYVoR5QukdBsZYl0eZV8FlbEKu5GbDGl7RoLQW5Lmpc23x8Q/vIeEkekV9xhB16l8aTTw5hJszr+Ofk/aD20eZ9VGlqSU6O8WcDERNkbElU= 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 1625754532596714.1043420742982; Thu, 8 Jul 2021 07:28:52 -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-518-wgyJXrxtMHC0gsGQh-pAtA-1; Thu, 08 Jul 2021 10:28:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 184D89F932; Thu, 8 Jul 2021 14:28:45 +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 E206B19CB4; Thu, 8 Jul 2021 14:28:44 +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 601501809C99; Thu, 8 Jul 2021 14:28:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 168ESYj6014145 for ; Thu, 8 Jul 2021 10:28:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id CC22410190A7; Thu, 8 Jul 2021 14:28:34 +0000 (UTC) Received: from work.redhat.com (ovpn-113-95.ams2.redhat.com [10.36.113.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 202A01017CE8; Thu, 8 Jul 2021 14:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625754531; 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=ApAsck3YWQKwoNhk3qyhI9s39x3aof/JQISyqtz+EZY=; b=P7J6iV96DZAure9jrVXD8OMLLct+DS/pED8rBJGthYY3IsTY6V7NND8AZx4QYgVKm04fI6 mgHNdLlKiXN2LOJ/Skoh1npRC4Df5JOcyc+Lqh92IHj8ro9eOR0r9OttcRwC5i9PCIm8BY jiPawrofIRxvWCJqkIbsWteVFzH9R/8= X-MC-Unique: wgyJXrxtMHC0gsGQh-pAtA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] virQEMUCapsGetMachineTypesCaps: Use GPtrArray Date: Thu, 8 Jul 2021 16:28:27 +0200 Message-Id: <20210708142828.122315-2-twiederh@redhat.com> In-Reply-To: <20210708142828.122315-1-twiederh@redhat.com> References: <20210708142828.122315-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.11 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: 1625754533882100001 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 --- 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..04dae7d66e 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 *, accel->nmachineTypes); + for (i =3D 0; i < array->len; ++i) + (*machines)[i] =3D g_ptr_array_remove_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 Wed May 8 19:50:46 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=1625754537; cv=none; d=zohomail.com; s=zohoarc; b=QB9YRVzsJE+W49usnHBvtmhjn9Gfj3yz4iizyMytlpRdsXeNms9yBvAhfLBKoO271Hl3j3BLclR2rPfMMp5GFv4FOnWc7iEbQ06UypgekUMsJg6X+Fn08dqx1Ek929AHCWAB/ewYacUWhXpBeyn15CaC7V4Hxn2HhtWyvTViW+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625754537; 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=J8s1YtHe4dmMy4GZTXlMmM9wIu5nysI+ncZ6BvofEQ8ZGxGsOl0PiJaTR6kxFiUCqWT4RWtBValx8/0FP9iE4LhUhFPp8tef6fTDyxWpZhTy08Ci7kC1qHFjOTXiFkrXMR3X79rP+7nLNTWoyRzeJ+ShvuTcym7iYuZG5lcRPsg= 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 162575453735496.98002061894692; Thu, 8 Jul 2021 07:28:57 -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-51-69T9x3sZMguPNcPbq1MWPg-1; Thu, 08 Jul 2021 10:28:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D5D79F936; Thu, 8 Jul 2021 14:28:48 +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 048D55D6A8; Thu, 8 Jul 2021 14:28:48 +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 C1F221809CB2; Thu, 8 Jul 2021 14:28:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 168ESZmj014151 for ; Thu, 8 Jul 2021 10:28:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id D21A1101E5AF; Thu, 8 Jul 2021 14:28:35 +0000 (UTC) Received: from work.redhat.com (ovpn-113-95.ams2.redhat.com [10.36.113.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 294E9100EB3E; Thu, 8 Jul 2021 14:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625754535; 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=DNsPo3OwG2pEIGlYFFLuuhhmZc+D9FCy56QIswn21wa/5mJg8Dpi0fuPsT2bC+5Jtqbt2o 7B72bRcT5M2p6EOtjjzzX2IAz8GvHZS7zr/yEhJ5MabGLC3sj1tjlrIj8gxrHTjqJ10Epa LfCc+lBaASeEpmCDV5dKuXAUvROhz78= X-MC-Unique: 69T9x3sZMguPNcPbq1MWPg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] viralloc: Delete VIR_INSERT_ELEMENT_COPY and VIR_INSERT_ELEMENT_COPY_INPLACE Date: Thu, 8 Jul 2021 16:28:28 +0200 Message-Id: <20210708142828.122315-3-twiederh@redhat.com> In-Reply-To: <20210708142828.122315-1-twiederh@redhat.com> References: <20210708142828.122315-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.15 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: 1625754538630100001 Content-Type: text/plain; charset="utf-8" There are no users left. Signed-off-by: Tim Wiederhake --- 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