From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, landfillbaby69@gmail.com
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: [PATCH] string, wchar: avoid some namespace pollution
Date: Wed, 08 Sep 2021 17:14:24 +0200 [thread overview]
Message-ID: <2891542.ucjEoNaZvj@omega> (raw)
In-Reply-To: <20210908005632.100624-1-eggert@cs.ucla.edu>
Hi Paul,
> * lib/string.in.h, lib/wchar.in.h:
> (free): Declare by hand instead of including stdlib.h.
This does not look right to me. There are two cases:
(A) REPLACE_FREE is 0. Then it is OK to declare it by hand, because gnulib
uses the system's free() function.
(B) REPLACE_FREE is 1. (This is the case on most non-glibc systems.)
Then gnulib's <stdlib.h> overrides 'free', by doing
#define free rpl_free
This means that the system's free() function is no longer visible after
some user code does '#include <stdlib.h>'.
If the user code now does
#include <string.h>
#include <stdlib.h>
then Gnulib's <string.h> will have declared that the result of strdup()
(or rpl_strdup()) must be deallocated through the system's free()
function. But the user cannot access this function any more. So he will
get a GCC (≥ 11) warning always!
This would be avoided if the user code does the includes in the opposite
order:
#include <stdlib.h>
#include <string.h>
because then, strdup() gets associated with 'rpl_free', not the system's
'free'. But the user is free to arrange their #includes in the order
they want (except for <config.h> which must always come first).
> This avoids some namespace pollution.
Yes, avoiding namespace pollution is desirable. But so far I don't see how
to make it coexist with correct rpl_free handling.
Bruno
next prev parent reply other threads:[~2021-09-08 15:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-08 0:56 [PATCH] string, wchar: avoid some namespace pollution Paul Eggert
2021-09-08 15:14 ` Bruno Haible [this message]
2021-09-08 15:40 ` Bruno Haible
2021-09-18 14:49 ` Bruno Haible
2021-09-23 14:44 ` Simon Josefsson via Gnulib discussion list
2022-01-04 12:22 ` Bruno Haible
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2891542.ucjEoNaZvj@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=eggert@cs.ucla.edu \
--cc=landfillbaby69@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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).