bug-gnulib
[Top][All Lists]
Advanced

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

error-h: Make less fragile


From: Bruno Haible
Subject: error-h: Make less fragile
Date: Sat, 11 Feb 2023 21:16:56 +0100

The error.in.h that I created on 2023-01-12 is a bit fragile:
  - It depends on the fact that a platform which has error() also has
    error_at_line() and vice versa. Namely, if system has one of the two
    functions but not the other, the 'error-h' module will arrange to
    generate an error.h, but this file will lack the declaration of the
    function that the system already has.
  - If a platform has <error.h> and adds additional declarations to it,
    gnulib's error.h will shadow it.

This patch fixes these problems.


2023-02-11  Bruno Haible  <bruno@clisp.org>

        error-h: Make less fragile.
        * lib/error.in.h: Use #include_next if the system has an <error.h>. Use
        a split double-inclusion guard.
        * m4/error_h.m4 (gl_ERROR_H): Invoke gl_CHECK_NEXT_HEADERS. Set
        HAVE_ERROR_H.
        * modules/error-h (Makefile.am): Substitute GUARD_PREFIX, HAVE_ERROR_H,
        INCLUDE_NEXT, PRAGMA_SYSTEM_HEADER, NEXT_ERROR_H.

diff --git a/lib/error.in.h b/lib/error.in.h
index bfddb011c0..dcb49d1608 100644
--- a/lib/error.in.h
+++ b/lib/error.in.h
@@ -16,8 +16,19 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
-#ifndef _ERROR_H
-#define _ERROR_H 1
+#ifndef _@GUARD_PREFIX@_ERROR_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_ERROR_H@
+# @INCLUDE_NEXT@ @NEXT_ERROR_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_ERROR_H
+#define _@GUARD_PREFIX@_ERROR_H
 
 /* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM.  
*/
 #include <stdio.h>
@@ -103,4 +114,5 @@ extern int error_one_per_line;
 }
 #endif
 
-#endif /* error.h */
+#endif /* _@GUARD_PREFIX@_ERROR_H */
+#endif /* _@GUARD_PREFIX@_ERROR_H */
diff --git a/m4/error_h.m4 b/m4/error_h.m4
index 15b5112309..f38e4ead13 100644
--- a/m4/error_h.m4
+++ b/m4/error_h.m4
@@ -1,4 +1,4 @@
-# error_h.m4 serial 2
+# error_h.m4 serial 3
 dnl Copyright (C) 1996-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,6 +11,14 @@ AC_DEFUN_ONCE([gl_ERROR_H],
 [
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
+  gl_CHECK_NEXT_HEADERS([error.h])
+  if test $ac_cv_header_error_h = yes; then
+    HAVE_ERROR_H=1
+  else
+    HAVE_ERROR_H=0
+  fi
+  AC_SUBST([HAVE_ERROR_H])
+
   REPLACE_ERROR=0
 
   gl_CHECK_FUNCS_ANDROID([error], [[#include <error.h>]])
diff --git a/modules/error-h b/modules/error-h
index 80bc06194b..a84d8e2705 100644
--- a/modules/error-h
+++ b/modules/error-h
@@ -23,6 +23,11 @@ if GL_GENERATE_ERROR_H
 error.h: error.in.h $(top_builddir)/config.status $(CXXDEFS_H)
 @NMD@  $(AM_V_GEN)$(MKDIR_P) '%reldir%'
        $(gl_V_at)$(SED_HEADER_STDOUT) \
+             -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+             -e 's|@''HAVE_ERROR_H''@|$(HAVE_ERROR_H)|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''NEXT_ERROR_H''@|$(NEXT_ERROR_H)|g' \
              -e 's|@''HAVE_ERROR''@|$(HAVE_ERROR)|g' \
              -e 's|@''HAVE_ERROR_AT_LINE''@|$(HAVE_ERROR_AT_LINE)|g' \
              -e 's|@''REPLACE_ERROR''@|$(REPLACE_ERROR)|g' \






reply via email to

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