]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stdlib: support including stdlib.h from config.h
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2024 21:41:04 +0000 (13:41 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2024 21:41:24 +0000 (13:41 -0800)
Emacs <config.h> includes <stdlib.h> in some situations, causing
problems on macOS as described by Eli Zaretskii in:
https://lists.gnu.org/r/emacs-devel/2024-12/msg00923.html
Although this usage is not recommended, it is easier to support
it for POSIX-required headers, than to fix Emacs.
* doc/extern-inline.texi (extern inline): Document the Emacs problem.
* lib/endian.c, lib/math.c, lib/stdbit.c, lib/stdlib.c:
* lib/sys_socket.c, lib/unistd.c, lib/wctype-h.c:
Define #define _GL_..._INLINE to _GL_EXTERN_INLINE
before including <config.h>, not merely before including
the .h file that defines the inline function.

ChangeLog
doc/extern-inline.texi
lib/endian.c
lib/math.c
lib/stdbit.c
lib/stdlib.c
lib/sys_socket.c
lib/unistd.c
lib/wctype-h.c

index 38b95c2479e877e67526cb0ad6c35dff28c398db..2a60634dc077095620d0ce9be5d55cfe390559fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-12-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stdlib: support including stdlib.h from config.h
+       Emacs <config.h> includes <stdlib.h> in some situations, causing
+       problems on macOS as described by Eli Zaretskii in:
+       https://lists.gnu.org/r/emacs-devel/2024-12/msg00923.html
+       Although this usage is not recommended, it is easier to support
+       it for POSIX-required headers, than to fix Emacs.
+       * doc/extern-inline.texi (extern inline): Document the Emacs problem.
+       * lib/endian.c, lib/math.c, lib/stdbit.c, lib/stdlib.c:
+       * lib/sys_socket.c, lib/unistd.c, lib/wctype-h.c:
+       Define #define _GL_..._INLINE to _GL_EXTERN_INLINE
+       before including <config.h>, not merely before including
+       the .h file that defines the inline function.
+
 2024-12-24  Bruno Haible  <bruno@clisp.org>
 
        setlocale: Fix a buffer overflow check (mistake in yesterday's commit).
index 3ebc39cdac67e97894e1bfce32a19c279bd6ebee..87b76f6451b78d732c82879a440e24b769e2afca 100644 (file)
@@ -67,8 +67,8 @@ and @file{aaa.c} can do this:
 
 @example
 /* aaa.c */
-#include <config.h>
 #define AAA_INLINE _GL_EXTERN_INLINE
+#include <config.h>
 #include <aaa.h>
 @end example
 
@@ -83,6 +83,12 @@ inline} so they suffer from code bloat, but they are not mainline
 platforms and will die out eventually.
 
 In this coding idiom,
+the compilation unit should define @code{AAA_INLINE} before
+including the @file{aaa.h} header that conditionally defines it.
+In the unusual and not-recommended case where @file{config.h}
+itself includes @file{aaa.h}, the compilation unit should
+define @code{AAA_INLINE} before including @file{config.h},
+not merely before including @file{aaa.h}.  Also,
 you need one @code{AAA_INLINE}-like macro per compilation unit,
 not one per header file.
 In other words, if the header file @file{aaa.h} defines functions
index 3e7e56f523d54521cd5319a761e706abea6916a5..089f5f7825e83e33b578ed7d554d2f514ff078bf 100644 (file)
@@ -17,7 +17,7 @@
 
 /* Written by Collin Funk.  */
 
+#define _GL_ENDIAN_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_ENDIAN_INLINE _GL_EXTERN_INLINE
 #include <endian.h>
index 78da4d4acad4c0c395a837754586263d1f07c59e..ade0d2657c56c0e57ba882418abe59ef79d7cbd9 100644 (file)
@@ -15,8 +15,8 @@
    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/>.  */
 
+#define _GL_MATH_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_MATH_INLINE _GL_EXTERN_INLINE
 #include <math.h>
 typedef int dummy;
index 4801e74d2819f76f84278297d7df0a638fa7ff09..b9c52698e91ffcf8fccc7ac67b214d546e7348fd 100644 (file)
@@ -17,7 +17,7 @@
 
 /* Written by Paul Eggert.  */
 
+#define _GL_STDBIT_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_STDBIT_INLINE _GL_EXTERN_INLINE
 #include <stdbit.h>
index 521d64627dc5da8e6e861fc6005e83ea30e9004d..6f70fa4bbda7b5d2a5526aa92dd6c7817243d15c 100644 (file)
@@ -15,7 +15,7 @@
    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/>.  */
 
+#define _GL_STDLIB_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_STDLIB_INLINE _GL_EXTERN_INLINE
 #include <stdlib.h>
index 672d3aace6dcffb50a237879348df270a19bfe1d..49d2122da54b6d52bdcab186058f7f47effa61bb 100644 (file)
@@ -15,8 +15,8 @@
    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/>.  */
 
+#define _GL_SYS_SOCKET_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_SYS_SOCKET_INLINE _GL_EXTERN_INLINE
 #include <sys/socket.h>
 typedef int dummy;
index f3b3f7bd2fe7ebbe5660d2d1266b7701ceb17aaa..b25112eb91e280ba238c411118ee67b964b29bae 100644 (file)
@@ -15,8 +15,8 @@
    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/>.  */
 
+#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
 #include <unistd.h>
 typedef int dummy;
index 7e4ff13a71f4f62dd548679cbea535a3a061e9d2..a1f020fd6518503577083b282f89a601518f4206 100644 (file)
@@ -17,7 +17,7 @@
 
 /* Normally this would be wctype.c, but that name's already taken.  */
 
+#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE
 #include <config.h>
 
-#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE
 #include <wctype.h>