bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, epsilon-devel@gnu.org,
	Paul Eggert <eggert@cs.ucla.edu>
Cc: poke-devel@gnu.org
Subject: Re: Keep config.h idempotent
Date: Thu, 26 Jan 2023 00:48:48 +0100	[thread overview]
Message-ID: <418965623.aKRZZrHkil@nimes> (raw)
In-Reply-To: <66302311-fded-4403-525e-cfa2a9cfde64@cs.ucla.edu>

Hi Paul, Luca,

Paul Eggert wrote:
> It appears to me that poke 2.90.1's "#define 
> returns_nonnull" is not a problem, because the Gnulib code never uses 
> that identifier. Instead, the Gnulib code does this:
> 
> #if _GL_HAS_ATTRIBUTE (returns_nonnull)
> 
> which uses this macro:
> 
> # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
> 
> and so has the same effect as this:
> 
> #if __has_attribute (__returns_nonnull__)
> 
> regardless of what returns_nonnull was defined to, because C doesn't 
> macro-expand immediate operands of ##.

Indeed, poke does

  # define returns_nonnull      /* Nothing. */
  # define __returns_nonnull__  /* Nothing. */

and, as you say, it's the latter that is troublesome.

Luca, while it would be good to remove this invalid
  # define __returns_nonnull__  /* Nothing. */
line in the long run, it's OK to leave it in for poke-3.0, since the Gnulib
patch that I committed, plus the gnulib submodule update that José committed,
will prevent the trouble.

> Isn't there still a problem with something like the following, even with 
> the latest Gnulib?
> 
>     #define __returns_nonnull__
>     #include <config.h>
> 
> That is, it seems to me that the real problem here is a collision with 
> poke's "#define __returns_nonnull__" before <config.h>, not with 
> including <config.h> twice.

True. Although it's rare that people will want to make such macro definitions
before '#include <config.h>'. It's more likely that packages do such macro
definitions deep in their own code, when it's seen after the first include of
<config.h>.

> I don't think Gnulib should imply to users that it's OK 
> to include <config.h> twice. That's an uncommon practice and is a recipe 
> for trouble, as too many programs do fun stuff in their configure.ac 
> that Gnulib has no control over. Instead, we should clarify Gnulib's 
> documentation to say that compilation units should include <config.h> 
> first, before including anything else, and should not include <config.h> 
> later.

I disagree for two reasons:

  * <config.h> is an invention of Autoconf, and the Autoconf documentation
    does not state that <config.h> should only be included once. It only
    states that it should be included before the first system header file,
    otherwise definitions such as '#define _GNU_SOURCE 1' are ineffective.
    Gnulib, as a user of Autoconf, should not cause additional constraints.
    In other words, <config.h> was meant to be idempotent from the beginning,
    and it's only a Gnulib glitch that caused it to be not idempotent in
    the face of some invalid "#define __returns_nonnull__".

  * Additional constraints for the user means more complicated maintenance.
    If developers have to distinguish .c files which are compiled as a
    separate compilation unit from .c files which are only included, their
    code becomes more fragile.
    And yes, some people do #include .c files, see e.g.
    gnulib/lib/strtoul.c or
    https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/libasprintf/lib-asprintf.c;h=c2fe4ed161f2716df3d5a96890154aa55c0fc656;hb=eb83efc3b58d690d444da0b82c3ecf36a54f28ac
    It's better to continue to give them the freedom of adding
    '#include <config.h>' where they feel a need for.
    The simpler the documentation is on this topic, the easier Gnulib can
    be used, and the fewer people curse Gnulib and Autoconf.

    In the case that you mentioned, that the developer has added AH_VERBATIM
    invocations in their configure.ac and that it destroys the idempotency
    of <config.h>, that's entirely their problem. The Gnulib or Autoconf
    documentation should not force practices on the user that are entirely
    in the domain / responsibility of the user.

> Obviously we can't make Gnulib immune to arbitrary #defines of reserved 
> names. This is not to say that we shouldn't accommodate GNU poke, just 
> that it's not clear that the cure is right here, as a general rule.

The change that I committed had two effects:
  (1) Work around that arbitrary #define.
  (2) Allow to override these _GL_ATTRIBUTE_* macros for the scope of a
      compilation unit. We already have seen the need to override
      _GL_ARG_NONNULL at compilation-unit scope. Similar needs may arise
      for any _GL_ATTRIBUTE_* macro.

So, I'd like to keep this commit, even if the rationale (1) is debatable.

Bruno





  reply	other threads:[~2023-01-25 23:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 14:05 Keep config.h idempotent Bruno Haible
2023-01-25 22:00 ` Paul Eggert
2023-01-25 23:48   ` Bruno Haible [this message]
2023-01-26  4:17     ` Paul Eggert

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=418965623.aKRZZrHkil@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=epsilon-devel@gnu.org \
    --cc=poke-devel@gnu.org \
    /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).