Skip to content

Commit 12e7585

Browse files
committed
Raise a real exception when calling remove_from_pari_stack() inside sig_on()
1 parent cc1d510 commit 12e7585

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cypari2/stack.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ from __future__ import absolute_import, division, print_function
1818
cimport cython
1919

2020
from cpython.ref cimport PyObject, Py_XINCREF, Py_XDECREF
21+
from cpython.exc cimport PyErr_SetString
2122

22-
from cysignals.signals cimport sig_on, sig_off, sig_block, sig_unblock
23+
from cysignals.signals cimport (sig_on, sig_off, sig_block, sig_unblock,
24+
sig_error)
2325
from cysignals.memory cimport check_malloc, sig_free
2426

2527
from .gen cimport Gen, Gen_new
@@ -52,6 +54,9 @@ cdef void remove_from_pari_stack(Gen self):
5254
print("ERROR: removing wrong instance of Gen")
5355
print(f"Expected: {<object>stackbottom}")
5456
print(f"Actual: {self}")
57+
if sig_on_count and not block_sigint:
58+
PyErr_SetString(SystemError, "calling remove_from_pari_stack() inside sig_on()")
59+
sig_error()
5560
if self.sp() != avma:
5661
if avma > self.sp():
5762
print("ERROR: inconsistent avma when removing Gen from PARI stack")
@@ -60,8 +65,6 @@ cdef void remove_from_pari_stack(Gen self):
6065
else:
6166
warn(f"cypari2 leaked {self.sp() - avma} bytes on the PARI stack",
6267
RuntimeWarning, stacklevel=2)
63-
if sig_on_count and not block_sigint:
64-
print(f"ERROR: sig_on_count = {sig_on_count} during remove_from_pari_stack()")
6568
n = self.next
6669
stackbottom = <PyObject*>n
6770
self.next = None

0 commit comments

Comments
 (0)