[Top][All Lists]

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

Re: Keep config.h idempotent

From: Paul Eggert
Subject: Re: Keep config.h idempotent
Date: Wed, 25 Jan 2023 14:00:21 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 2023-01-25 06:05, Bruno Haible wrote:
What happens, is that this compilation unit #includes <config.h> five times,
and somewhere between the first and the fifth inclusion, poke's code does
   #define returns_nonnull

This is their particular way of not emitting this particular GCC/clang
attribute, and is OK since 'returns_nonnull' is not a keyword and not a
token in the reserved namespace.

Is this diagnosis correct? 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 ##.

If I understand things correctly the problem with poke 2.90.1 wasn't its "#define returns_nonnull"; it was its "#define __returns_nonnull__", which indeed defines a token in the reserved namespace.

Hence this sequence

  #include <config.h>
  #define returns_nonnull
  #include <config.h>

is supposed to work fine.

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.

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.

More generally, 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.

reply via email to

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