sagemath/sagemath-sigfpe.patch
Jerry James eb706cd5f8 Version 9.1.
- Drop upstreamed -nauty patch.
- Drop -cbc patch; upstream uses the system Cbc now.
- Add -ecl patch for ecl 20.4.24.
2020-07-10 11:04:09 -06:00

143 lines
5 KiB
Diff

diff -up src/sage/libs/ecl.pyx.orig src/sage/libs/ecl.pyx
--- src/sage/libs/ecl.pyx.orig 2020-07-07 09:07:43.622621879 -0600
+++ src/sage/libs/ecl.pyx 2020-07-09 10:04:16.260992211 -0600
@@ -15,7 +15,7 @@ Library interface to Embeddable Common L
#adapted to work with pure Python types.
from libc.stdlib cimport abort
-from libc.signal cimport SIGINT, SIGBUS, SIGSEGV
+from libc.signal cimport SIGINT, SIGBUS, SIGSEGV, SIGFPE
from libc.signal cimport raise_ as signal_raise
from posix.signal cimport sigaction, sigaction_t
cimport cysignals.signals
@@ -47,9 +47,14 @@ cdef extern from "eclsig.h":
void ecl_sig_off()
cdef sigaction_t ecl_sigint_handler
cdef sigaction_t ecl_sigbus_handler
+ cdef sigaction_t ecl_sigfpe_handler
cdef sigaction_t ecl_sigsegv_handler
cdef mpz_t ecl_mpz_from_bignum(cl_object obj)
cdef cl_object ecl_bignum_from_mpz(mpz_t num)
+ cdef int fegetexcept()
+ cdef int feenableexcept(int)
+ cdef int fedisableexcept(int)
+ cdef int ecl_feflags
cdef cl_object string_to_object(char * s):
return ecl_read_from_cstring(s)
@@ -232,6 +237,7 @@ def init_ecl():
global ecl_has_booted
cdef char *argv[1]
cdef sigaction_t sage_action[32]
+ cdef int sage_fpes
cdef int i
if ecl_has_booted:
@@ -248,6 +254,8 @@ def init_ecl():
for i in range(1,32):
sigaction(i, NULL, &sage_action[i])
+ sage_fpes = fegetexcept()
+
#initialize ECL
ecl_set_option(ECL_OPT_SIGNAL_HANDLING_THREAD, 0)
cl_boot(1, argv)
@@ -255,12 +263,19 @@ def init_ecl():
#save signal handler from ECL
sigaction(SIGINT, NULL, &ecl_sigint_handler)
sigaction(SIGBUS, NULL, &ecl_sigbus_handler)
+ sigaction(SIGFPE, NULL, &ecl_sigfpe_handler)
sigaction(SIGSEGV, NULL, &ecl_sigsegv_handler)
+ #save ECL's floating point exception flags
+ ecl_feflags = fegetexcept()
+
#and put the Sage signal handlers back
for i in range(1,32):
sigaction(i, &sage_action[i], NULL)
+ fedisableexcept(ecl_feflags)
+ feenableexcept(sage_fpes)
+
#initialise list of objects and bind to global variable
# *SAGE-LIST-OF-OBJECTS* to make it rooted in the reachable tree for the GC
list_of_objects=cl_cons(Cnil,cl_cons(Cnil,Cnil))
diff -up src/sage/libs/eclsig.h.orig src/sage/libs/eclsig.h
--- src/sage/libs/eclsig.h.orig 2020-05-20 16:33:41.000000000 -0600
+++ src/sage/libs/eclsig.h 2020-07-09 10:01:25.618299374 -0600
@@ -9,25 +9,59 @@
#include <signal.h>
+
+/* Rummage around to determine how ECL was configured */
+#define ECL_AVOID_FPE_H /* Prevent some local includes */
+#include <ecl/config-internal.h>
+
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#ifndef FE_ALL_EXCEPT
+#define FE_ALL_EXCEPT FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID
+#endif
+#else
+#ifndef FE_ALL_EXCEPT
+#define FE_ALL_EXCEPT 0
+#endif
+#endif
+
+#ifndef HAVE_FEENABLEEXCEPT
+/* These are GNU extensions */
+#define fegetexcept() 0
+#define feenablexcept(flags)
+#define fdisableexcept(flags)
+#endif
+
static struct sigaction ecl_sigint_handler;
static struct sigaction ecl_sigbus_handler;
+static struct sigaction ecl_sigfpe_handler;
static struct sigaction ecl_sigsegv_handler;
static struct sigaction sage_sigint_handler;
static struct sigaction sage_sigbus_handler;
+static struct sigaction sage_sigfpe_handler;
static struct sigaction sage_sigsegv_handler;
+static int ecl_feflags;
+static int sage_feflags;
static inline void set_ecl_signal_handler(void)
{
sigaction(SIGINT, &ecl_sigint_handler, &sage_sigint_handler);
sigaction(SIGBUS, &ecl_sigbus_handler, &sage_sigbus_handler);
+ sigaction(SIGFPE, &ecl_sigfpe_handler, &sage_sigfpe_handler);
sigaction(SIGSEGV, &ecl_sigsegv_handler, &sage_sigsegv_handler);
+ /* sage_feflags should be 0; we don't set them otherwise */
+ sage_feflags = fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(ecl_feflags);
}
static inline void unset_ecl_signal_handler(void)
{
sigaction(SIGINT, &sage_sigint_handler, NULL);
sigaction(SIGBUS, &sage_sigbus_handler, NULL);
+ sigaction(SIGFPE, &sage_sigfpe_handler, NULL);
sigaction(SIGSEGV, &sage_sigsegv_handler, NULL);
+ ecl_feflags = fedisableexcept(FE_ALL_EXCEPT);
+ feenableexcept(sage_feflags);
}
/* This MUST be a macro because sig_on() must be in the same
diff -up src/sage/libs/mpmath/ext_impl.pyx.orig src/sage/libs/mpmath/ext_impl.pyx
--- src/sage/libs/mpmath/ext_impl.pyx.orig 2020-05-20 16:33:41.000000000 -0600
+++ src/sage/libs/mpmath/ext_impl.pyx 2020-07-09 10:01:25.620299371 -0600
@@ -162,9 +162,9 @@ opts_double_precision.rounding = ROUND_N
opts_mini_prec.prec = 5
opts_mini_prec.rounding = ROUND_D
-cdef double _double_inf = float("1e300") * float("1e300")
-cdef double _double_ninf = -_double_inf
-cdef double _double_nan = _double_inf - _double_inf
+cdef double _double_inf = float("inf")
+cdef double _double_ninf = float("-inf")
+cdef double _double_nan = float("nan")
cdef inline void MPF_init(MPF *x):
"""Allocate space and set value to zero.