From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28892 invoked from network); 24 Sep 2021 00:18:34 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 24 Sep 2021 00:18:34 -0000 Received: (qmail 1816 invoked by uid 550); 24 Sep 2021 00:18:32 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1785 invoked from network); 24 Sep 2021 00:18:31 -0000 Date: Thu, 23 Sep 2021 20:18:19 -0400 From: Rich Felker To: =?utf-8?B?w4lyaWNv?= Nogueira Cc: musl@lists.openwall.com Message-ID: <20210924001819.GY13220@brightrain.aerifal.cx> References: <20210309210213.29539-1-ericonr@disroot.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210309210213.29539-1-ericonr@disroot.org> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH v3] add qsort_r and make qsort a wrapper around it On Tue, Mar 09, 2021 at 06:02:13PM -0300, Érico Nogueira wrote: > we make qsort a wrapper by providing a wrapper_cmp function that uses > the extra argument as a function pointer. should be optimized to a tail > call on most architectures, as long as it's built with > -fomit-frame-pointer, so the performance impact should be minimal. > > to keep the git history clean, for now qsort_r is implemented in qsort.c > and qsort is implemented in qsort_nr.c. qsort.c also received a few > trivial cleanups, including replacing (*cmp)() calls with cmp(). > qsort_nr.c contains only wrapper_cmp and qsort as a qsort_r wrapper > itself. > --- > > Following suggestions from IRC, as few changes as possible to the files, > a final clean up commit after this one would involve some git mv's (I > won't make a patch for it). Added weak_alias to force qsort to use > libc's qsort_r. > > If this can't be accepted due to the overhead on some archs (ppc, mips, > arm in some situations?), maybe we could revisit v2 of the patch? > > include/stdlib.h | 1 + > src/include/stdlib.h | 1 + > src/stdlib/qsort.c | 37 ++++++++++++++++++++----------------- > src/stdlib/qsort_nr.c | 14 ++++++++++++++ > 4 files changed, 36 insertions(+), 17 deletions(-) > create mode 100644 src/stdlib/qsort_nr.c > > diff --git a/include/stdlib.h b/include/stdlib.h > index b54a051f..0c0ced5f 100644 > --- a/include/stdlib.h > +++ b/include/stdlib.h > @@ -158,6 +158,7 @@ struct __locale_struct; > float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); > double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); > long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); > +void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); > #endif > [...] I'm merging this now with the change from only exposing it under _GNU_SOURCE to _BSD_SOURCE (default). As it's been accepted for POSIX future, I'd like to make it visible under baseline POSIX profile too, but I think that's a potentially riskier change that we can do later. As noted many times, the issue of GCC refusing to tail call on some archs is unfortunate, but we should get this fixed on the GCC side rather than doing ugly things trying to work around it. Rich