Hi Eric,
Wow! What a large change.
> 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).
You handled locale.h, stddef.h, stdio.h, stdlib.h, string.h, unistd.h, wchar.h,
but time.h also should define NULL, according to POSIX.
> Here's what I'm testing
I got some "malformed patch" errors while applying the patch. Due to wrapped
lines such as
@@ -12,6 +12,11 @@ The macros @code{EXIT_SUCCESS} and @code{EXIT_FAILURE} are
not defined on
Can you produce your patches without the diff -p option, or attach them
rather than include them in the mail?
> 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.
The vasnprintf code is also shared with libintl, which does not use any
replacements of <locale.h>, <stdlib.h>, nor <stddef.h>. Therefore defining
wchar_t for all platforms, while possible, would not simplify vasnprintf.
> 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>).
But the uClibc users are stubborn in their refusal to use wchar_t in some
builds.
> Any other comments, while I continue with my testing?
In unistd.in.h:32 I would change the comment
/* NetBSD 5.0 mis-defines NULL. */
to
/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
In m4/locale_h.m4 it's a waste of configure time to check for the include_next
support of locale.h if it's not going to be replaced. I would keep doing
gl_CHECK_NEXT_HEADERS([locale.h])
conditionally.
Likewise for m4/stddef_h.m4 and m4/wchar.m4.
In m4/stddef_h.m4, I would not use a conditional expression inside an array
subscript. C requires an array subscript to be an integer constant
expression, but some older C standard did not mention that conditional
expressions consisting of integer constant expressions are integer constant
expressions. Therefore it's safer only to play with + - * /.
The replacement value that you are using for NULL is not right for C++. In
ISO C++ <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf>
sections 18.1.(3) and footnote 188 say
"The macro NULL is an implementation-defined C++ null pointer constant in
this International Standard (4.10).
Possible definitions include 0 and 0L, but not (void*)0."
A test case is
============================= foo.cc ============================
#include <stddef.h>
struct A {
int foo (void *);
int foo (char *);
int foo (int);
int foo (long);
};
int A::foo (void *) { return 1; }
int A::foo (char *) { return 2; }
int A::foo (int) { return 0; }
int A::foo (long) { return 0; }
int verify_size[2 * (sizeof NULL == sizeof (void *)) - 1];
int main ()
{
A x;
return x.foo(NULL);
}
// g++ 3.1...4.3.3 all call A::foo (int).
// The openSUSE g++ 4.3.1 calls A::foo (long).
==================================================================
Find attached the changes that I would apply on top of yours (to be
applied with "patch -p0", as always).
--- doc/posix-headers/locale.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/locale.texi 2009-08-13 10:52:43.000000000 +0200
@@ -12,7 +12,7 @@
mingw.
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/stddef.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/stddef.texi 2009-08-13 10:52:42.000000000 +0200
@@ -11,7 +11,7 @@
Some old platforms fail to provide @code{wchar_t}.
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/stdio.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/stdio.texi 2009-08-13 10:52:42.000000000 +0200
@@ -8,7 +8,7 @@
Portability problems fixed by Gnulib:
@itemize
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/stdlib.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/stdlib.texi 2009-08-13 10:52:43.000000000 +0200
@@ -14,7 +14,7 @@
The macro @code{EXIT_FAILURE} is incorrectly defined on Tandem/NSK.
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/string.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/string.texi 2009-08-13 10:52:43.000000000 +0200
@@ -8,7 +8,7 @@
Portability problems fixed by Gnulib:
@itemize
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/unistd.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/unistd.texi 2009-08-13 10:52:43.000000000 +0200
@@ -20,7 +20,7 @@
mingw.
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- doc/posix-headers/wchar.texi.orig 2009-08-13 11:38:25.000000000 +0200
+++ doc/posix-headers/wchar.texi 2009-08-13 10:52:43.000000000 +0200
@@ -18,7 +18,7 @@
IRIX 5.3.
@item
-Some platforms provide @code{NULL} that cannot be used in arbitrary
+Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
expressions:
NetBSD 5.0
@end itemize
--- lib/stddef.in.h.orig 2009-08-13 11:38:25.000000000 +0200
+++ lib/stddef.in.h 2009-08-13 11:36:41.000000000 +0200
@@ -60,7 +60,20 @@
/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
#if @REPLACE_NULL@
# undef NULL
-# define NULL ((void *) 0)
+# ifdef __cplusplus
+ /* ISO C++ says that the macro NULL must expand to an integer constant
+ expression, hence '((void *) 0)' is not allowed in C++. */
+# if __GNUG__ >= 3
+ /* GNU C++ has a __null macro that behaves like an integer ('int' or
+ 'long') but has the same size as a pointer. Use that, to avoid
+ warnings. */
+# define NULL __null
+# else
+# define NULL 0L
+# endif
+# else
+# define NULL ((void *) 0)
+# endif
#endif
/* Some platforms lack wchar_t. */
--- lib/unistd.in.h.orig 2009-08-13 11:38:25.000000000 +0200
+++ lib/unistd.in.h 2009-08-13 10:53:28.000000000 +0200
@@ -29,7 +29,7 @@
#ifndef _GL_UNISTD_H
#define _GL_UNISTD_H
-/* NetBSD 5.0 mis-defines NULL. */
+/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
#include <stddef.h>
/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
--- m4/locale_h.m4.orig 2009-08-13 11:38:25.000000000 +0200
+++ m4/locale_h.m4 2009-08-13 10:55:25.000000000 +0200
@@ -12,17 +12,15 @@
int x = LC_MESSAGES;], [],
[gl_cv_header_working_locale_h=yes],
[gl_cv_header_working_locale_h=no])])
- if test $gl_cv_header_working_locale_h = yes; then
- LOCALE_H=
- else
- 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
+
+ if test $gl_cv_header_working_locale_h = yes && test -z "$STDDEF_H"; then
+ LOCALE_H=
+ else
+ gl_CHECK_NEXT_HEADERS([locale.h])
LOCALE_H=locale.h
fi
+ AC_SUBST([LOCALE_H])
])
--- m4/stddef_h.m4.orig 2009-08-13 11:38:25.000000000 +0200
+++ m4/stddef_h.m4 2009-08-13 11:01:22.000000000 +0200
@@ -9,7 +9,6 @@
[
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
@@ -17,7 +16,7 @@
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];
+ int test[2 * (sizeof NULL == sizeof (void *)) -1];
]])],
[gl_cv_decl_null_works=yes],
[gl_cv_decl_null_works=no])])
@@ -25,6 +24,9 @@
REPLACE_NULL=1
STDDEF_H=stddef.h
fi
+ if test -n "$STDDEF_H"; then
+ gl_CHECK_NEXT_HEADERS([stddef.h])
+ fi
])
AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
--- m4/wchar.m4.orig 2009-08-13 11:38:25.000000000 +0200
+++ m4/wchar.m4 2009-08-13 11:06:19.000000000 +0200
@@ -27,7 +27,10 @@
fi
AC_SUBST([HAVE_WINT_T])
- if test $gl_cv_header_wchar_h_standalone != yes || test $gt_cv_c_wint_t != yes; then
+ dnl If <stddef.h> is replaced, then <wchar.h> must also be replaced.
+ AC_REQUIRE([gl_STDDEF_H])
+
+ if test $gl_cv_header_wchar_h_standalone != yes || test $gt_cv_c_wint_t != yes || test -n "$STDDEF_H"; then
WCHAR_H=wchar.h
fi
@@ -42,12 +45,8 @@
HAVE_WCHAR_H=0
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
+ if test -n "$WCHAR_H"; then
+ gl_CHECK_NEXT_HEADERS([wchar.h])
fi
])