[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] stdlib: support including stdlib.h from config.h
From: |
Paul Eggert |
Subject: |
[PATCH] stdlib: support including stdlib.h from config.h |
Date: |
Tue, 24 Dec 2024 13:41:56 -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 | 15 +++++++++++++++
doc/extern-inline.texi | 8 +++++++-
lib/endian.c | 2 +-
lib/math.c | 2 +-
lib/stdbit.c | 2 +-
lib/stdlib.c | 2 +-
lib/sys_socket.c | 2 +-
lib/unistd.c | 2 +-
lib/wctype-h.c | 2 +-
9 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 38b95c2479..2a60634dc0 100644
--- 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).
diff --git a/doc/extern-inline.texi b/doc/extern-inline.texi
index 3ebc39cdac..87b76f6451 100644
--- a/doc/extern-inline.texi
+++ b/doc/extern-inline.texi
@@ -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
diff --git a/lib/endian.c b/lib/endian.c
index 3e7e56f523..089f5f7825 100644
--- a/lib/endian.c
+++ b/lib/endian.c
@@ -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>
diff --git a/lib/math.c b/lib/math.c
index 78da4d4aca..ade0d2657c 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -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;
diff --git a/lib/stdbit.c b/lib/stdbit.c
index 4801e74d28..b9c52698e9 100644
--- a/lib/stdbit.c
+++ b/lib/stdbit.c
@@ -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>
diff --git a/lib/stdlib.c b/lib/stdlib.c
index 521d64627d..6f70fa4bbd 100644
--- a/lib/stdlib.c
+++ b/lib/stdlib.c
@@ -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>
diff --git a/lib/sys_socket.c b/lib/sys_socket.c
index 672d3aace6..49d2122da5 100644
--- a/lib/sys_socket.c
+++ b/lib/sys_socket.c
@@ -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;
diff --git a/lib/unistd.c b/lib/unistd.c
index f3b3f7bd2f..b25112eb91 100644
--- a/lib/unistd.c
+++ b/lib/unistd.c
@@ -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;
diff --git a/lib/wctype-h.c b/lib/wctype-h.c
index 7e4ff13a71..a1f020fd65 100644
--- a/lib/wctype-h.c
+++ b/lib/wctype-h.c
@@ -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>
--
2.45.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] stdlib: support including stdlib.h from config.h,
Paul Eggert <=