-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Eric Blake on 3/20/2009 6:30 AM: >> $ find /usr/include | xargs grep sig_atomic_t >> /usr/include/sys/signal.h:typedef volatile int sig_atomic_t; > > Therefore, 'volatile sig_atomic_t' is not a bug, even if sig_atomic_t > already included volatile in its typedef. So the real solution here is to > enhance a .m4 test to detect your compiler's bug in refusing to compile > something that the C standard requires, and write a gnulib replacement > <sys/types.h> and/or <signal.h> that does:
<sys/types.h> would be the wrong place to add it; POSIX only requires its definition in <signal.h>. And that is fortunate, since gnulib has not yet tackled sys/types but does have signal.in.h already. Does the first patch solve things for you? $ git pull git://repo.or.cz/gnulib/ericb.git master I blindly chose int for sig_atomic_t. I suppose there is a chance that this is the wrong type for some platform, in which case test-stdint should catch that, and we can revisit how to coordinate between the signal and stdint which size and signedness to use for sig_atomic_t. Meanwhile, I added a signal-tests module as a basic smoke test as the second patch. Any review or objections before I push this to savannah? - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAknFh2AACgkQ84KuGfSFAYBcKQCeKgCDRgzUgE2dTDCVOj8qdYYV yWgAoJTTeYVY77azoLDN3rXjNbYZkh4X =0qai -----END PGP SIGNATURE-----
From b4cfd66ecb0093c466589ce4274bbdfc7178149c Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Sat, 21 Mar 2009 17:57:40 -0600 Subject: [PATCH 1/2] signal.h: always support 'volatile sig_atomic_t' * m4/signal_h.m4 (gl_SIGNAL_H): Check for AIX limitation. (gl_SIGNAL_H_DEFAULTS): Add a default. * modules/signal (Makefile.am): Substitute if needed. * lib/signal.in.h (sig_atomic_t): Redefine if needed, so that users can blindly add volatile. * doc/posix-headers/signal.texi (signal.h): Document it. Reported by Matthew Woehlke. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 11 +++++++++++ doc/posix-headers/signal.texi | 4 ++++ lib/signal.in.h | 11 ++++++++++- m4/signal_h.m4 | 12 ++++++++++-- modules/signal | 1 + 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a23101..d0030b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-03-21 Eric Blake <e...@byu.net> + + signal.h: always support 'volatile sig_atomic_t' + * m4/signal_h.m4 (gl_SIGNAL_H): Check for AIX limitation. + (gl_SIGNAL_H_DEFAULTS): Add a default. + * modules/signal (Makefile.am): Substitute if needed. + * lib/signal.in.h (sig_atomic_t): Redefine if needed, so that + users can blindly add volatile. + * doc/posix-headers/signal.texi (signal.h): Document it. + Reported by Matthew Woehlke. + 2009-03-20 Bruno Haible <br...@clisp.org> Make sockets.h self-contained. diff --git a/doc/posix-headers/signal.texi b/doc/posix-headers/signal.texi index 860a79d..05be64b 100644 --- a/doc/posix-headers/signal.texi +++ b/doc/posix-headers/signal.texi @@ -8,6 +8,10 @@ Gnulib module: signal Portability problems fixed by Gnulib: @itemize @item +...@code{volatile sig_atomic_t} is rejected by older compilers on some +platforms: +AIX. +...@item @code{sigset_t} is only declared in <sys/types.h> on some platforms: mingw. @item diff --git a/lib/signal.in.h b/lib/signal.in.h index 3c74fd8..5c42fe9 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -1,6 +1,6 @@ /* A GNU-like <signal.h>. - Copyright (C) 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2006-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 @@ -41,6 +41,15 @@ Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */ #include <sys/types.h> +/* On AIX, sig_atomic_t already includes volatile. C99 requires that + 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not. + Hence, redefine this to a non-volatile type as needed. */ +#if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@ +typedef int rpl_sig_atomic_t; +# undef sig_atomic_t +# define sig_atomic_t rpl_sig_atomic_t +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/m4/signal_h.m4 b/m4/signal_h.m4 index 4ac2e04..35534f4 100644 --- a/m4/signal_h.m4 +++ b/m4/signal_h.m4 @@ -1,5 +1,5 @@ -# signal_h.m4 serial 6 -dnl Copyright (C) 2007, 2008 Free Software Foundation, Inc. +# signal_h.m4 serial 7 +dnl Copyright (C) 2007, 2008, 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. @@ -8,6 +8,12 @@ AC_DEFUN([gl_SIGNAL_H], [ AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) gl_CHECK_NEXT_HEADERS([signal.h]) +dnl AIX declares sig_atomic_t to already include volatile, and C89 compilers +# then choke on 'volatile sig_atomic_t'. C99 requires that it compile. + AC_CHECK_TYPE([volatile sig_atomic_t], [], + [HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=0], [[ +#include <signal.h> + ]]) ]) AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR], @@ -29,4 +35,6 @@ AC_DEFUN([gl_SIGNAL_H_DEFAULTS], HAVE_SIGACTION=1; AC_SUBST([HAVE_SIGACTION]) HAVE_STRUCT_SIGACTION_SA_SIGACTION=1; AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION]) + HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1; + AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T]) ]) diff --git a/modules/signal b/modules/signal index 5afb24f..bfef96f 100644 --- a/modules/signal +++ b/modules/signal @@ -31,6 +31,7 @@ signal.h: signal.in.h -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \ -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \ -e 's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g' \ + -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/signal.in.h; \ } > $...@-t -- 1.6.1.2 From e0ac25e195cdf7f5e7dea00167eef7eec5e52fe7 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Sat, 21 Mar 2009 18:26:52 -0600 Subject: [PATCH 2/2] signal-tests: test previous patch * tests/test-signal.c: New file. * modules/signal-tests: Likewise. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 4 ++++ modules/signal-tests | 13 +++++++++++++ tests/test-signal.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 modules/signal-tests create mode 100644 tests/test-signal.c diff --git a/ChangeLog b/ChangeLog index d0030b3..def2b4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-03-21 Eric Blake <e...@byu.net> + signal-tests: test previous patch + * tests/test-signal.c: New file. + * modules/signal-tests: Likewise. + signal.h: always support 'volatile sig_atomic_t' * m4/signal_h.m4 (gl_SIGNAL_H): Check for AIX limitation. (gl_SIGNAL_H_DEFAULTS): Add a default. diff --git a/modules/signal-tests b/modules/signal-tests new file mode 100644 index 0000000..0686537 --- /dev/null +++ b/modules/signal-tests @@ -0,0 +1,13 @@ +Files: +tests/test-signal.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-signal +check_PROGRAMS += test-signal + +License: +LGPL diff --git a/tests/test-signal.c b/tests/test-signal.c new file mode 100644 index 0000000..4bc13ab --- /dev/null +++ b/tests/test-signal.c @@ -0,0 +1,28 @@ +/* Test of <signal.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 <e...@byu.net>, 2009. */ + +#include <config.h> + +#include <signal.h> + +volatile sig_atomic_t s; + +int main () +{ + return s; +} -- 1.6.1.2