@@ -57,16 +57,10 @@ AUTHORS:
57
57
58
58
from __future__ import absolute_import, division, print_function
59
59
60
- import types
61
60
cimport cython
62
61
63
- from cpython.int cimport PyInt_Check
64
- from cpython.long cimport PyLong_Check
65
- from cpython.bytes cimport PyBytes_Check
66
- from cpython.unicode cimport PyUnicode_Check
67
- from cpython.float cimport PyFloat_AS_DOUBLE
68
- from cpython.complex cimport PyComplex_RealAsDouble, PyComplex_ImagAsDouble
69
- from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT
62
+ from cpython.object cimport (Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT,
63
+ PyTypeObject)
70
64
71
65
from cysignals.memory cimport sig_free, check_malloc
72
66
from cysignals.signals cimport sig_check, sig_on, sig_off, sig_block, sig_unblock
@@ -158,7 +152,7 @@ cdef class Gen(Gen_base):
158
152
raise RuntimeError (" PARI objects cannot be instantiated directly; use pari(x) to convert x to PARI" )
159
153
160
154
def __dealloc__ (self ):
161
- if self .next is not NULL :
155
+ if self .next is not None :
162
156
# stack
163
157
remove_from_pari_stack(self )
164
158
elif self .address is not NULL :
@@ -194,7 +188,7 @@ cdef class Gen(Gen_base):
194
188
>>> pari("[[1, 2], 3]")[0][1] # indirect doctest
195
189
2
196
190
"""
197
- if self .next is not NULL :
191
+ if self .next is not None :
198
192
raise TypeError (" cannot create reference to PARI stack (call fixGEN() first)" )
199
193
if is_on_stack(g):
200
194
raise ValueError (" new_ref() called with GEN which does not belong to parent" )
@@ -208,7 +202,7 @@ cdef class Gen(Gen_base):
208
202
Return the PARI ``GEN`` corresponding to ``self`` which is
209
203
guaranteed not to change.
210
204
"""
211
- if self .next is not NULL :
205
+ if self .next is not None :
212
206
move_gens_to_heap(self .sp())
213
207
return self .g
214
208
@@ -4554,6 +4548,20 @@ cdef class Gen(Gen_base):
4554
4548
raise NotImplementedError (" the method allocatemem() should not be used; use pari.allocatemem() instead" )
4555
4549
4556
4550
4551
+ cdef int Gen_clear(self ) except - 1 :
4552
+ """
4553
+ Implementation of tp_clear() for Gen. We need to override Cython's
4554
+ default since we do not want self.next to be cleared: it is crucial
4555
+ that the next Gen stays alive until remove_from_pari_stack(self) is
4556
+ called by __dealloc__.
4557
+ """
4558
+ # Only itemcache needs to be cleared
4559
+ (< Gen> self ).itemcache = None
4560
+
4561
+
4562
+ (< PyTypeObject* > Gen).tp_clear = Gen_clear
4563
+
4564
+
4557
4565
@ cython.boundscheck (False )
4558
4566
@ cython.wraparound (False )
4559
4567
cdef Gen list_of_Gens_to_Gen(list s):
0 commit comments