On 1/17/22 10:37, Reuben Thomas wrote:

"extern-inline" copies a stanza of code into
config.h. That code includes a test of the preprocessor macro
"__header_inline". That macro is defined in a system header on macOS.
When config.h is #included, no other header has been included.
Therefore, the symbol will never have been defined at the point where
it is tested in config.h. Therefore, the test will always fail.

Thanks for explaining more. That part of Gnulib was introduced in 2013:

https://lists.gnu.org/r/bug-gnulib/2013-11/msg00045.html

and as I vaguely recall was in response to this macports ticket:

https://trac.macports.org/ticket/41033

Apparently until now nobody tested that part of Gnulib to make sure that it omits the workaround on newer Apple platforms where the underlying bug has been fixed. (The underlying bug was that <ctype.h> defined static functions to implement isalpha etc. on OS X 10.8 and earlier in C, but the C standard does not allow this and using static functions broke some GNU code.)

Although the workaround still functions on current macOS, it's better to use proper inline functions when available so I installed the attached patch into Gnulib. Please give it a try.

I don't know whether the macOS world has moved on and nobody cares about older Apple releases with the ctype.h bug. If so, we could simplify Gnulib.
From 55d5e977bc9d05d67221c56a9c65e4bf11828793 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Mon, 17 Jan 2022 14:03:01 -0800
Subject: [PATCH] extern-inline: improve macOS port

* m4/extern-inline.m4 (gl_EXTERN_INLINE):
Define HAVE___HEADER_INLINE at configure-time, so that config.h
knows the workaround is not needed even though ctype.h has not yet
been included.  This lets the compiler use extern inline functions
on newer macOS platforms, instead of static inline.
Problem reported by Reuben Thomas in:
https://lists.gnu.org/r/bug-gnulib/2022-01/msg00130.html
---
 ChangeLog           | 11 +++++++++++
 m4/extern-inline.m4 | 19 +++++++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 33944f44b8..c5eebe4872 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-01-17  Paul Eggert  <egg...@cs.ucla.edu>
+
+	extern-inline: improve macOS port
+	* m4/extern-inline.m4 (gl_EXTERN_INLINE):
+	Define HAVE___HEADER_INLINE at configure-time, so that config.h
+	knows the workaround is not needed even though ctype.h has not yet
+	been included.  This lets the compiler use extern inline functions
+	on newer macOS platforms, instead of static inline.
+	Problem reported by Reuben Thomas in:
+	https://lists.gnu.org/r/bug-gnulib/2022-01/msg00130.html
+
 2022-01-17  Bruno Haible  <br...@clisp.org>
 
 	xstrtol: Trim dependencies.
diff --git a/m4/extern-inline.m4 b/m4/extern-inline.m4
index 2e914dbc07..8a12bddd57 100644
--- a/m4/extern-inline.m4
+++ b/m4/extern-inline.m4
@@ -7,7 +7,22 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_EXTERN_INLINE],
 [
-  AH_VERBATIM([extern_inline],
+  AC_CACHE_CHECK([whether ctype.h defines __header_inline],
+    [gl_cv_have___header_inline],
+    [AC_PREPROC_IFELSE(
+       [AC_LANG_SOURCE([[#include <ctype.h>
+                         #ifndef __header_inline
+                          #error "<ctype.h> does not define __header_inline"
+                         #endif
+                        ]])],
+       [gl_cv_have___header_inline=yes],
+       [gl_cv_have___header_inline=no])])
+  if test "$gl_cv_have___header_inline" = yes; then
+    AC_DEFINE([HAVE___HEADER_INLINE], [1],
+      [Define to 1 if ctype.h defines __header_inline.])
+  fi
+
+  AH_VERBATIM([HAVE___HEADER_INLINE_1],
 [/* Please see the Gnulib manual for how to use these macros.
 
    Suppress extern inline with HP-UX cc, as it appears to be broken; see
@@ -54,7 +69,7 @@ AC_DEFUN([gl_EXTERN_INLINE],
  */
 #if (((defined __APPLE__ && defined __MACH__) \
       || defined __DragonFly__ || defined __FreeBSD__) \
-     && (defined __header_inline \
+     && (defined HAVE___HEADER_INLINE \
          ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \
             && ! defined __clang__) \
          : ((! defined _DONT_USE_CTYPE_INLINE_ \
-- 
2.32.0

Reply via email to