From nobody Mon Feb 9 04:56:38 2026 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=1628075025; cv=none; d=zohomail.com; s=zohoarc; b=WozcANw2/WEXEiBtMHVmJUAQwYAk6AbRXWUVupLzOjSS9s4drxaoOEorSYCH+G5HJMId+mcLHMvKgwDiHIs66BKgMUkvCDXvSekrFRgjkuighL4wCpSi7uaZn8TaD9kDa8WpS6vDSg5NN2Md367F7z0xRdU0NZbrgL/OlVsbRbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628075025; h=Content-Type:Content-Transfer-Encoding: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=ZYYzqGQ8MdjQuguNVhS2NSRNCaZbD4F21BAJEhAP1Fc=; b=GTgjfgo8NzxFChFvCi14Ag8i7RR2sEu+PLc8RMBAWRj4HYdmnTdu1svgDC1mTqlCgooi0qB29/e36qib8AVSNf6nkLHXwkniiXUjJH79GHuH0k23PurLKbX6++5ewkHCIGyQox59W9+6g4z0H/nNLMvHcdPYRSD/UTKAXZ9xiVg= 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 16280750251081015.7165397007792; Wed, 4 Aug 2021 04:03:45 -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-380-jNt1lzkUMeqyDFh-AvG9og-1; Wed, 04 Aug 2021 07:03:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8222210066E5; Wed, 4 Aug 2021 11:03:35 +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 5EE6729671; Wed, 4 Aug 2021 11:03:35 +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 163444A707; Wed, 4 Aug 2021 11:03:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 174B2oY6014199 for ; Wed, 4 Aug 2021 07:02:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 622425D9DC; Wed, 4 Aug 2021 11:02:50 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id B71FF5DD68 for ; Wed, 4 Aug 2021 11:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628075024; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=ZYYzqGQ8MdjQuguNVhS2NSRNCaZbD4F21BAJEhAP1Fc=; b=U2Z8/WsbR/iTJCprqGPHe5FWykwkhmb7BW4Z7WuAtuAVC7+ryULvgXEThg0XyUCTJf2cWY 04mKWMwGJC5BtGozrCYb02JpMjnYhJUmVF3UptqYIoc2cSjG3ATmZRa3eKzqArGnety0d7 Qv5p2E2UVPoOQLbOSGFIey83tCPYN7s= X-MC-Unique: jNt1lzkUMeqyDFh-AvG9og-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/23] virInsertElementsN: Rename 'add' argument Date: Wed, 4 Aug 2021 13:02:21 +0200 Message-Id: <704b55a5210ffe8f64f45bd1d93784219b92e78b.1628074874.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.14 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: 1628075026660100005 Content-Type: text/plain; charset="utf-8" The idea of @add was that the insersion/appension macros would allow adding more than one element but this feature was never implemented. 'add' is nowadays used as a dummy variable consuming the result of the VIR_TYPEMATCH compile time check. Make it obvious that we don't use 'add' by renaming it to 'typematchDummy', marking it as unused and replacing all occurences where the value was used by literal '1'. Signed-off-by: Peter Krempa --- src/util/viralloc.c | 31 ++++++++++++++++--------------- src/util/viralloc.h | 14 +------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/util/viralloc.c b/src/util/viralloc.c index cd7ae9e7d1..6c76da8537 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -148,7 +148,7 @@ void virShrinkN(void *ptrptr, size_t size, size_t *coun= tptr, size_t toremove) * @size: the size of one element in bytes * @at: index within array where new elements should be added, -1 fo= r end * @countptr: variable tracking number of elements currently allocated - * @add: number of elements to add + * @typematchDummy: helper variable to consume results of compile time che= cks * @newelems: pointer to array of one or more new elements to move into * place (the originals will be zeroed out if successful * and if clearOriginal is true) @@ -160,8 +160,8 @@ void virShrinkN(void *ptrptr, size_t size, size_t *coun= tptr, size_t toremove) * already* done that. * * Re-allocate an array of *countptr elements, each sizeof(*ptrptr) bytes - * long, to be *countptr+add elements long, then appropriately move - * the elements starting at ptrptr[at] up by add elements, copy the + * long, to be *countptr elements long, then appropriately move + * the elements starting at ptrptr[at] up by 1 elements, copy the * items from newelems into ptrptr[at], then store the address of * allocated memory in *ptrptr and the new size in *countptr. If * newelems is NULL, the new elements at ptrptr[at] are instead filled @@ -173,22 +173,23 @@ void virShrinkN(void *ptrptr, size_t size, size_t *co= untptr, size_t toremove) int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, - size_t add, void *newelems, + size_t typematchDummy G_GNUC_UNUSED, + void *newelems, bool clearOriginal, bool inPlace) { if (at =3D=3D -1) { at =3D *countptr; } else if (at > *countptr) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("out of bounds index - count %zu at %zu add %zu"), - *countptr, at, add); + _("out of bounds index - count %zu at %zu"), + *countptr, at); return -1; } if (inPlace) { - *countptr +=3D add; + *countptr +=3D 1; } else { - virExpandN(ptrptr, size, countptr, add); + virExpandN(ptrptr, size, countptr, 1); } /* memory was successfully re-allocated. Move up all elements from @@ -197,19 +198,19 @@ virInsertElementsN(void *ptrptr, size_t size, size_t = at, * from their original location. Remember that *countptr has * already been updated with new element count! */ - if (at < *countptr - add) { - memmove(*(char**)ptrptr + (size * (at + add)), + if (at < *countptr - 1) { + memmove(*(char**)ptrptr + (size * (at + 1)), *(char**)ptrptr + (size * at), - size * (*countptr - add - at)); + size * (*countptr - 1 - at)); } if (newelems) { - memcpy(*(char**)ptrptr + (size * at), newelems, size * add); + memcpy(*(char**)ptrptr + (size * at), newelems, size); if (clearOriginal) - memset((char*)newelems, 0, size * add); - } else if (inPlace || (at < *countptr - add)) { + memset((char*)newelems, 0, size); + } else if (inPlace || (at < *countptr - 1)) { /* NB: if inPlace, assume memory at the end wasn't initialized */ - memset(*(char**)ptrptr + (size * at), 0, size * add); + memset(*(char**)ptrptr + (size * at), 0, size); } return 0; diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 72e8f13bef..b637bc2ca4 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -43,7 +43,7 @@ void virResizeN(void *ptrptr, size_t size, size_t *alloc,= size_t count, size_t d void virShrinkN(void *ptrptr, size_t size, size_t *count, size_t toremove) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, - size_t add, void *newelem, + size_t typematchDummy, void *newelem, bool clearOriginal, bool inPlace) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, @@ -182,12 +182,6 @@ int virDeleteElementsN(void *ptrptr, size_t size, size= _t at, size_t *countptr, * VIR_INSERT_ELEMENT_INPLACE is identical, but assumes any necessary * memory re-allocation has already been done. * - * 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 - * assured ptr and &newelem are of compatible types. - * * These macros are safe to use on arguments with side effects. * * Returns -1 on failure (with OOM error reported), 0 on success @@ -224,12 +218,6 @@ int virDeleteElementsN(void *ptrptr, size_t size, size= _t at, size_t *countptr, * VIR_APPEND_ELEMENT_*INPLACE are identical, but assume any * necessary memory re-allocation has already been done. * - * VIR_APPEND_ELEMENT_* all 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 - * assured ptr and &newelem are of compatible types. - * * These macros are safe to use on arguments with side effects. * * Returns -1 on failure (with OOM error reported), 0 on success --=20 2.31.1