summarylogtreecommitdiffstats
path: root/sagemath-ecl-20.04.patch
blob: 0a0ecfcc9ddf0432a3967929faa9c84ab8f1fda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
diff --git a/src/sage/interfaces/interface.py b/src/sage/interfaces/interface.py
index 616c13d..430ba80 100644
--- a/src/sage/interfaces/interface.py
+++ b/src/sage/interfaces/interface.py
@@ -589,9 +589,9 @@ class Interface(WithEqualityById, ParentWithBase):
         EXAMPLES::
 
             sage: maxima.quad_qags(x, x, 0, 1, epsrel=1e-4)
-            [0.5,0.55511151231257...e-14,21,0]
+            [0.5,5.5511151231257...e-15,21,0]
             sage: maxima.function_call('quad_qags', [x, x, 0, 1], {'epsrel':'1e-4'})
-            [0.5,0.55511151231257...e-14,21,0]
+            [0.5,5.5511151231257...e-15,21,0]
         """
         args, kwds = self._convert_args_kwds(args, kwds)
         self._check_valid_function_name(function)
diff --git a/src/sage/interfaces/maxima.py b/src/sage/interfaces/maxima.py
index 9ab456e..3e8f4a6 100644
--- a/src/sage/interfaces/maxima.py
+++ b/src/sage/interfaces/maxima.py
@@ -128,9 +128,9 @@ http://maxima.sourceforge.net/docs/intromax/intromax.html.
 
     sage: a = maxima('(1 + sqrt(2))^5')
     sage: float(a)
-    82.01219330881975
+    82.0121933088197...
     sage: a.numer()
-    82.01219330881975
+    82.0121933088197...
 
 ::
 
diff --git a/src/sage/interfaces/maxima_abstract.py b/src/sage/interfaces/maxima_abstract.py
index 86fbe75..ed3055d 100644
--- a/src/sage/interfaces/maxima_abstract.py
+++ b/src/sage/interfaces/maxima_abstract.py
@@ -1518,7 +1518,7 @@ class MaximaAbstractElement(ExtraTabCompletion, InterfaceElement):
         EXAMPLES::
 
             sage: maxima('exp(-sqrt(x))').nintegral('x',0,1)
-            (0.5284822353142306, 0.41633141378838...e-10, 231, 0)
+            (0.5284822353142306, 4.1633141378838...e-11, 231, 0)
 
         Note that GP also does numerical integration, and can do so to very
         high precision very quickly::
diff --git a/src/sage/interfaces/tests.py b/src/sage/interfaces/tests.py
index fc77f12..a6847a9 100644
--- a/src/sage/interfaces/tests.py
+++ b/src/sage/interfaces/tests.py
@@ -31,8 +31,8 @@ Test that write errors to stderr are handled gracefully by GAP
     ....: except IOError:
     ....:     f = open('/dev/null', 'w')
     sage: kwds = dict(shell=True, stdout=f, stderr=f)
-    sage: subprocess.call("echo syntax error | ecl", **kwds)
-    0
+    sage: subprocess.call("echo syntax error | ecl", **kwds) in (0, 255)
+    True
     sage: subprocess.call("echo syntax error | gap", **kwds) in (0, 1)
     True
     sage: subprocess.call("echo syntax error | gp", **kwds)
diff --git a/src/sage/libs/ecl.pxd b/src/sage/libs/ecl.pxd
index 4dd273f..f0b30de 100644
--- a/src/sage/libs/ecl.pxd
+++ b/src/sage/libs/ecl.pxd
@@ -39,7 +39,6 @@ cdef extern from "ecl/ecl.h":
         ECL_OPT_TRAP_SIGINT,
         ECL_OPT_TRAP_SIGILL,
         ECL_OPT_TRAP_SIGBUS,
-        ECL_OPT_TRAP_SIGCHLD,
         ECL_OPT_TRAP_SIGPIPE,
         ECL_OPT_TRAP_INTERRUPT_SIGNAL,
         ECL_OPT_SIGNAL_HANDLING_THREAD,
@@ -53,7 +52,6 @@ cdef extern from "ecl/ecl.h":
         ECL_OPT_LISP_STACK_SAFETY_AREA,
         ECL_OPT_C_STACK_SIZE,
         ECL_OPT_C_STACK_SAFETY_AREA,
-        ECL_OPT_SIGALTSTACK_SIZE,
         ECL_OPT_HEAP_SIZE,
         ECL_OPT_HEAP_SAFETY_AREA,
         ECL_OPT_THREAD_INTERRUPT_SIGNAL,
diff --git a/src/sage/libs/ecl.pyx b/src/sage/libs/ecl.pyx
index e408866..fa24ac0 100644
--- a/src/sage/libs/ecl.pyx
+++ b/src/sage/libs/ecl.pyx
@@ -15,7 +15,7 @@ Library interface to Embeddable Common Lisp (ECL)
 #adapted to work with pure Python types.
 
 from libc.stdlib cimport abort
-from libc.signal cimport SIGINT, SIGBUS, SIGSEGV, SIGCHLD
+from libc.signal cimport SIGINT, SIGBUS, SIGFPE, SIGSEGV
 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)
@@ -139,7 +143,6 @@ def test_ecl_options():
         ECL_OPT_TRAP_SIGINT = 1
         ECL_OPT_TRAP_SIGILL = 1
         ECL_OPT_TRAP_SIGBUS = 1
-        ECL_OPT_TRAP_SIGCHLD = 0
         ECL_OPT_TRAP_SIGPIPE = 1
         ECL_OPT_TRAP_INTERRUPT_SIGNAL = 1
         ECL_OPT_SIGNAL_HANDLING_THREAD = 0
@@ -153,7 +156,6 @@ def test_ecl_options():
         ECL_OPT_LISP_STACK_SAFETY_AREA = ...
         ECL_OPT_C_STACK_SIZE = ...
         ECL_OPT_C_STACK_SAFETY_AREA = ...
-        ECL_OPT_SIGALTSTACK_SIZE = 1
         ECL_OPT_HEAP_SIZE = ...
         ECL_OPT_HEAP_SAFETY_AREA = ...
         ECL_OPT_THREAD_INTERRUPT_SIGNAL = ...
@@ -171,8 +173,6 @@ def test_ecl_options():
         ecl_get_option(ECL_OPT_TRAP_SIGILL)))
     print('ECL_OPT_TRAP_SIGBUS = {0}'.format(
         ecl_get_option(ECL_OPT_TRAP_SIGBUS)))
-    print('ECL_OPT_TRAP_SIGCHLD = {0}'.format(
-        ecl_get_option(ECL_OPT_TRAP_SIGCHLD)))
     print('ECL_OPT_TRAP_SIGPIPE = {0}'.format(
         ecl_get_option(ECL_OPT_TRAP_SIGPIPE)))
     print('ECL_OPT_TRAP_INTERRUPT_SIGNAL = {0}'.format(
@@ -199,8 +199,6 @@ def test_ecl_options():
         ecl_get_option(ECL_OPT_C_STACK_SIZE)))
     print('ECL_OPT_C_STACK_SAFETY_AREA = {0}'.format(
         ecl_get_option(ECL_OPT_C_STACK_SAFETY_AREA)))
-    print('ECL_OPT_SIGALTSTACK_SIZE = {0}'.format(
-        ecl_get_option(ECL_OPT_SIGALTSTACK_SIZE)))
     print('ECL_OPT_HEAP_SIZE = {0}'.format(
         ecl_get_option(ECL_OPT_HEAP_SIZE)))
     print('ECL_OPT_HEAP_SAFETY_AREA = {0}'.format(
@@ -238,14 +243,12 @@ 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:
         raise RuntimeError("ECL is already initialized")
 
-    # we need it to stop handling SIGCHLD
-    ecl_set_option(ECL_OPT_TRAP_SIGCHLD, 0);
-
     #we keep our own GMP memory functions. ECL should not claim them
     ecl_set_option(ECL_OPT_SET_GMP_MEMORY_FUNCTIONS,0);
 
@@ -257,6 +263,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)
@@ -264,14 +272,12 @@ 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()
+
-    #verify that no SIGCHLD handler was installed
-    cdef sigaction_t sig_test
-    sigaction(SIGCHLD, NULL, &sig_test)
-    assert sage_action[SIGCHLD].sa_handler == NULL  # Sage does not set SIGCHLD handler
-    assert sig_test.sa_handler == NULL              # And ECL bootup did not set one 
-
     #and put the Sage signal handlers back
     for i in range(1,32):
         sigaction(i, &sage_action[i], NULL)
@@ -276,6 +288,9 @@ def init_ecl():
     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))
@@ -319,7 +334,6 @@ def init_ecl():
                     (values nil (princ-to-string cnd)))))
         """))
     safe_funcall_clobj=cl_eval(string_to_object(b"(symbol-function 'sage-safe-funcall)"))
-
     ecl_has_booted = 1
 
 cdef cl_object ecl_safe_eval(cl_object form) except NULL:
diff --git a/src/sage/libs/eclsig.h b/src/sage/libs/eclsig.h
index f9f2690..a7e1f40 100644
--- a/src/sage/libs/eclsig.h
+++ b/src/sage/libs/eclsig.h
@@ -9,24 +9,66 @@
 
 
 #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
+#define feclearexcept(flags) do {} while (0)
+#endif
+
+#ifndef HAVE_FEENABLEEXCEPT
+/* These are GNU extensions */
+#define fegetexcept() 0
+#define feenablexcept(flags) do {} while (0)
+#define fdisableexcept(flags) do {} while (0)
+#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);
+
+    /* first clear pending floating point exceptions, if any */
+    feclearexcept(FE_ALL_EXCEPT);
+
+    /* 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)
 {
+    /* clear pending exceptions and restore previous exception mask */
+    feclearexcept(FE_ALL_EXCEPT);
+    ecl_feflags = fedisableexcept(FE_ALL_EXCEPT);
+    feenableexcept(sage_feflags);
+
     sigaction(SIGINT, &sage_sigint_handler, NULL);
     sigaction(SIGBUS, &sage_sigbus_handler, NULL);
+    sigaction(SIGFPE, &sage_sigfpe_handler, NULL);
     sigaction(SIGSEGV, &sage_sigsegv_handler, NULL);
 }