mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Balazs Kezes <rlblaster@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: qsort_r or qsort_s in musl
Date: Mon, 3 Sep 2018 18:53:16 -0400	[thread overview]
Message-ID: <20180903225316.GY1878@brightrain.aerifal.cx> (raw)
In-Reply-To: <20180903205705.GA7639@localhost>

On Mon, Sep 03, 2018 at 09:57:05PM +0100, Balazs Kezes wrote:
> Hi!
> 
> I can find a lot of discussions on the web around qsort_r and the pain that musl
> lacks it but I can't find any official word on this from musl devs. If there is
> one, could src/stdlib/qsort.c contain a pointer to it?
> 
> Are there any plans having one of them in musl? I'd prefer qsort_r since that
> would provide greater compatibility with glibc. I even found patches for it:
> https://gist.github.com/izabera/e68927258ad2d29a1586bad276fabcab
> https://github.com/esmil/musl/commit/194f9cf93da8ae62491b7386edf481ea8565ae4e
> 
> qsort_r differs between bsd/osx and glibc though:
> https://sourceware.org/ml/libc-alpha/2008-12/msg00003.html
> 
> The argument for qsort_s is that it is in the C11 standard as an optional
> feature and has similar interface as glibc's qsort_r.
> 
> To avoid choosing sides it could be even qsort_musl for all I care. I could then
> use preprocessor to choose the right version. I know there are many workarounds:
> global variables, thread local variables, copy pasting and changing qsort from
> musl in my own source tree, using glibc. None of them feel right.
> 
> Any thoughts?

I think it's been discussed several times before, probably on the
list, but I can summarize the state of the topic as far as I'm aware:

qsort_s, as part of Annex K, is pretty much rejected as long as it's
neither a mandatory part of C, nor widely used by applications. If we
were to implement it, it should conform to the standard function by
that name, which would entail doing lots of wrong things like
introducing "runtime constraint handler" as global state. It's ironic
that the function whose purported purpose is being thread-safe with
regard to context ends up introducing mechanisms that make it
fundamentally thread-unsafe.

qsort_r was at first rejected because of the conflicting definitions
-- existence of same-named interfaces with different semantics or
signatures is one of the big criteria for exclusion of nonstandard
extensions in musl. However, from the FreeBSD side at least there
seems to be interest in dropping their version and agreeing upon a
standard aligned with glibc's version, for the sake of POSIX:

http://austingroupbugs.net/view.php?id=900

I'm not aware of any further progress on the issue, but if it becomes
clear that POSIX is either going to standardize a version that agree
with the GNU definition, or commit to not standardizing any that
conflict, I think the level of consensus we have so far is sufficient
to consider doing it.

In the mean time, you can always implement a thin wrapper defining
qsort_r in terms of qsort, using thread-local storage for the context
argument.

Rich


  reply	other threads:[~2018-09-03 22:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 20:57 Balazs Kezes
2018-09-03 22:53 ` Rich Felker [this message]
2018-09-04  7:41   ` Balazs Kezes
2018-09-04 14:48     ` Eric Blake
2018-09-04 15:18       ` Rich Felker
2018-09-04 15:45         ` Balazs Kezes
2018-09-04 15:45         ` Leah Neukirchen
2018-09-04 16:13           ` Rich Felker
2018-09-10 17:27   ` Ed Maste
2018-09-10 17:43     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903225316.GY1878@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=rlblaster@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).