From nobody Mon May 13 17:51:14 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170074217598270.22255369641653; Thu, 23 Nov 2023 04:22:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A282C1857; Thu, 23 Nov 2023 07:22:52 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9A2DB1805; Thu, 23 Nov 2023 07:19:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 92B0F17E4; Thu, 23 Nov 2023 07:19:06 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2266217E4 for ; Thu, 23 Nov 2023 07:19:05 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-Xf7d-q_8OMq06zW4Q5dR6w-1; Thu, 23 Nov 2023 07:19:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0BB528004EE for ; Thu, 23 Nov 2023 12:19:02 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3C62166B26 for ; Thu, 23 Nov 2023 12:19:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Xf7d-q_8OMq06zW4Q5dR6w-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 1/3] build-aux: Refresh list of nonreentrant functions Date: Thu, 23 Nov 2023 13:18:58 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: V3QSXQ25GWZJ72WNKHOSWBDGWW6VFN53 X-Message-ID-Hash: V3QSXQ25GWZJ72WNKHOSWBDGWW6VFN53 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1700742176901100001 There's a new twalk() function that has a reentrant variant. Add the former onto list of nonreentrant functions. Also, refresh the comment on how to get the list, because it's outdated a bit. Signed-off-by: Michal Privoznik --- build-aux/Makefile.nonreentrant | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/build-aux/Makefile.nonreentrant b/build-aux/Makefile.nonreentr= ant index 87bb9db20e..729f395e9d 100644 --- a/build-aux/Makefile.nonreentrant +++ b/build-aux/Makefile.nonreentrant @@ -15,17 +15,17 @@ ## . =20 # -# Generated by running the following on Fedora 26: +# Generated by running the following on current Gentoo: # -# nm -D --defined-only /lib64/libc.so.6 \ +# nm -D --defined-only --without-symbol-versions /lib64/libc.so.6 \ # | grep '_r$' \ # | awk '{print $3}' \ -# | grep -v __ \ -# | grep -v qsort \ # Red herring since we don't need to pass extra a= rgs to qsort comparator -# | grep -v readdir \ # This is safe as long as each DIR * instance i= s only used by one thread -# | sort \ -# | uniq \ -# | sed -e 's/_r//' +# | grep -v -e '^_' -e 'qsort' -e 'readdir' \ +# | sort -u \ +# | sed -s 's/_r$//' +# +# qsort() is safe because we don't need to pass extra args to qsort compar= ator, +# readdir*() is safe as long as each DIR * instance is only used by one th= read. # # Also manually add in all inet_* functions some of which # are not threadsafe and do not have _r variants. They are @@ -94,8 +94,8 @@ NON_REENTRANT +=3D nrand48 NON_REENTRANT +=3D ptsname NON_REENTRANT +=3D qecvt NON_REENTRANT +=3D qfcvt -NON_REENTRANT +=3D random NON_REENTRANT +=3D rand +NON_REENTRANT +=3D random NON_REENTRANT +=3D seed48 NON_REENTRANT +=3D setstate NON_REENTRANT +=3D sgetsgent @@ -106,6 +106,7 @@ NON_REENTRANT +=3D strerror NON_REENTRANT +=3D strtok NON_REENTRANT +=3D tmpnam NON_REENTRANT +=3D ttyname +NON_REENTRANT +=3D twalk NON_REENTRANT +=3D inet_addr NON_REENTRANT +=3D inet_aton NON_REENTRANT +=3D inet_lnaof --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Mon May 13 17:51:14 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1700742549805215.31358057353998; Thu, 23 Nov 2023 04:29:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8F2991866; Thu, 23 Nov 2023 07:29:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 820F2186A; Thu, 23 Nov 2023 07:19:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 012AE17AC; Thu, 23 Nov 2023 07:19:08 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 66C8E17E8 for ; Thu, 23 Nov 2023 07:19:06 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-CIjNT6YONfC9mip4uDkcBw-1; Thu, 23 Nov 2023 07:19:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB3598007B3 for ; Thu, 23 Nov 2023 12:19:03 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 207CA2166B26 for ; Thu, 23 Nov 2023 12:19:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: CIjNT6YONfC9mip4uDkcBw-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 2/3] lib: Replace qsort() with g_qsort_with_data() Date: Thu, 23 Nov 2023 13:18:59 +0100 Message-ID: <3d31e981ce8f1418643d1dd0dd42e6ee08817b41.1700741882.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 7GQIB3IRUFERJWTW7PXUZYL4HRYDMANN X-Message-ID-Hash: 7GQIB3IRUFERJWTW7PXUZYL4HRYDMANN X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1700742550201100001 While glibc provides qsort(), which usually is just a mergesort, until sorting arrays so huge that temporary array used by mergesort would not fit into physical memory (which in our case is never), we are not guaranteed it'll use mergesort. The advantage of mergesort is clear - it's stable. IOW, if we have an array of values parsed from XML, qsort() it and produce some output based on those values, we can then compare the output with some expected output, line by line. But with newer glibc this is all history. After [1], qsort() is no longer mergesort but introsort instead, which is not stable. This is suboptimal, because in some cases we want to preserve order of equal items. For instance, in ebiptablesApplyNewRules(), nwfilter rules are sorted by their priority. But if two rules have the same priority, we want to keep them in the order they appear in the XML. Since it's hard/needless work to identify places where stable or unstable sorting is needed, let's just play it safe and use stable sorting everywhere. Fortunately, glib provides g_qsort_with_data() which indeed implement mergesort and it's a drop in replacement for qsort(), almost. It accepts fifth argument (pointer to opaque data), that is passed to comparator function, which then accepts three arguments. We have to keep one occurance of qsort() though - in NSS module which deliberately does not link with glib. 1: https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommitdiff;h=3D03bf8357e82= 91857a435afcc3048e0b697b6cc04 Signed-off-by: Michal Privoznik --- build-aux/Makefile.nonreentrant | 3 +-- build-aux/syntax-check.mk | 2 +- src/conf/capabilities.c | 8 ++++--- src/conf/domain_conf.c | 6 +++-- src/cpu/cpu.c | 7 +++--- src/cpu/cpu_x86.c | 15 +++++++----- src/lxc/lxc_container.c | 3 ++- src/nwfilter/nwfilter_ebiptables_driver.c | 29 +++++++++++++++-------- src/qemu/qemu_monitor_json.c | 6 +++-- src/qemu/qemu_process.c | 7 +++--- src/security/security_manager.c | 9 ++++--- src/util/virfile.c | 8 ++++--- src/util/virhash.c | 9 ++++--- src/util/virresctrl.c | 9 ++++--- src/util/virstring.c | 12 ++++++---- src/util/virstring.h | 8 +++++-- src/util/virtypedparam.c | 9 ++++--- tests/commandhelper.c | 6 +++-- tests/virstringtest.c | 8 +++---- tools/virsh-checkpoint.c | 10 ++++---- tools/virsh-domain-monitor.c | 11 +++++---- tools/virsh-host.c | 7 ++++-- tools/virsh-interface.c | 11 +++++---- tools/virsh-network.c | 29 +++++++++++++++-------- tools/virsh-nodedev.c | 11 +++++---- tools/virsh-nwfilter.c | 22 ++++++++++------- tools/virsh-pool.c | 11 +++++---- tools/virsh-secret.c | 11 +++++---- tools/virsh-snapshot.c | 10 ++++---- tools/virsh-volume.c | 10 +++++--- 30 files changed, 196 insertions(+), 111 deletions(-) diff --git a/build-aux/Makefile.nonreentrant b/build-aux/Makefile.nonreentr= ant index 729f395e9d..4ecd694b2f 100644 --- a/build-aux/Makefile.nonreentrant +++ b/build-aux/Makefile.nonreentrant @@ -20,11 +20,10 @@ # nm -D --defined-only --without-symbol-versions /lib64/libc.so.6 \ # | grep '_r$' \ # | awk '{print $3}' \ -# | grep -v -e '^_' -e 'qsort' -e 'readdir' \ +# | grep -v -e '^_' -e 'readdir' \ # | sort -u \ # | sed -s 's/_r$//' # -# qsort() is safe because we don't need to pass extra args to qsort compar= ator, # readdir*() is safe as long as each DIR * instance is only used by one th= read. # # Also manually add in all inet_* functions some of which diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 53dcf11a06..309ca0c29a 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -380,7 +380,7 @@ sc_prohibit_unsigned_pid: # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$'= \ # |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \ -# |grep -vE '^(qsort|if|close|assert|fputc|free|N_|vir.*GetName|.*Unlock|v= irNodeListDevices|virHashRemoveEntry|freeaddrinfo|.*[fF]ree|xdrmem_create|x= mlXPathFreeObject|virUUIDFormat|openvzSetProgramSentinal|polkit_action_unre= f)$' +# |grep -vE '^(if|close|assert|fputc|free|N_|vir.*GetName|.*Unlock|virNode= ListDevices|virHashRemoveEntry|freeaddrinfo|.*[fF]ree|xdrmem_create|xmlXPat= hFreeObject|virUUIDFormat|openvzSetProgramSentinal|polkit_action_unref)$' =20 msg_gen_function =3D msg_gen_function +=3D VIR_ERROR diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 34f04cb7d3..32badee7b3 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2073,7 +2073,8 @@ virCapsHostCacheBankFree(virCapsHostCacheBank *ptr) =20 static int virCapsHostCacheBankSorter(const void *a, - const void *b) + const void *b, + void *opaque G_GNUC_UNUSED) { virCapsHostCacheBank *ca =3D *(virCapsHostCacheBank **)a; virCapsHostCacheBank *cb =3D *(virCapsHostCacheBank **)b; @@ -2273,8 +2274,9 @@ virCapabilitiesInitCaches(virCaps *caps) * still traverse the directory instead of guessing names (in case the= re is * 'index1' and 'index3' but no 'index2'). */ if (caps->host.cache.banks) { - qsort(caps->host.cache.banks, caps->host.cache.nbanks, - sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter); + g_qsort_with_data(caps->host.cache.banks, caps->host.cache.nbanks, + sizeof(*caps->host.cache.banks), + virCapsHostCacheBankSorter, NULL); } =20 if (virCapabilitiesInitResctrlMemory(caps) < 0) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 27f6862067..f7d7244738 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15703,7 +15703,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, } =20 =20 -static int virDomainIdMapEntrySort(const void *a, const void *b) +static int virDomainIdMapEntrySort(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const virDomainIdMapEntry *entrya =3D a; const virDomainIdMapEntry *entryb =3D b; @@ -15746,7 +15748,7 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, } } =20 - qsort(idmap, num, sizeof(idmap[0]), virDomainIdMapEntrySort); + g_qsort_with_data(idmap, num, sizeof(idmap[0]), virDomainIdMapEntrySor= t, NULL); =20 return idmap; } diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index bb5737e938..bc43aa4e93 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1045,7 +1045,8 @@ virCPUConvertLegacy(virArch arch, =20 static int virCPUFeatureCompare(const void *p1, - const void *p2) + const void *p2, + void *opaque G_GNUC_UNUSED) { const virCPUFeatureDef *f1 =3D p1; const virCPUFeatureDef *f2 =3D p2; @@ -1085,8 +1086,8 @@ virCPUExpandFeatures(virArch arch, driver->expandFeatures(cpu) < 0) return -1; =20 - qsort(cpu->features, cpu->nfeatures, sizeof(*cpu->features), - virCPUFeatureCompare); + g_qsort_with_data(cpu->features, cpu->nfeatures, sizeof(*cpu->features= ), + virCPUFeatureCompare, NULL); =20 VIR_DEBUG("nfeatures=3D%zu", cpu->nfeatures); return 0; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 7a7f3b409d..8d0e3947ce 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -393,7 +393,9 @@ x86FeatureFindInternal(const char *name) =20 =20 static int -virCPUx86DataSorter(const void *a, const void *b) +virCPUx86DataSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virCPUx86DataItem *da =3D (virCPUx86DataItem *) a; virCPUx86DataItem *db =3D (virCPUx86DataItem *) b; @@ -437,7 +439,7 @@ static int virCPUx86DataItemCmp(const virCPUx86DataItem *item1, const virCPUx86DataItem *item2) { - return virCPUx86DataSorter(item1, item2); + return virCPUx86DataSorter(item1, item2, NULL); } =20 =20 @@ -541,8 +543,9 @@ virCPUx86DataAddItem(virCPUx86Data *data, VIR_APPEND_ELEMENT_COPY(data->items, data->len, *((virCPUx86DataItem *)item)); =20 - qsort(data->items, data->len, - sizeof(virCPUx86DataItem), virCPUx86DataSorter); + g_qsort_with_data(data->items, data->len, + sizeof(virCPUx86DataItem), + virCPUx86DataSorter, NULL); } =20 return 0; @@ -3465,8 +3468,8 @@ virCPUx86DataGetHost(void) } =20 /* the rest of the code expects the function to be in order */ - qsort(cpuid->data.x86.items, cpuid->data.x86.len, - sizeof(virCPUx86DataItem), virCPUx86DataSorter); + g_qsort_with_data(cpuid->data.x86.items, cpuid->data.x86.len, + sizeof(virCPUx86DataItem), virCPUx86DataSorter, NULL= ); =20 return cpuid; } diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 35a882171b..652697890f 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -791,7 +791,8 @@ static int lxcContainerSetReadOnly(void) if (!mounts) return 0; =20 - qsort(mounts, nmounts, sizeof(mounts[0]), virStringSortRevCompare); + g_qsort_with_data(mounts, nmounts, + sizeof(mounts[0]), virStringSortRevCompare, NULL); =20 /* turn 'mounts' into a proper GStrv */ VIR_EXPAND_N(mounts, nmounts, 1); diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 1c5da2ae05..56bddb9097 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3087,7 +3087,9 @@ virNWFilterRuleInstSort(const void *a, const void *b) =20 =20 static int -virNWFilterRuleInstSortPtr(const void *a, const void *b) +virNWFilterRuleInstSortPtr(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNWFilterRuleInst * const *insta =3D a; virNWFilterRuleInst * const *instb =3D b; @@ -3097,7 +3099,8 @@ virNWFilterRuleInstSortPtr(const void *a, const void = *b) =20 static int ebiptablesFilterOrderSort(const void *va, - const void *vb) + const void *vb, + void *opaque G_GNUC_UNUSED) { const virHashKeyValuePair *a =3D va; const virHashKeyValuePair *b =3D vb; @@ -3244,7 +3247,9 @@ struct _ebtablesSubChainInst { =20 =20 static int -ebtablesSubChainInstSort(const void *a, const void *b) +ebtablesSubChainInstSort(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const ebtablesSubChainInst **insta =3D (const ebtablesSubChainInst **)= a; const ebtablesSubChainInst **instb =3D (const ebtablesSubChainInst **)= b; @@ -3268,7 +3273,8 @@ ebtablesGetSubChainInsts(GHashTable *chains, if (filter_names =3D=3D NULL) return -1; =20 - qsort(filter_names, nfilter_names, sizeof(*filter_names), ebiptablesFi= lterOrderSort); + g_qsort_with_data(filter_names, nfilter_names, + sizeof(*filter_names), ebiptablesFilterOrderSort, NU= LL); =20 for (i =3D 0; filter_names[i].key; i++) { g_autofree ebtablesSubChainInst *inst =3D NULL; @@ -3306,9 +3312,10 @@ ebiptablesApplyNewRules(const char *ifname, size_t nsubchains =3D 0; int ret =3D -1; =20 - if (nrules) - qsort(rules, nrules, sizeof(rules[0]), - virNWFilterRuleInstSortPtr); + if (nrules) { + g_qsort_with_data(rules, nrules, sizeof(rules[0]), + virNWFilterRuleInstSortPtr, NULL); + } =20 /* cleanup whatever may exist */ virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); @@ -3388,9 +3395,11 @@ ebiptablesApplyNewRules(const char *ifname, goto cleanup; } =20 - if (nsubchains > 0) - qsort(subchains, nsubchains, sizeof(subchains[0]), - ebtablesSubChainInstSort); + if (nsubchains > 0) { + g_qsort_with_data(subchains, nsubchains, + sizeof(subchains[0]), + ebtablesSubChainInstSort, NULL); + } =20 for (i =3D 0, j =3D 0; i < nrules; i++) { if (virNWFilterRuleIsProtocolEthernet(rules[i]->def)) { diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 105d729d7c..6f1dffe8f7 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7607,7 +7607,8 @@ qemuMonitorJSONProcessHotpluggableCpusReply(virJSONVa= lue *vcpu, =20 static int qemuMonitorQueryHotpluggableCpusEntrySort(const void *p1, - const void *p2) + const void *p2, + void *opaque G_GNUC_UNUSED) { const struct qemuMonitorQueryHotpluggableCpusEntry *a =3D p1; const struct qemuMonitorQueryHotpluggableCpusEntry *b =3D p2; @@ -7659,7 +7660,8 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitor *mon, goto cleanup; } =20 - qsort(info, ninfo, sizeof(*info), qemuMonitorQueryHotpluggableCpusEntr= ySort); + g_qsort_with_data(info, ninfo, sizeof(*info), + qemuMonitorQueryHotpluggableCpusEntrySort, NULL); =20 *entries =3D g_steal_pointer(&info); *nentries =3D ninfo; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b9267d8699..f32e82bbd1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6093,7 +6093,8 @@ qemuDomainHasHotpluggableStartupVcpus(virDomainDef *d= ef) =20 static int qemuProcessVcpusSortOrder(const void *a, - const void *b) + const void *b, + void *opaque G_GNUC_UNUSED) { virDomainVcpuDef *vcpua =3D *((virDomainVcpuDef **)a); virDomainVcpuDef *vcpub =3D *((virDomainVcpuDef **)b); @@ -6133,8 +6134,8 @@ qemuProcessSetupHotpluggableVcpus(virDomainObj *vm, if (nbootHotplug =3D=3D 0) return 0; =20 - qsort(bootHotplug, nbootHotplug, sizeof(*bootHotplug), - qemuProcessVcpusSortOrder); + g_qsort_with_data(bootHotplug, nbootHotplug, + sizeof(*bootHotplug), qemuProcessVcpusSortOrder, NUL= L); =20 if (virDomainCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup= ) < 0) goto cleanup; diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index 5df0cd3419..afd41f1c20 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -1247,7 +1247,9 @@ virSecurityManagerRestoreNetdevLabel(virSecurityManag= er *mgr, =20 =20 static int -cmpstringp(const void *p1, const void *p2) +cmpstringp(const void *p1, + const void *p2, + void *opaque G_GNUC_UNUSED) { const char *s1 =3D *(char * const *) p1; const char *s2 =3D *(char * const *) p2; @@ -1303,8 +1305,9 @@ virSecurityManagerMetadataLock(virSecurityManager *mg= r G_GNUC_UNUSED, * paths in the same order and thus no deadlock can occur. * Lastly, it makes searching for duplicate paths below * simpler. */ - if (paths) - qsort(paths, npaths, sizeof(*paths), cmpstringp); + if (paths) { + g_qsort_with_data(paths, npaths, sizeof(*paths), cmpstringp, NULL); + } =20 for (i =3D 0; i < npaths; i++) { const char *p =3D paths[i]; diff --git a/src/util/virfile.c b/src/util/virfile.c index 54708652fb..007b6cf512 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2193,9 +2193,11 @@ virFileGetMountSubtreeImpl(const char *mtabpath, mounts[nmounts - 2] =3D g_strdup(mntent.mnt_dir); } =20 - if (mounts) - qsort(mounts, nmounts - 1, sizeof(mounts[0]), - reverse ? virStringSortRevCompare : virStringSortCompare); + if (mounts) { + g_qsort_with_data(mounts, nmounts - 1, sizeof(mounts[0]), + reverse ? virStringSortRevCompare : virStringSor= tCompare, + NULL); + } =20 *mountsret =3D mounts; *nmountsret =3D nmounts ? nmounts - 1 : 0; diff --git a/src/util/virhash.c b/src/util/virhash.c index 8365f51eb3..19908c9412 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -514,7 +514,8 @@ void *virHashSearch(GHashTable *table, =20 static int virHashGetItemsKeySorter(const void *va, - const void *vb) + const void *vb, + void *opaque G_GNUC_UNUSED) { const virHashKeyValuePair *a =3D va; const virHashKeyValuePair *b =3D vb; @@ -552,8 +553,10 @@ virHashGetItems(GHashTable *table, i++; } =20 - if (sortKeys) - qsort(items, *nitems, sizeof(*items), virHashGetItemsKeySorter); + if (sortKeys) { + g_qsort_with_data(items, *nitems, + sizeof(*items), virHashGetItemsKeySorter, NULL); + } =20 return items; } diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 8ca58f5d10..30ae25c487 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2522,7 +2522,8 @@ virResctrlMonitorRemove(virResctrlMonitor *monitor) =20 static int virResctrlMonitorStatsSorter(const void *a, - const void *b) + const void *b, + void *opaque G_GNUC_UNUSED) { return (*(virResctrlMonitorStats **)a)->id - (*(virResctrlMonitorStats **)b)->id; @@ -2625,8 +2626,10 @@ virResctrlMonitorGetStats(virResctrlMonitor *monitor, } =20 /* Sort in id's ascending order */ - if (*nstats) - qsort(*stats, *nstats, sizeof(**stats), virResctrlMonitorStatsSort= er); + if (*nstats) { + g_qsort_with_data(*stats, *nstats, sizeof(**stats), + virResctrlMonitorStatsSorter, NULL); + } =20 ret =3D 0; cleanup: diff --git a/src/util/virstring.c b/src/util/virstring.c index 6b728ff047..81c9aff304 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -518,9 +518,11 @@ virStringIsEmpty(const char *str) * virStringSortCompare: * * A comparator function for sorting strings in - * normal order with qsort(). + * normal order with g_qsort_with_data(). */ -int virStringSortCompare(const void *a, const void *b) +int virStringSortCompare(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const char **sa =3D (const char**)a; const char **sb =3D (const char**)b; @@ -532,9 +534,11 @@ int virStringSortCompare(const void *a, const void *b) * virStringSortRevCompare: * * A comparator function for sorting strings in - * reverse order with qsort(). + * reverse order with g_qsort_with_data(). */ -int virStringSortRevCompare(const void *a, const void *b) +int virStringSortRevCompare(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const char **sa =3D (const char**)a; const char **sb =3D (const char**)b; diff --git a/src/util/virstring.h b/src/util/virstring.h index 16dcce98f4..8f9b1edc8f 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -83,8 +83,12 @@ bool virStringIsEmpty(const char *str); int virStrcpy(char *dest, const char *src, size_t destbytes); #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) =20 -int virStringSortCompare(const void *a, const void *b); -int virStringSortRevCompare(const void *a, const void *b); +int virStringSortCompare(const void *a, + const void *b, + void *opaque); +int virStringSortRevCompare(const void *a, + const void *b, + void *opaque); int virStringToUpper(char **dst, const char *src); =20 ssize_t virStringSearch(const char *str, diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index ef3b8052f6..1be249d855 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -43,7 +43,9 @@ VIR_ENUM_IMPL(virTypedParameter, ); =20 static int -virTypedParamsSortName(const void *left, const void *right) +virTypedParamsSortName(const void *left, + const void *right, + void *opaque G_GNUC_UNUSED) { const virTypedParameter *param_left =3D left, *param_right =3D right; return strcmp(param_left->field, param_right->field); @@ -78,7 +80,8 @@ virTypedParamsValidate(virTypedParameterPtr params, int n= params, ...) =20 /* Here we intentionally don't copy values */ memcpy(sorted, params, sizeof(*params) * nparams); - qsort(sorted, nparams, sizeof(*sorted), virTypedParamsSortName); + g_qsort_with_data(sorted, nparams, + sizeof(*sorted), virTypedParamsSortName, NULL); =20 name =3D va_arg(ap, const char *); while (name) { @@ -102,7 +105,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int= nparams, ...) =20 va_end(ap); =20 - qsort(keys, nkeys, sizeof(*keys), virTypedParamsSortName); + g_qsort_with_data(keys, nkeys, sizeof(*keys), virTypedParamsSortName, = NULL); =20 for (i =3D 0, j =3D 0; i < nparams && j < nkeys;) { if (STRNEQ(sorted[i].field, keys[j].field)) { diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 334b02122c..d4629d824e 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -129,7 +129,9 @@ static void printArguments(FILE *log, int argc, char** = argv) } } =20 -static int envsort(const void *a, const void *b) +static int envsort(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const char *astr =3D *(const char**)a; const char *bstr =3D *(const char**)b; @@ -165,7 +167,7 @@ static int printEnvironment(FILE *log) newenv[i] =3D environ[i]; } =20 - qsort(newenv, length, sizeof(newenv[0]), envsort); + g_qsort_with_data(newenv, length, sizeof(newenv[0]), envsort, NULL); =20 for (i =3D 0; i < length; i++) { /* Ignore the variables used to instruct the loader into diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 6e697cc240..f4976890db 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -89,10 +89,10 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED) }; size_t i; =20 - qsort(randlist, G_N_ELEMENTS(randlist), sizeof(randlist[0]), - virStringSortCompare); - qsort(randrlist, G_N_ELEMENTS(randrlist), sizeof(randrlist[0]), - virStringSortRevCompare); + g_qsort_with_data(randlist, G_N_ELEMENTS(randlist), + sizeof(randlist[0]), virStringSortCompare, NULL); + g_qsort_with_data(randrlist, G_N_ELEMENTS(randrlist), + sizeof(randrlist[0]), virStringSortRevCompare, NULL); =20 for (i =3D 0; i < G_N_ELEMENTS(randlist); i++) { if (STRNEQ(randlist[i], sortlist[i])) { diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 727de34abb..34bae34f9a 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -526,7 +526,8 @@ virshCheckpointListFree(struct virshCheckpointList *che= ckpointlist) =20 static int virshChkSorter(const void *a, - const void *b) + const void *b, + void *opaque G_GNUC_UNUSED) { const struct virshChk *sa =3D a; const struct virshChk *sb =3D b; @@ -594,9 +595,10 @@ virshCheckpointListCollect(vshControl *ctl, } =20 if (!(orig_flags & VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL) && - checkpointlist->chks) - qsort(checkpointlist->chks, checkpointlist->nchks, - sizeof(*checkpointlist->chks), virshChkSorter); + checkpointlist->chks) { + g_qsort_with_data(checkpointlist->chks, checkpointlist->nchks, + sizeof(*checkpointlist->chks), virshChkSorter, N= ULL); + } =20 ret =3D g_steal_pointer(&checkpointlist); =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 89fdc7a050..a2c56fc090 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1483,7 +1483,9 @@ static const vshCmdInfo info_list[] =3D { =20 /* compare domains, pack NULLed ones at the end */ static int -virshDomainSorter(const void *a, const void *b) +virshDomainSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virDomainPtr *da =3D (virDomainPtr *) a; virDomainPtr *db =3D (virDomainPtr *) b; @@ -1741,9 +1743,10 @@ virshDomainListCollect(vshControl *ctl, unsigned int= flags) =20 finished: /* sort the list */ - if (list->domains && list->ndomains) - qsort(list->domains, list->ndomains, sizeof(*list->domains), - virshDomainSorter); + if (list->domains && list->ndomains) { + g_qsort_with_data(list->domains, list->ndomains, + sizeof(*list->domains), virshDomainSorter, NULL); + } =20 /* truncate the list if filter simulation deleted entries */ if (deleted) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 4116481978..6c14be865f 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -300,7 +300,9 @@ static const vshCmdOptDef opts_freepages[] =3D { }; =20 static int -vshPageSizeSorter(const void *a, const void *b) +vshPageSizeSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { unsigned int pa =3D *(unsigned int *)a; unsigned int pb =3D *(unsigned int *)b; @@ -377,7 +379,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) * @pagesize array will contain duplicates. We should * remove them otherwise not very nice output will be * produced. */ - qsort(pagesize, nodes_cnt, sizeof(*pagesize), vshPageSizeSorte= r); + g_qsort_with_data(pagesize, nodes_cnt, + sizeof(*pagesize), vshPageSizeSorter, NULL); =20 for (i =3D 0; i < nodes_cnt - 1;) { if (pagesize[i] =3D=3D pagesize[i + 1]) { diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 77c0fff847..09a3668438 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -141,7 +141,9 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshInterfaceSorter(const void *a, const void *b) +virshInterfaceSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virInterfacePtr *ia =3D (virInterfacePtr *) a; virInterfacePtr *ib =3D (virInterfacePtr *) b; @@ -281,9 +283,10 @@ virshInterfaceListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->ifaces && list->nifaces) - qsort(list->ifaces, list->nifaces, - sizeof(*list->ifaces), virshInterfaceSorter); + if (list->ifaces && list->nifaces) { + g_qsort_with_data(list->ifaces, list->nifaces, + sizeof(*list->ifaces), virshInterfaceSorter, NUL= L); + } =20 /* truncate the list if filter simulation deleted entries */ if (deleted) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 998e7e15e3..68c7543863 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -791,7 +791,9 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshNetworkSorter(const void *a, const void *b) +virshNetworkSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNetworkPtr *na =3D (virNetworkPtr *) a; virNetworkPtr *nb =3D (virNetworkPtr *) b; @@ -982,9 +984,10 @@ virshNetworkListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->nets && list->nnets) - qsort(list->nets, list->nnets, - sizeof(*list->nets), virshNetworkSorter); + if (list->nets && list->nnets) { + g_qsort_with_data(list->nets, list->nnets, + sizeof(*list->nets), virshNetworkSorter, NULL); + } =20 /* truncate the list if filter simulation deleted entries */ if (deleted) @@ -1801,7 +1804,9 @@ static const vshCmdOptDef opts_network_dhcp_leases[] = =3D { }; =20 static int -virshNetworkDHCPLeaseSorter(const void *a, const void *b) +virshNetworkDHCPLeaseSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNetworkDHCPLeasePtr *lease1 =3D (virNetworkDHCPLeasePtr *) a; virNetworkDHCPLeasePtr *lease2 =3D (virNetworkDHCPLeasePtr *) b; @@ -1840,7 +1845,8 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) } =20 /* Sort the list according to MAC Address/IAID */ - qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter); + g_qsort_with_data(leases, nleases, + sizeof(*leases), virshNetworkDHCPLeaseSorter, NULL); =20 table =3D vshTableNew(_("Expiry Time"), _("MAC address"), _("Protocol"= ), _("IP address"), _("Hostname"), _("Client ID or DU= ID"), @@ -2068,7 +2074,9 @@ cmdNetworkPortDelete(vshControl *ctl, const vshCmd *c= md) =20 =20 static int -virshNetworkPortSorter(const void *a, const void *b) +virshNetworkPortSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNetworkPortPtr *na =3D (virNetworkPortPtr *) a; virNetworkPortPtr *nb =3D (virNetworkPortPtr *) b; @@ -2129,9 +2137,10 @@ virshNetworkPortListCollect(vshControl *ctl, list->nports =3D ret; =20 /* sort the list */ - if (list->ports && list->nports) - qsort(list->ports, list->nports, - sizeof(*list->ports), virshNetworkPortSorter); + if (list->ports && list->nports) { + g_qsort_with_data(list->ports, list->nports, + sizeof(*list->ports), virshNetworkPortSorter, NU= LL); + } =20 success =3D true; =20 diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 82b8fb44fc..fb38fd7fcc 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -183,7 +183,9 @@ virshNodeListLookup(int devid, bool parent, void *opaqu= e) } =20 static int -virshNodeDeviceSorter(const void *a, const void *b) +virshNodeDeviceSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNodeDevicePtr *na =3D (virNodeDevicePtr *) a; virNodeDevicePtr *nb =3D (virNodeDevicePtr *) b; @@ -334,9 +336,10 @@ virshNodeDeviceListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->devices && list->ndevices) - qsort(list->devices, list->ndevices, - sizeof(*list->devices), virshNodeDeviceSorter); + if (list->devices && list->ndevices) { + g_qsort_with_data(list->devices, list->ndevices, + sizeof(*list->devices), virshNodeDeviceSorter, N= ULL); + } =20 /* truncate the list if filter simulation deleted entries */ if (deleted) diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 92b2b7b3bc..fa52d020e4 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -220,7 +220,9 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshNWFilterSorter(const void *a, const void *b) +virshNWFilterSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNWFilterPtr *fa =3D (virNWFilterPtr *) a; virNWFilterPtr *fb =3D (virNWFilterPtr *) b; @@ -323,9 +325,10 @@ virshNWFilterListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->filters && list->nfilters) - qsort(list->filters, list->nfilters, - sizeof(*list->filters), virshNWFilterSorter); + if (list->filters && list->nfilters) { + g_qsort_with_data(list->filters, list->nfilters, + sizeof(*list->filters), virshNWFilterSorter, NUL= L); + } =20 /* truncate the list for not found filter objects */ if (deleted) @@ -644,7 +647,9 @@ cmdNWFilterBindingDumpXML(vshControl *ctl, const vshCmd= *cmd) =20 =20 static int -virshNWFilterBindingSorter(const void *a, const void *b) +virshNWFilterBindingSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virNWFilterBindingPtr *fa =3D (virNWFilterBindingPtr *) a; virNWFilterBindingPtr *fb =3D (virNWFilterBindingPtr *) b; @@ -702,9 +707,10 @@ virshNWFilterBindingListCollect(vshControl *ctl, list->nbindings =3D ret; =20 /* sort the list */ - if (list->bindings && list->nbindings > 1) - qsort(list->bindings, list->nbindings, - sizeof(*list->bindings), virshNWFilterBindingSorter); + if (list->bindings && list->nbindings > 1) { + g_qsort_with_data(list->bindings, list->nbindings, + sizeof(*list->bindings), virshNWFilterBindingSor= ter, NULL); + } =20 success =3D true; =20 diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 5803530d79..36f00cf643 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -814,7 +814,9 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshStoragePoolSorter(const void *a, const void *b) +virshStoragePoolSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virStoragePoolPtr *pa =3D (virStoragePoolPtr *) a; virStoragePoolPtr *pb =3D (virStoragePoolPtr *) b; @@ -1005,9 +1007,10 @@ virshStoragePoolListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->pools && list->npools) - qsort(list->pools, list->npools, - sizeof(*list->pools), virshStoragePoolSorter); + if (list->pools && list->npools) { + g_qsort_with_data(list->pools, list->npools, + sizeof(*list->pools), virshStoragePoolSorter, NU= LL); + } =20 /* truncate the list if filter simulation deleted entries */ if (deleted) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 694e16c5cb..e54712ba78 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -399,7 +399,9 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshSecretSorter(const void *a, const void *b) +virshSecretSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virSecretPtr *sa =3D (virSecretPtr *) a; virSecretPtr *sb =3D (virSecretPtr *) b; @@ -509,9 +511,10 @@ virshSecretListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->secrets && list->nsecrets) - qsort(list->secrets, list->nsecrets, - sizeof(*list->secrets), virshSecretSorter); + if (list->secrets && list->nsecrets) { + g_qsort_with_data(list->secrets, list->nsecrets, + sizeof(*list->secrets), virshSecretSorter, NULL); + } =20 /* truncate the list for not found secret objects */ if (deleted) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index c85258c09a..2049872322 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -982,7 +982,9 @@ virshSnapshotListFree(struct virshSnapshotList *snaplis= t) } =20 static int -virshSnapSorter(const void *a, const void *b) +virshSnapSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { const struct virshSnap *sa =3D a; const struct virshSnap *sb =3D b; @@ -1232,7 +1234,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, * still in list. We mark known descendants by clearing * snaps[i].parents. Sorry, this is O(n^3) - hope your * hierarchy isn't huge. XXX Is it worth making O(n^2 log n) - * by using qsort and bsearch? */ + * by using g_qsort_with_data and bsearch? */ if (start_index < 0) { vshError(ctl, _("snapshot %1$s disappeared from list"), fromna= me); goto cleanup; @@ -1312,8 +1314,8 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, } if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL) && snaplist->snaps && snaplist->nsnaps) { - qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), - virshSnapSorter); + g_qsort_with_data(snaplist->snaps, snaplist->nsnaps, + sizeof(*snaplist->snaps), virshSnapSorter, NULL); } snaplist->nsnaps -=3D deleted; =20 diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 9a2b21d3f3..329ca3a66c 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -1200,7 +1200,9 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) } =20 static int -virshStorageVolSorter(const void *a, const void *b) +virshStorageVolSorter(const void *a, + const void *b, + void *opaque G_GNUC_UNUSED) { virStorageVolPtr *va =3D (virStorageVolPtr *) a; virStorageVolPtr *vb =3D (virStorageVolPtr *) b; @@ -1299,8 +1301,10 @@ virshStorageVolListCollect(vshControl *ctl, =20 finished: /* sort the list */ - if (list->vols && list->nvols) - qsort(list->vols, list->nvols, sizeof(*list->vols), virshStorageVo= lSorter); + if (list->vols && list->nvols) { + g_qsort_with_data(list->vols, list->nvols, + sizeof(*list->vols), virshStorageVolSorter, NULL= ); + } =20 if (deleted) VIR_SHRINK_N(list->vols, list->nvols, deleted); --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Mon May 13 17:51:14 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1700742240912790.343336504522; Thu, 23 Nov 2023 04:24:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D12FC18C1; Thu, 23 Nov 2023 07:23:59 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 690D71919; Thu, 23 Nov 2023 07:19:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1DB4417EC; Thu, 23 Nov 2023 07:19:07 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 43BA817F5 for ; Thu, 23 Nov 2023 07:19:06 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-Tfpgr1AsPzyvke7XRohlQA-1; Thu, 23 Nov 2023 07:19:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F245811E7B for ; Thu, 23 Nov 2023 12:19:04 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE75A2166B26 for ; Thu, 23 Nov 2023 12:19:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Tfpgr1AsPzyvke7XRohlQA-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 3/3] syntax-check: Forbid use of qsort() Date: Thu, 23 Nov 2023 13:19:00 +0100 Message-ID: <8d18b0674a6584db9975480d778be2bfd6130914.1700741882.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SFSJVGQKOONTATB3OB5VKHMAFYRI4F2N X-Message-ID-Hash: SFSJVGQKOONTATB3OB5VKHMAFYRI4F2N X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1700742241107100001 Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- build-aux/syntax-check.mk | 7 +++++++ tools/nss/libvirt_nss.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 309ca0c29a..462bff72f8 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -248,6 +248,13 @@ sc_prohibit_canonicalize_file_name: halt=3D'use virFileCanonicalizePath() instead of canonicalize_file_name()= ' \ $(_sc_search_regexp) =20 +# qsort from glibc is unstable. Use g_qsort_with_data from glib instead +sc_prohibit_qsort: + @prohibit=3D'\' \ diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ff6ea1d373..d79a00a1b0 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -71,7 +71,8 @@ sortAddr(leaseAddress *tmpAddress, size_t ntmpAddress) { if (tmpAddress) - qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSo= rter); + qsort(tmpAddress, ntmpAddress, /* exempt from syntax-check */ + sizeof(*tmpAddress), leaseAddressSorter); } =20 =20 --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org