changeset 15755:68596f3bad3e

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.
author Bruno Haible <bruno@clisp.org>
date Sat, 24 Sep 2011 00:50:39 +0200
parents 05bdc6eefa07
children 6efe9315fa03
files ChangeLog doc/posix-functions/raise.texi lib/raise.c lib/signal.in.h m4/raise.m4 m4/signal_h.m4 modules/raise modules/signal tests/test-signal-c++.cc
diffstat 9 files changed, 137 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2011-09-23  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	pipe2: Fix compilation on pre-C99 compilers.
--- 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:
--- 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 <http://www.gnu.org/licenses/>.  */
 
-/* written by Jim Meyering */
+/* written by Jim Meyering and Bruno Haible */
 
 #include <config.h>
 
-#include <sys/types.h>
+/* Specification.  */
 #include <signal.h>
-#include <unistd.h>
+
+#if HAVE_RAISE
+/* Native Windows platform.  */
+
+# include <errno.h>
+
+# 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 <unistd.h>
 
 int
 raise (int sig)
 {
   return kill (getpid (), sig);
 }
+
+#endif
--- 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@
 
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])
+])
--- 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])
 ])
--- 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
 
--- 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)' \
--- 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 *));