2023-05-30 Paul Eggert <eggert@cs.ucla.edu>
+ error: don’t call ‘exit’
+ Let the underlying functions call ‘exit’, instead of having the
+ Gnulib replacement macros do it. Use ‘unreachable’ to tell the
+ compiler that those functions exit when the status is nonzero.
+ This saves a function call.
+ * lib/error.in.h: Include stddef.h, not stdlib.h.
+ (__gl_error_call): Rely on the function to exit, using
+ ‘unreachable’ to tell the compiler that the function does not return.
+ * modules/error (Depends-on): Add stddef.
+
error: don’t evaluate status arg twice
This avoids potential issues if the first argument has a side effect.
* lib/error.in.h (__gl_error_call): New macro, which evaluates its
#error "Please include config.h first."
#endif
+/* Get 'unreachable'. */
+#include <stddef.h>
+
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */
#include <stdio.h>
-/* Get exit(). */
-#include <stdlib.h>
-
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
#if GNULIB_VFPRINTF_POSIX
# define __gl_error_call(function, status, ...) \
({ \
int const __errstatus = status; \
- (function) (0, __VA_ARGS__); \
- __errstatus != 0 ? exit (__errstatus) : (void) 0; \
+ (function) (__errstatus, __VA_ARGS__); \
+ __errstatus != 0 ? unreachable () : (void) 0; \
})
#else
# define __gl_error_call(function, status, ...) \