bug-gnulib
[Top][All Lists]
Advanced

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

Re: error: Support the compiler's control flow analysis better (was: cop


From: Pádraig Brady
Subject: Re: error: Support the compiler's control flow analysis better (was: copy-file: Silence gcc warnings)
Date: Sun, 28 May 2023 13:31:39 +0100
User-agent: Mozilla Thunderbird

On 27/05/2023 21:53, Bruno Haible wrote:
Paul Eggert wrote:
Maybe by defining
error and error_at_line as inline functions

They're defined by glibc, no? The definitions might collide.

Yes, they are defined in glibc. Overriding functions without causing
collisions is our core expertise here :)

Also, I suppose the compiler might not inline them

Indeed, when I attempt to define
   void inline_error (int status, int errnum, const char *fmt, ...) { ... }
gcc does not inline the function, because it never inlines varargs functions.

An alternative would be to define
   void inline_error (int status, int errnum, const char *message) { ... }
and pass xasprintf (fmt, ...) as message argument. But the out-of-memory
handling or the LGPLv2+ / GPL license difference causes problems.

Fortunately, we don't need an inline function: Jim's die() implementation
shows that it can be done with just a macro definition.

The basic problem is that the old 'error' API doesn't mix well with
[[noreturn]] and the like. We could write a new function, "eexit" say,
that behaves like "error" except it never returns. (I chose the name
"eexit" so as to not mess up the indenting of existing code.)

Or we could just live with "die", as it works.

While this is definitely working, it has the problem that it pulls
developers away from the glibc API. Things are easier for developers
if they can use the symbols from POSIX or glibc rather than gnulib-
invented symbols. And that is possible here.

Also, the name 'die' has the problem that it may invoke traumatic
memories in some people (like the verb 'kill', but we can't get rid
of this one since it's standardized).

+# ifndef _GL_NO_INLINE_ERROR
+#  undef error
+#  define error(status, ...) \
+     ((rpl_error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
+# endif

We might need to cast STATUS to bool to avoid the
following failure from coreutils CI:

In file included from src/die.h:22,
                 from src/chroot.c:27:
src/chroot.c: In function 'main':
src/chroot.c:362:25: error: '?:'using integer constants in boolean context 
[-Werror=int-in-bool-context]
  362 |         error (warn ? 0 : EXIT_CANCELED, 0, "%s", (err));
./lib/error.h:422:33: note: in definition of macro 'error'
  422 |      ((error)(0, __VA_ARGS__), (status) ? exit (status) : (void)0)
      |                                 ^~~~~~


cheers,
Pádraig




reply via email to

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