libvirt/src/nwfilter
Michal Privoznik cfcbba4c2b lib: Replace qsort() with g_qsort_with_data()
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=glibc.git;a=commitdiff;h=03bf8357e8291857a435afcc3048e0b697b6cc04
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-11-24 09:53:14 +01:00
..
xml example: add ipv6 filters examples 2020-11-04 17:21:45 +01:00
meson.build systemd: Set service_extra_in/socket_extra_in everywhere 2023-10-25 12:19:32 +02:00
nwfilter_dhcpsnoop.c nwfilter: Move error messages onto a single line 2023-09-04 09:35:36 +02:00
nwfilter_dhcpsnoop.h lib: Drop internal virXXXPtr typedefs 2021-04-13 17:00:38 +02:00
nwfilter_driver.c nwfilter: Update format strings in translated messages 2023-04-01 11:40:33 +02:00
nwfilter_driver.h nwfilter: Remove unused includes 2022-06-07 16:04:21 +02:00
nwfilter_ebiptables_driver.c lib: Replace qsort() with g_qsort_with_data() 2023-11-24 09:53:14 +01:00
nwfilter_ebiptables_driver.h src/nwfilter: use #pragma once in headers 2019-06-19 17:12:30 +02:00
nwfilter_gentech_driver.c lib: use struct zero initializer instead of memset 2023-08-03 16:41:19 +02:00
nwfilter_gentech_driver.h nwfilter: Remove unused includes 2022-06-07 16:04:21 +02:00
nwfilter_learnipaddr.c nwfilter: Move error messages onto a single line 2023-09-04 09:35:36 +02:00
nwfilter_learnipaddr.h nwfilter: Remove unused includes 2022-06-07 16:04:21 +02:00
nwfilter_tech_driver.h lib: Drop internal virXXXPtr typedefs 2021-04-13 17:00:38 +02:00
virtnwfilterd.init.in configure: Provide OpenRC scripts for sub-daemons 2019-12-16 10:11:22 +01:00
virtnwfilterd.service.extra.in systemd: Set service_extra_in/socket_extra_in everywhere 2023-10-25 12:19:32 +02:00
virtnwfilterd.socket.extra.in systemd: Set service_extra_in/socket_extra_in everywhere 2023-10-25 12:19:32 +02:00