error: don’t call ‘exit’
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 May 2023 21:38:41 +0000 (14:38 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 May 2023 21:39:27 +0000 (14:39 -0700)
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.

ChangeLog
lib/error.in.h
modules/error

index f70eeef893cb383d0098982111f30d46be97abc5..cd427e981908a3ae217b1a105b60d827a646903e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 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
index a5f49e41437a0f2d82aeaa5a888020afbcda58dc..ecb19818c8305b4cfadbf5a1d465dab3d1d7f3c7 100644 (file)
  #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
@@ -53,8 +53,8 @@
 # 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, ...) \
index 63317f1821b68ba4cd9b0dae6c7dc263179dbb91..88d567674aa1e5b6a65b0a5481e3abd79e2ada4a 100644 (file)
@@ -7,6 +7,7 @@ m4/error.m4
 
 Depends-on:
 error-h
+stddef
 stdio
 getprogname
 strerror        [test $COMPILE_ERROR_C = 1]