Skip to content

Commit f12759f

Browse files
committed
For safety, clone errors instead of keeping on stack
1 parent 74f31ac commit f12759f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cypari2/handle_error.pyx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from cysignals.signals cimport sig_block, sig_unblock, sig_error
2929

3030
from .paridecl cimport *
3131
from .paripriv cimport *
32-
from .stack cimport new_gen_noclear, reset_avma
32+
from .stack cimport clone_gen_noclear, reset_avma
3333

3434

3535
# We derive PariError from RuntimeError, for backward compatibility with
@@ -170,6 +170,23 @@ cdef int _pari_err_handle(GEN E) except 0:
170170
Traceback (most recent call last):
171171
...
172172
PariError: impossible inverse in gdiv: 0
173+
174+
Test exceptions with a pointer to a PARI object:
175+
176+
>>> from cypari2 import Pari
177+
>>> def exc():
178+
... K = Pari().nfinit("x^2 + 1")
179+
... I = K.idealhnf(2)
180+
... I[0]
181+
... try:
182+
... K.idealaddtoone(I, I)
183+
... except RuntimeError as e:
184+
... return e
185+
>>> L = [exc(), exc()]
186+
>>> print(L[0])
187+
elements not coprime in idealaddtoone:
188+
[2, 0; 0, 2]
189+
[2, 0; 0, 2]
173190
"""
174191
cdef long errnum = E[1]
175192
cdef char* errstr
@@ -193,7 +210,7 @@ cdef int _pari_err_handle(GEN E) except 0:
193210
if s is not NULL:
194211
pari_error_string = s.decode('ascii') + ": " + pari_error_string
195212

196-
raise PariError(errnum, pari_error_string, new_gen_noclear(E))
213+
raise PariError(errnum, pari_error_string, clone_gen_noclear(E))
197214

198215

199216
cdef void _pari_err_recover(long errnum):

0 commit comments

Comments
 (0)