[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: definition of NULL
From: |
Eric Blake |
Subject: |
Re: definition of NULL |
Date: |
Wed, 12 Aug 2009 21:45:26 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Bruno Haible <bruno <at> clisp.org> writes:
> > I argue that NetBSD's definition of NULL is thus buggy
>
> Regarding POSIX, with XSH 2.1.2.(1), you are probably right.
>
> > we should add gnulib check and config.h workaround for it.
>
> The definition of NULL is a particularly thorny area, because so many headers
> use it and so many headers define it. I don't think it's worth the trouble -
It wasn't _that_ much trouble. There are only 7 headers defined by POSIX to
define NULL, and we already provide gnulib overrides for 6 of the 7 (the only
one lacking was stddef.h itself). Here's what I'm testing; so far, I've proven
that it works on cygwin whether I use the system-standard stddef.h or a
manually-hacked one that simulates the broken NetBSD definition. I still
intend to test it on an actual NetBSD machine, to see if I missed anything
obvious. The weirdest part is that newlib provides the header <unistd.h> and
uses the idiom:
#define __need_wint_t
#include <stddef.h>
to define wint_t, while gcc provides the header <stddef.h> and intentionally
honors __need_wint_t to provide wint_t even though it should not normally be
exposed by an isolated include of <stddef.h>. (Non-idempotent include files
are certainly interesting to debug; it took me lots of #warnings to figure out
was going on).
This patch does not do anything about the *printf family basing a lot of code
on HAVE_WCHAR_T; one idea is that we could make the *printf-posix versions of
these macros require the stddef module and then blindly assume that wchar_t is
available (although this means updating several #if checks), while leaving the
simpler *printf versions at the mercy of the platform's (lack of) wchar_t. For
that matter, I couldn't find any definitive documentation of a modern platform
that lacks wchar_t (just that some uclibc builds lack <wchar.h>).
Any other comments, while I continue with my testing?
From: Eric Blake <address@hidden>
Date: Wed, 12 Aug 2009 08:31:14 -0600
Subject: [PATCH 1/2] Revert "Avoid compilation error on NetBSD 5.0."
This reverts commit b8521e81e705f88784e7a6709bcd6c5a3ea440e0.
---
tests/test-locale.c | 2 +-
tests/test-stdio.c | 2 +-
tests/test-stdlib.c | 2 +-
tests/test-string.c | 2 +-
tests/test-unistd.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/test-locale.c b/tests/test-locale.c
index 60a50a7..625cc43 100644
--- a/tests/test-locale.c
+++ b/tests/test-locale.c
@@ -35,7 +35,7 @@ int a[] =
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
-verify (sizeof (NULL) == sizeof (void *));
+verify (sizeof NULL == sizeof (void *));
int
main ()
diff --git a/tests/test-stdio.c b/tests/test-stdio.c
index 41299e2..dcfe38d 100644
--- a/tests/test-stdio.c
+++ b/tests/test-stdio.c
@@ -27,7 +27,7 @@ int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
-verify (sizeof (NULL) == sizeof (void *));
+verify (sizeof NULL == sizeof (void *));
int
main ()
diff --git a/tests/test-stdlib.c b/tests/test-stdlib.c
index 711cfa6..ae46ba1 100644
--- a/tests/test-stdlib.c
+++ b/tests/test-stdlib.c
@@ -26,7 +26,7 @@ int exitcode;
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
-verify (sizeof (NULL) == sizeof (void *));
+verify (sizeof NULL == sizeof (void *));
int
main ()
diff --git a/tests/test-string.c b/tests/test-string.c
index 688d0d3..fe53cd9 100644
--- a/tests/test-string.c
+++ b/tests/test-string.c
@@ -24,7 +24,7 @@
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
-verify (sizeof (NULL) == sizeof (void *));
+verify (sizeof NULL == sizeof (void *));
int
main ()
diff --git a/tests/test-unistd.c b/tests/test-unistd.c
index e0b8291..129367b 100644
--- a/tests/test-unistd.c
+++ b/tests/test-unistd.c
@@ -24,7 +24,7 @@
/* Check that NULL can be passed through varargs as a pointer type,
per POSIX 2008. */
-verify (sizeof (NULL) == sizeof (void *));
+verify (sizeof NULL == sizeof (void *));
/* Check that the various SEEK_* macros are defined. */
int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
---
1.6.3.2
From: Eric Blake <address@hidden>
Date: Wed, 12 Aug 2009 10:23:03 -0600
Subject: [PATCH 2/2] Fix NetBSD 5.0 NULL bug, rather than working around it.
* tests/test-locale.c: Revert previous patch.
* tests/test-stdio.c: Likewise.
* tests/test-stdlib.c: Likewise.
* tests/test-string.c: Likewise.
* tests/test-unistd.c: Likewise.
* modules/wchar-tests (Depends-on): Add verify.
* tests/test-wchar.c: Test for NULL compliance.
* modules/locale (Depends-on): Add stddef.
* modules/stdio (Depends-on): Likewise.
* modules/stdlib (Depends-on): Likewise.
* modules/string (Depends-on): Likewise.
* modules/unistd (Depends-on): Likewise.
* modules/wchar (Depends-on): Likewise.
* lib/locale.in.h (includes): Use <stddef.h> to fix NULL.
* lib/stdlib.in.h (includes): Likewise.
* lib/string.in.h (includes): Likewise.
* lib/unistd.in.h (includes): Likewise.
* m4/locale_h.m4 (gl_LOCALE_H): Replace locale.h if stddef.h was
replaced.
* m4/wchar.m4 (gl_WCHAR_H): Likewise.
* m4/stddef_h.m4: New file.
* modules/stddef: Likewise.
* lib/stddef.in.h: Likewise.
* modules/stddef-tests: Likewise.
* tests/test-stddef.c: Likewise.
* MODULES.html.sh (Basic types <stddef.h>): Mention new module.
* doc/posix-headers/stddef.texi (stddef.h): Document the bug.
* doc/posix-headers/locale.texi (locale.h): Likewise.
* doc/posix-headers/stdio.texi (stdio.h): Likewise.
* doc/posix-headers/stdlib.texi (stdlib.h): Likewise.
* doc/posix-headers/string.texi (string.h): Likewise.
* doc/posix-headers/unistd.texi (unistd.h): Likewise.
* doc/posix-headers/wchar.texi (wchar.h): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 37 +++++++++++++++++++++
MODULES.html.sh | 10 ++++++
doc/posix-headers/locale.texi | 5 +++
doc/posix-headers/stddef.texi | 9 ++++-
doc/posix-headers/stdio.texi | 4 ++
doc/posix-headers/stdlib.texi | 5 +++
doc/posix-headers/string.texi | 4 ++
doc/posix-headers/unistd.texi | 5 +++
doc/posix-headers/wchar.texi | 5 +++
lib/locale.in.h | 5 ++-
lib/stddef.in.h | 73 +++++++++++++++++++++++++++++++++++++++++
lib/stdlib.in.h | 2 +
lib/string.in.h | 2 +
lib/unistd.in.h | 5 ++-
m4/locale_h.m4 | 12 +++++--
m4/stddef_h.m4 | 43 ++++++++++++++++++++++++
m4/wchar.m4 | 8 ++++-
modules/locale | 1 +
modules/stddef | 40 ++++++++++++++++++++++
modules/stddef-tests | 14 ++++++++
modules/stdio | 1 +
modules/stdlib | 1 +
modules/string | 1 +
modules/unistd | 1 +
modules/wchar | 1 +
modules/wchar-tests | 1 +
tests/test-stddef.c | 38 +++++++++++++++++++++
tests/test-wchar.c | 8 ++++-
28 files changed, 332 insertions(+), 9 deletions(-)
create mode 100644 lib/stddef.in.h
create mode 100644 m4/stddef_h.m4
create mode 100644 modules/stddef
create mode 100644 modules/stddef-tests
create mode 100644 tests/test-stddef.c
diff --git a/ChangeLog b/ChangeLog
index eb3a690..c5ad9e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2009-08-12 Eric Blake <address@hidden>
+
+ Fix NetBSD 5.0 NULL bug, rather than working around it.
+ * tests/test-locale.c: Revert previous patch.
+ * tests/test-stdio.c: Likewise.
+ * tests/test-stdlib.c: Likewise.
+ * tests/test-string.c: Likewise.
+ * tests/test-unistd.c: Likewise.
+ * modules/wchar-tests (Depends-on): Add verify.
+ * tests/test-wchar.c: Test for NULL compliance.
+ * modules/locale (Depends-on): Add stddef.
+ * modules/stdio (Depends-on): Likewise.
+ * modules/stdlib (Depends-on): Likewise.
+ * modules/string (Depends-on): Likewise.
+ * modules/unistd (Depends-on): Likewise.
+ * modules/wchar (Depends-on): Likewise.
+ * lib/locale.in.h (includes): Use <stddef.h> to fix NULL.
+ * lib/stdlib.in.h (includes): Likewise.
+ * lib/string.in.h (includes): Likewise.
+ * lib/unistd.in.h (includes): Likewise.
+ * m4/locale_h.m4 (gl_LOCALE_H): Replace locale.h if stddef.h was
+ replaced.
+ * m4/wchar.m4 (gl_WCHAR_H): Likewise.
+ * m4/stddef_h.m4: New file.
+ * modules/stddef: Likewise.
+ * lib/stddef.in.h: Likewise.
+ * modules/stddef-tests: Likewise.
+ * tests/test-stddef.c: Likewise.
+ * MODULES.html.sh (Basic types <stddef.h>): Mention new module.
+ * doc/posix-headers/stddef.texi (stddef.h): Document the bug.
+ * doc/posix-headers/locale.texi (locale.h): Likewise.
+ * doc/posix-headers/stdio.texi (stdio.h): Likewise.
+ * doc/posix-headers/stdlib.texi (stdlib.h): Likewise.
+ * doc/posix-headers/string.texi (string.h): Likewise.
+ * doc/posix-headers/unistd.texi (unistd.h): Likewise.
+ * doc/posix-headers/wchar.texi (wchar.h): Likewise.
+
2009-08-12 Bruno Haible <address@hidden>
* m4/getopt.m4 (gl_REPLACE_GETOPT): New macro, was called
diff --git a/MODULES.html.sh b/MODULES.html.sh
index ce5ac80..298b655 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2032,6 +2032,16 @@ func_all_modules ()
func_module stdbool
func_end_table
+ element="Basic types <stddef.h>"
+ element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"`
+ func_section_wrap isoc_sup_stddef
+ func_wrap H3
+ func_echo "$element"
+
+ func_begin_table
+ func_module stddef
+ func_end_table
+
element="Integer types and values <stdint.h>"
element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"`
func_section_wrap isoc_sup_stdint
diff --git a/doc/posix-headers/locale.texi b/doc/posix-headers/locale.texi
index a65da97..b0a5869 100644
--- a/doc/posix-headers/locale.texi
+++ b/doc/posix-headers/locale.texi
@@ -10,6 +10,11 @@ Portability problems fixed by Gnulib:
@item
The definition of @samp{LC_MESSAGES} is missing on some platforms:
mingw.
+
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/stddef.texi b/doc/posix-headers/stddef.texi
index df28e0f..531254b 100644
--- a/doc/posix-headers/stddef.texi
+++ b/doc/posix-headers/stddef.texi
@@ -3,10 +3,17 @@
POSIX specification: @url{http://www.opengroup.org/susv3xbd/stddef.h.html}
-Gnulib module: ---
+Gnulib module: stddef
Portability problems fixed by Gnulib:
@itemize
address@hidden
+Some old platforms fail to provide @code{wchar_t}.
+
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/stdio.texi b/doc/posix-headers/stdio.texi
index c413616..7c53f7f 100644
--- a/doc/posix-headers/stdio.texi
+++ b/doc/posix-headers/stdio.texi
@@ -7,6 +7,10 @@ Gnulib module: stdio
Portability problems fixed by Gnulib:
@itemize
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/stdlib.texi b/doc/posix-headers/stdlib.texi
index 2fc6280..881b378 100644
--- a/doc/posix-headers/stdlib.texi
+++ b/doc/posix-headers/stdlib.texi
@@ -12,6 +12,11 @@ The macros @code{EXIT_SUCCESS} and @code{EXIT_FAILURE} are
not defined on
some platforms.
@item
The macro @code{EXIT_FAILURE} is incorrectly defined on Tandem/NSK.
+
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/string.texi b/doc/posix-headers/string.texi
index 42f67b9..cef3ead 100644
--- a/doc/posix-headers/string.texi
+++ b/doc/posix-headers/string.texi
@@ -7,6 +7,10 @@ Gnulib module: string
Portability problems fixed by Gnulib:
@itemize
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/unistd.texi b/doc/posix-headers/unistd.texi
index 855eefb..de3c117 100644
--- a/doc/posix-headers/unistd.texi
+++ b/doc/posix-headers/unistd.texi
@@ -18,6 +18,11 @@ OS/2 EMX, mingw.
@item
The @code{_exit} function is not declared in this file on some platforms:
mingw.
+
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-headers/wchar.texi b/doc/posix-headers/wchar.texi
index bdd8232..cafe2b3 100644
--- a/doc/posix-headers/wchar.texi
+++ b/doc/posix-headers/wchar.texi
@@ -16,6 +16,11 @@ OSF/1 with Desktop Toolkit C, BSD/OS 4.0.1.
@item
The type @code{wint_t} and macro @code{WEOF} are missing on some platforms:
IRIX 5.3.
+
address@hidden
+Some platforms provide @code{NULL} that cannot be used in arbitrary
+expressions:
+NetBSD 5.0
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/lib/locale.in.h b/lib/locale.in.h
index 10629f6..0557c9f 100644
--- a/lib/locale.in.h
+++ b/lib/locale.in.h
@@ -1,5 +1,5 @@
/* A POSIX <locale.h>.
- Copyright (C) 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,6 +26,9 @@
#ifndef _GL_LOCALE_H
#define _GL_LOCALE_H
+/* NetBSD 5.0 mis-defines NULL. */
+#include <stddef.h>
+
/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
On systems that don't define it, use the same value as GNU libintl. */
#if !defined LC_MESSAGES
diff --git a/lib/stddef.in.h b/lib/stddef.in.h
new file mode 100644
index 0000000..adac321
--- /dev/null
+++ b/lib/stddef.in.h
@@ -0,0 +1,73 @@
+/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
+
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Eric Blake. */
+
+/*
+ * POSIX 2008 <stddef.h> for platforms that have issues.
+ * <http://www.opengroup.org/susv3xbd/stddef.h.html>
+ */
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
+
+#if defined __need_wchar_t || defined __need_size_t \
+ || defined __need_ptrdiff_t || defined __need_NULL \
+ || defined __need_wint_t
+/* Special invocation convention inside gcc header files. In
+ particular, gcc provides a version of <stddef.h> that blindly
+ redefines NULL even when __need_wint_t was defined, even though
+ wint_t is not normally provided by <stddef.h>. Hence, we must
+ remember if special invocation has ever been used to obtain wint_t,
+ in which case we need to clean up NULL yet again. */
+
+# if !(defined _GL_STDDEF_H && defined _GL_STDDEF_WINT_T)
+# ifdef __need_wint_t
+# undef _GL_STDDEF_H
+# define _GL_STDDEF_WINT_T
+# endif
+# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
+# endif
+
+#else
+/* Normal invocation convention. */
+
+# ifndef _GL_STDDEF_H
+
+/* The include_next requires a split double-inclusion guard. */
+
+# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
+
+# ifndef _GL_STDDEF_H
+# define _GL_STDDEF_H
+
+/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
+#if @REPLACE_NULL@
+# undef NULL
+# define NULL ((void *) 0)
+#endif
+
+/* Some platforms lack wchar_t. */
+#if address@hidden@
+# define wchar_t int
+#endif
+
+# endif /* _GL_STDDEF_H */
+# endif /* _GL_STDDEF_H */
+#endif /* __need_XXX */
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index f99767f..c7c8e8f 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -35,6 +35,8 @@
#ifndef _GL_STDLIB_H
#define _GL_STDLIB_H
+/* NetBSD 5.0 mis-defines NULL. */
+#include <stddef.h>
/* Solaris declares getloadavg() in <sys/loadavg.h>. */
#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
diff --git a/lib/string.in.h b/lib/string.in.h
index 9f98b0d..8eaeeb8 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -28,6 +28,8 @@
#ifndef _GL_STRING_H
#define _GL_STRING_H
+/* NetBSD 5.0 mis-defines NULL. */
+#include <stddef.h>
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 5cad6c8..98fdd46 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -29,6 +29,9 @@
#ifndef _GL_UNISTD_H
#define _GL_UNISTD_H
+/* NetBSD 5.0 mis-defines NULL. */
+#include <stddef.h>
+
/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
# include <stdio.h>
@@ -375,7 +378,6 @@ extern int gethostname(char *name, size_t len);
See <http://www.opengroup.org/susv3xsh/getlogin.html>.
*/
# if address@hidden@
-# include <stddef.h>
extern int getlogin_r (char *name, size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
@@ -536,7 +538,6 @@ extern int link (const char *path1, const char *path2);
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/readlink.html>. */
# if address@hidden@
-# include <stddef.h>
extern int readlink (const char *file, char *buf, size_t bufsize);
# endif
#elif defined GNULIB_POSIXCHECK
diff --git a/m4/locale_h.m4 b/m4/locale_h.m4
index 2bf5abc..c8a7091 100644
--- a/m4/locale_h.m4
+++ b/m4/locale_h.m4
@@ -1,5 +1,5 @@
-# locale_h.m4 serial 2
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# locale_h.m4 serial 3
+dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -15,8 +15,14 @@ int x = LC_MESSAGES;], [],
if test $gl_cv_header_working_locale_h = yes; then
LOCALE_H=
else
- gl_CHECK_NEXT_HEADERS([locale.h])
LOCALE_H=locale.h
fi
AC_SUBST([LOCALE_H])
+ gl_CHECK_NEXT_HEADERS([locale.h])
+
+ dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
+ AC_REQUIRE([gl_STDDEF_H])
+ if test -n "$STDDEF_H"; then
+ LOCALE_H=locale.h
+ fi
])
diff --git a/m4/stddef_h.m4 b/m4/stddef_h.m4
new file mode 100644
index 0000000..a107a5c
--- /dev/null
+++ b/m4/stddef_h.m4
@@ -0,0 +1,43 @@
+dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues.
+# stddef_h.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_STDDEF_H],
+[
+ AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
+ AC_REQUIRE([gt_TYPE_WCHAR_T])
+ gl_CHECK_NEXT_HEADERS([stddef.h])
+ if test $gt_cv_c_wchar_t = no; then
+ HAVE_WCHAR_T=0
+ STDDEF_H=stddef.h
+ fi
+ AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
+ [gl_cv_decl_null_works],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
+ int test[sizeof NULL == sizeof (void *) ? 1 : -1];
+]])],
+ [gl_cv_decl_null_works=yes],
+ [gl_cv_decl_null_works=no])])
+ if test $gl_cv_decl_null_works = no; then
+ REPLACE_NULL=1
+ STDDEF_H=stddef.h
+ fi
+])
+
+AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
+ GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_STDDEF_H_DEFAULTS],
+[
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
+ HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])
+ STDDEF_H=''; AC_SUBST([STDDEF_H])
+])
diff --git a/m4/wchar.m4 b/m4/wchar.m4
index 2e52a82..4e32f85 100644
--- a/m4/wchar.m4
+++ b/m4/wchar.m4
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is
preserved.
dnl Written by Eric Blake.
-# wchar.m4 serial 23
+# wchar.m4 serial 24
AC_DEFUN([gl_WCHAR_H],
[
@@ -43,6 +43,12 @@ wchar_t w;]],
fi
AC_SUBST([HAVE_WCHAR_H])
gl_CHECK_NEXT_HEADERS([wchar.h])
+
+ dnl If <stddef.h> is replaced, then <wchar.h> must also be replaced.
+ AC_REQUIRE([gl_STDDEF_H])
+ if test -n "$STDDEF_H"; then
+ WCHAR_H=wchar.h
+ fi
])
dnl Unconditionally enables the replacement of <wchar.h>.
diff --git a/modules/locale b/modules/locale
index d15d5d3..0afc5cb 100644
--- a/modules/locale
+++ b/modules/locale
@@ -7,6 +7,7 @@ m4/locale_h.m4
Depends-on:
include_next
+stddef
configure.ac:
gl_LOCALE_H
diff --git a/modules/stddef b/modules/stddef
new file mode 100644
index 0000000..c68e00b
--- /dev/null
+++ b/modules/stddef
@@ -0,0 +1,40 @@
+Description:
+A <stddef.h> that works around platform issues.
+
+Files:
+lib/stddef.in.h
+m4/stddef_h.m4
+m4/wchar_t.m4
+
+Depends-on:
+include_next
+
+configure.ac:
+gl_STDDEF_H
+
+Makefile.am:
+BUILT_SOURCES += $(STDDEF_H)
+
+# We need the following in order to create <stddef.h> when the system
+# doesn't have one that works with the given compiler.
+stddef.h: stddef.in.h
+ rm -f address@hidden $@
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
+ -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
+ -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
+ < $(srcdir)/stddef.in.h; \
+ } > address@hidden
+ mv address@hidden $@
+MOSTLYCLEANFILES += stddef.h stddef.h-t
+
+Include:
+#include <stddef.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/stddef-tests b/modules/stddef-tests
new file mode 100644
index 0000000..04be2f5
--- /dev/null
+++ b/modules/stddef-tests
@@ -0,0 +1,14 @@
+Files:
+tests/test-stddef.c
+
+Depends-on:
+verify
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-stddef
+check_PROGRAMS += test-stddef
+
+License:
+LGPL
diff --git a/modules/stdio b/modules/stdio
index 87308a6..cf88630 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -10,6 +10,7 @@ Depends-on:
include_next
link-warning
raise
+stddef
configure.ac:
gl_STDIO_H
diff --git a/modules/stdlib b/modules/stdlib
index fda3372..49798ad 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -9,6 +9,7 @@ Depends-on:
include_next
link-warning
unistd
+stddef
stdint
configure.ac:
diff --git a/modules/string b/modules/string
index b2c802c..738deeb 100644
--- a/modules/string
+++ b/modules/string
@@ -9,6 +9,7 @@ Depends-on:
extensions
include_next
link-warning
+stddef
configure.ac:
gl_HEADER_STRING_H
diff --git a/modules/unistd b/modules/unistd
index 06f77c5..5977bf9 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -8,6 +8,7 @@ lib/unistd.in.h
Depends-on:
include_next
link-warning
+stddef
configure.ac:
gl_UNISTD_H
diff --git a/modules/wchar b/modules/wchar
index f46150c..d4dad6c 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -9,6 +9,7 @@ m4/wint_t.m4
Depends-on:
include_next
link-warning
+stddef
configure.ac:
gl_WCHAR_H
diff --git a/modules/wchar-tests b/modules/wchar-tests
index 9a55d2b..dac05ec 100644
--- a/modules/wchar-tests
+++ b/modules/wchar-tests
@@ -2,6 +2,7 @@ Files:
tests/test-wchar.c
Depends-on:
+verify
configure.ac:
diff --git a/tests/test-stddef.c b/tests/test-stddef.c
new file mode 100644
index 0000000..f848498
--- /dev/null
+++ b/tests/test-stddef.c
@@ -0,0 +1,38 @@
+/* Test of <stddef.h> substitute.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake <address@hidden>, 2009. */
+
+#include <config.h>
+
+#include <stddef.h>
+
+#include "verify.h"
+
+/* Check that appropriate types are defined. */
+wchar_t a = 'c';
+ptrdiff_t b = 1;
+size_t c = 2;
+
+/* Check that NULL can be passed through varargs as a pointer type,
+ per POSIX 2008. */
+verify (sizeof NULL == sizeof (void *));
+
+int
+main ()
+{
+ return 0;
+}
diff --git a/tests/test-wchar.c b/tests/test-wchar.c
index 19da7d9..2866068 100644
--- a/tests/test-wchar.c
+++ b/tests/test-wchar.c
@@ -1,5 +1,5 @@
/* Test of <wchar.h> substitute.
- Copyright (C) 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,10 +20,16 @@
#include <wchar.h>
+#include "verify.h"
+
/* Check that the types wchar_t and wint_t are defined. */
wchar_t a = 'c';
wint_t b = 'x';
+/* Check that NULL can be passed through varargs as a pointer type,
+ per POSIX 2008. */
+verify (sizeof NULL == sizeof (void *));
+
int
main ()
{
--
1.6.3.2