[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keep config.h idempotent

From: Bruno Haible
Subject: Re: Keep config.h idempotent
Date: Thu, 26 Jan 2023 00:48:48 +0100

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

> 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
    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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]