@@ -27,6 +27,8 @@ from .paridecl cimport (avma, pari_mainstack, gnil, gcopy,
27
27
is_universal_constant, is_on_stack,
28
28
isclone, gclone, gclone_refc)
29
29
30
+ from warnings import warn
31
+
30
32
31
33
cdef extern from * :
32
34
int sig_on_count " cysigs.sig_on_count"
@@ -50,9 +52,13 @@ cdef void remove_from_pari_stack(Gen self):
50
52
print (f" Expected: {<object>stackbottom}" )
51
53
print (f" Actual: {self}" )
52
54
if self .sp() != avma:
53
- print (" ERROR: inconsistent avma when removing Gen from PARI stack" )
54
- print (f" Expected: 0x{self.sp():x}" )
55
- print (f" Actual: 0x{avma:x}" )
55
+ if avma > self .sp():
56
+ print (" ERROR: inconsistent avma when removing Gen from PARI stack" )
57
+ print (f" Expected: 0x{self.sp():x}" )
58
+ print (f" Actual: 0x{avma:x}" )
59
+ else :
60
+ warn(f" cypari2 leaked {self.sp() - avma} bytes on the PARI stack" ,
61
+ RuntimeWarning , stacklevel = 2 )
56
62
stackbottom = n = self .next
57
63
self .next = NULL
58
64
reset_avma()
@@ -73,8 +79,10 @@ cdef inline Gen Gen_stack_new(GEN x):
73
79
z.next = stackbottom
74
80
stackbottom = < PyObject* > z
75
81
if z.next is not < PyObject* > top_of_stack:
76
- if z.sp() > (< Gen> z.next).sp():
77
- raise SystemError (" objects on PARI stack in invalid order" )
82
+ s0 = z.sp()
83
+ s1 = (< Gen> z.next).sp()
84
+ if s0 > s1:
85
+ raise SystemError (f" objects on PARI stack in invalid order (first: 0x{s0:x}; next: 0x{s1:x})" )
78
86
return z
79
87
80
88
0 commit comments