# HG changeset patch # User Bruno Haible # Date 1316818239 -7200 # Node ID 68596f3bad3e2fa7af2f8361afef4f2b22ca0d49 # Parent 05bdc6eefa0741c9f6dc577712fe10e50ce7ce0b raise: Support for MSVC. * lib/signal.in.h (raise): New declaration. * lib/raise.c (raise_nothrow, rpl_raise): New alternate implementation for native Windows platforms. * m4/raise.m4: New file. * m4/signal_h.m4 (gl_SIGNAL_H_DEFAULTS): Initialize GNULIB_RAISE, HAVE_RAISE, REPLACE_RAISE. * modules/signal (Makefile.am): Substitute GNULIB_RAISE, HAVE_RAISE, REPLACE_RAISE. * modules/raise (Status, Notice): Remove fields. (Files): Add m4/raise.m4. (Depends-on): Add signal, msvc-inval. (configure.ac): Use the common idioms. (Maintainer): Add me. * tests/test-signal-c++.cc: Check the signature of raise. * doc/posix-functions/raise.texi: Mention the problem on MSVC. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-09-23 Bruno Haible + + raise: Support for MSVC. + * lib/signal.in.h (raise): New declaration. + * lib/raise.c (raise_nothrow, rpl_raise): New alternate implementation + for native Windows platforms. + * m4/raise.m4: New file. + * m4/signal_h.m4 (gl_SIGNAL_H_DEFAULTS): Initialize GNULIB_RAISE, + HAVE_RAISE, REPLACE_RAISE. + * modules/signal (Makefile.am): Substitute GNULIB_RAISE, HAVE_RAISE, + REPLACE_RAISE. + * modules/raise (Status, Notice): Remove fields. + (Files): Add m4/raise.m4. + (Depends-on): Add signal, msvc-inval. + (configure.ac): Use the common idioms. + (Maintainer): Add me. + * tests/test-signal-c++.cc: Check the signature of raise. + * doc/posix-functions/raise.texi: Mention the problem on MSVC. + 2011-09-23 Bruno Haible pipe2: Fix compilation on pre-C99 compilers. diff --git a/doc/posix-functions/raise.texi b/doc/posix-functions/raise.texi --- a/doc/posix-functions/raise.texi +++ b/doc/posix-functions/raise.texi @@ -10,6 +10,9 @@ @itemize @item This function is missing on some old platforms. +@item +This function crashes when invoked with invalid arguments on some platforms: +MSVC 9. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/raise.c b/lib/raise.c --- a/lib/raise.c +++ b/lib/raise.c @@ -15,16 +15,59 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* written by Jim Meyering */ +/* written by Jim Meyering and Bruno Haible */ #include -#include +/* Specification. */ #include -#include + +#if HAVE_RAISE +/* Native Windows platform. */ + +# include + +# include "msvc-inval.h" + +# undef raise + +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static inline int +raise_nothrow (int sig) +{ + int result; + + TRY_MSVC_INVAL + { + result = raise (sig); + } + CATCH_MSVC_INVAL + { + result = -1; + errno = EINVAL; + } + DONE_MSVC_INVAL; + + return result; +} +# define raise raise_nothrow +# endif + +int +rpl_raise (int sig) +{ + return raise_nothrow (sig); +} + +#else +/* An old Unix platform. */ + +# include int raise (int sig) { return kill (getpid (), sig); } + +#endif diff --git a/lib/signal.in.h b/lib/signal.in.h --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -152,6 +152,29 @@ #endif +#if @GNULIB_RAISE@ +# if @REPLACE_RAISE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef raise +# define raise rpl_raise +# endif +_GL_FUNCDECL_RPL (raise, int, (int sig)); +_GL_CXXALIAS_RPL (raise, int, (int sig)); +# else +# if !@HAVE_RAISE@ +_GL_FUNCDECL_SYS (raise, int, (int sig)); +# endif +_GL_CXXALIAS_SYS (raise, int, (int sig)); +# endif +_GL_CXXALIASWARN (raise); +#elif defined GNULIB_POSIXCHECK +# undef raise +/* Assume raise is always declared. */ +_GL_WARN_ON_USE (raise, "raise can crash on native Windows - " + "use gnulib module raise for portability"); +#endif + + #if @GNULIB_SIGPROCMASK@ # if !@HAVE_POSIX_SIGNALBLOCKING@ diff --git a/m4/raise.m4 b/m4/raise.m4 new file mode 100644 --- /dev/null +++ b/m4/raise.m4 @@ -0,0 +1,25 @@ +# raise.m4 serial 1 +dnl Copyright (C) 2011 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_FUNC_RAISE], +[ + AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([gl_MSVC_INVAL]) + AC_CHECK_FUNCS([raise]) + if test $ac_cv_func_raise = no; then + HAVE_RAISE=0 + else + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_RAISE=1 + fi + fi +]) + +# Prerequisites of lib/raise.c. +AC_DEFUN([gl_PREREQ_RAISE], [ + AC_REQUIRE([AC_C_INLINE]) +]) diff --git a/m4/signal_h.m4 b/m4/signal_h.m4 --- a/m4/signal_h.m4 +++ b/m4/signal_h.m4 @@ -1,4 +1,4 @@ -# signal_h.m4 serial 17 +# signal_h.m4 serial 18 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -62,12 +62,14 @@ AC_DEFUN([gl_SIGNAL_H_DEFAULTS], [ GNULIB_PTHREAD_SIGMASK=0; AC_SUBST([GNULIB_PTHREAD_SIGMASK]) + GNULIB_RAISE=0; AC_SUBST([GNULIB_RAISE]) GNULIB_SIGNAL_H_SIGPIPE=0; AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE]) GNULIB_SIGPROCMASK=0; AC_SUBST([GNULIB_SIGPROCMASK]) GNULIB_SIGACTION=0; AC_SUBST([GNULIB_SIGACTION]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING]) HAVE_PTHREAD_SIGMASK=1; AC_SUBST([HAVE_PTHREAD_SIGMASK]) + HAVE_RAISE=1; AC_SUBST([HAVE_RAISE]) HAVE_SIGSET_T=1; AC_SUBST([HAVE_SIGSET_T]) HAVE_SIGINFO_T=1; AC_SUBST([HAVE_SIGINFO_T]) HAVE_SIGACTION=1; AC_SUBST([HAVE_SIGACTION]) @@ -77,4 +79,5 @@ AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T]) HAVE_SIGHANDLER_T=1; AC_SUBST([HAVE_SIGHANDLER_T]) REPLACE_PTHREAD_SIGMASK=0; AC_SUBST([REPLACE_PTHREAD_SIGMASK]) + REPLACE_RAISE=0; AC_SUBST([REPLACE_RAISE]) ]) diff --git a/modules/raise b/modules/raise --- a/modules/raise +++ b/modules/raise @@ -1,19 +1,21 @@ Description: Send a signal to the executing process. -Status: -obsolete - -Notice: -This module is obsolete. - Files: lib/raise.c +m4/raise.m4 Depends-on: +signal +msvc-inval [test $HAVE_RAISE = 0 || test $REPLACE_RAISE = 1] configure.ac: -AC_REPLACE_FUNCS(raise) +gl_FUNC_RAISE +if test $HAVE_RAISE = 0 || test $REPLACE_RAISE = 1; then + AC_LIBOBJ([raise]) + gl_PREREQ_RAISE +fi +gl_SIGNAL_MODULE_INDICATOR([raise]) Makefile.am: @@ -24,5 +26,5 @@ LGPLv2+ Maintainer: -Jim Meyering +Jim Meyering, Bruno Haible diff --git a/modules/signal b/modules/signal --- a/modules/signal +++ b/modules/signal @@ -29,11 +29,13 @@ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \ -e 's|@''GNULIB_PTHREAD_SIGMASK''@|$(GNULIB_PTHREAD_SIGMASK)|g' \ + -e 's|@''GNULIB_RAISE''@|$(GNULIB_RAISE)|g' \ -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' \ -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \ -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \ -e 's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \ -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \ + -e 's|@''HAVE_RAISE''@|$(HAVE_RAISE)|g' \ -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \ -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \ -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \ @@ -41,6 +43,7 @@ -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \ -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \ -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' \ + -e 's|@''REPLACE_RAISE''@|$(REPLACE_RAISE)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ diff --git a/tests/test-signal-c++.cc b/tests/test-signal-c++.cc --- a/tests/test-signal-c++.cc +++ b/tests/test-signal-c++.cc @@ -29,6 +29,10 @@ (int, const sigset_t *, sigset_t *)); #endif +#if GNULIB_TEST_RAISE +SIGNATURE_CHECK (GNULIB_NAMESPACE::raise, int, (int)); +#endif + #if GNULIB_TEST_SIGPROCMASK SIGNATURE_CHECK (GNULIB_NAMESPACE::sigismember, int, (const sigset_t *, int)); SIGNATURE_CHECK (GNULIB_NAMESPACE::sigemptyset, int, (sigset_t *));