~ chicken-core (chicken-5) fb02ab4ef72d155c09549672e01660ba4c26eea0


commit fb02ab4ef72d155c09549672e01660ba4c26eea0
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Wed Jun 13 22:54:26 2012 +0200
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Sat Jul 7 22:44:25 2012 +0200

    Use sigsetjmp/siglongjmp instead of setjmp/longjmp on platforms where these are available to prevent inadvertent resetting of signal mask and the associated unneccessary system call overhead
    
    Signed-off-by: felix <felix@call-with-current-continuation.org>

diff --git a/Makefile.bsd b/Makefile.bsd
index 7c545afa..4402c039 100644
--- a/Makefile.bsd
+++ b/Makefile.bsd
@@ -84,6 +84,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_MEMMOVE 1" >>$@
 	echo "#define HAVE_MEMORY_H 1" >>$@
 	echo "#define HAVE_SIGACTION 1" >>$@
+	echo "#define HAVE_SIGSETJMP 1" >>$@
 	echo "#define HAVE_STDINT_H 1" >>$@
 	echo "#define HAVE_STDLIB_H 1" >>$@
 	echo "#define HAVE_STRERROR 1" >>$@
diff --git a/Makefile.linux b/Makefile.linux
index 37f848ce..c55d55e9 100644
--- a/Makefile.linux
+++ b/Makefile.linux
@@ -73,6 +73,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_MEMMOVE 1" >>$@
 	echo "#define HAVE_MEMORY_H 1" >>$@
 	echo "#define HAVE_SIGACTION 1" >>$@
+	echo "#define HAVE_SIGSETJMP 1" >>$@
 	echo "#define HAVE_STDINT_H 1" >>$@
 	echo "#define HAVE_STDLIB_H 1" >>$@
 	echo "#define HAVE_STRERROR 1" >>$@
diff --git a/Makefile.macosx b/Makefile.macosx
index fdb2483e..a0a73fae 100644
--- a/Makefile.macosx
+++ b/Makefile.macosx
@@ -97,6 +97,7 @@ chicken-config.h: chicken-defaults.h
 	echo "#define HAVE_MEMMOVE 1" >>$@
 	echo "#define HAVE_MEMORY_H 1" >>$@
 	echo "#define HAVE_SIGACTION 1" >>$@
+	echo "#define HAVE_SIGSETJMP 1" >>$@
 	echo "#define HAVE_STDINT_H 1" >>$@
 	echo "#define HAVE_STDLIB_H 1" >>$@
 	echo "#define HAVE_STRERROR 1" >>$@
diff --git a/NEWS b/NEWS
index 4b31d83d..136dbc9f 100644
--- a/NEWS
+++ b/NEWS
@@ -241,6 +241,8 @@
     and "-heap-shrinkage"
   - the assembly-language stub routine for the implementation of "apply"
     was broken for Sparc64 systems and has been disabled for this platform
+  - signal masks were accedentally reset upon GC for some platforms; use
+    sigsetjmp/siglongjmp on BSD, Linux and MacOS X
  
 - Type system
   - added new type-specifiers "input-port", "output-port", "(list-of T)" 
diff --git a/chicken.h b/chicken.h
index 837a51cf..6e9e009c 100644
--- a/chicken.h
+++ b/chicken.h
@@ -874,8 +874,17 @@ DECL_C_PROC_p0 (128,  1,0,0,0,0,0,0,0)
 # define C_gettimeofday             gettimeofday
 # define C_gmtime                   gmtime
 # define C_localtime                localtime
-# define C_setjmp                   setjmp
-# define C_longjmp                  longjmp
+/*
+ * It is undefined whether regular setjmp/longjmp save/restore signal mask
+ * so try to use versions that we know won't try to save & restore.
+ */
+# if defined(HAVE_SIGSETJMP)
+#   define C_setjmp(e)              sigsetjmp(e, 0)
+#   define C_longjmp(e,v)           siglongjmp(e, v)
+# else
+#   define C_setjmp                 setjmp
+#   define C_longjmp                longjmp
+# endif
 # define C_alloca                   alloca
 # define C_strerror                 strerror
 # define C_isalpha                  isalpha
Trap