mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Markus Wichmann <nullplan@gmx.net>
Cc: musl@lists.openwall.com,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [musl] [PATCH] search: provide twalk_r()
Date: Fri, 10 Feb 2023 16:05:30 -0500	[thread overview]
Message-ID: <20230210210529.GC4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <20230210200745.GB1903@voyager>

On Fri, Feb 10, 2023 at 09:07:45PM +0100, Markus Wichmann wrote:
> On Fri, Feb 10, 2023 at 09:35:02AM +0100, Bartosz Golaszewski wrote:
> > These extensions exist for a reason - they are simply useful and
> > programs do use them out in the wild. twalk() on its own is brain-dead
> > and only useful to small programs that can afford to have global
> > variables. If you have a variable that tries to hold no global
> > context, then the possibility to pass data to the walk callback is
> > absolutely required. This is a general problem with those hash-map,
> > binary tree etc. APIs in POSIX - they don't seem to be designed very
> > well. GNU extensions try to address some of those issues.
> >
> 
> Nobody ever questioned the usefulness of these extensions. The reason
> musl does not adopt them immediately, however, is that without
> standardization, we run the risk of future incompatible standardization,
> and therefore, musl developing quirks. musl cannot remove functionality
> without breaking ABI, and it is currently not built in a way that would
> allow breaking ABI. So only new functions can be added, old ones must
> remain indefinitely.
> 
> Case in point: qsort_r(). The BSDs had added another function of the
> same name, but with different argument order (both in the qsort_r() call
> and the comparison function). If musl had added the BSD version and then
> the GNU version got standardized, musl would have had to work around the
> incompatibility somehow. Or else be stuck with the nonconforming
> version.
> 
> I concur that the hashmap and binary tree POSIX APIs are not very well
> designed, and I question the need for them in libc. Personally, I would
> counsel against using anything from search.h, especially when it does
> not fit your needs. That would also get rid of the requirement for libc
> to support nonstandard APIs. I mean, we are talking about data
> structures here; it is not like there is a shortage of libraries
> implementing these for all sorts of things.

Thanks for explaining this. If folks want twalk_r, a good way to
approach this would be either proposing the GNU-compatible function to
one or more of the BSDs, or proposing it directly to POSIX with the
glibc implementation as precedent.

However, in the short term, an easy way to get it without any support
from the standard library is as a wraper for twalk, something like
this (untested):

static _Thread_local void (*action)(const void *, VISIT, void *);
static _Thread_local void *data;

static void wrapper_action(const void *p, VISIT v, int d)
{
	action(p, v, data);
}

void twalk_r(const void *root, void (*action)(const void *, VISIT, void *), void *data)
{
	void (*old_action)(const void *, VISIT, void *) = action;
	void *old_data = data;
	twalk(root, wrapper_action);
	data = old_data;
	action = old_action;
}

The only reason I put the old_* stuff there is to make it reentrant,
in case the action function itself calls twalk_r.

Rich

      reply	other threads:[~2023-02-10 21:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-09 20:43 Bartosz Golaszewski
2023-02-09 21:16 ` Rich Felker
2023-02-09 21:26   ` Bartosz Golaszewski
2023-02-10  2:18     ` Khem Raj
2023-02-10  8:35       ` Bartosz Golaszewski
2023-02-10 20:07         ` Markus Wichmann
2023-02-10 21:05           ` Rich Felker [this message]

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=20230210210529.GC4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=musl@lists.openwall.com \
    --cc=nullplan@gmx.net \
    /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).