@@ -144,11 +144,10 @@ cimport cython
144
144
from libc.math cimport (ldexp, sqrt as sqrt_double, log as log_c,
145
145
ceil as ceil_c, isnan)
146
146
from libc.string cimport memcpy
147
- cdef extern from " <limits.h>" :
148
- const long LONG_MAX # Work around https://github.com/cython/cython/pull/2016
147
+ from libc.limits cimport LONG_MAX
149
148
150
149
from cysignals.memory cimport check_allocarray, check_malloc, sig_free
151
- from cysignals.signals cimport sig_on, sig_off, sig_check
150
+ from cysignals.signals cimport sig_on, sig_off, sig_check, sig_occurred
152
151
153
152
import operator
154
153
import sys
@@ -7296,39 +7295,41 @@ cdef PyObject* fast_tp_new(type t, args, kwds) except NULL:
7296
7295
7297
7296
return new
7298
7297
7299
- cdef void fast_tp_dealloc(PyObject* o):
7300
7298
7299
+ cdef void fast_tp_dealloc(PyObject* o):
7301
7300
# If there is room in the pool for a used integer object,
7302
7301
# then put it in rather than deallocating it.
7303
-
7304
7302
global integer_pool, integer_pool_count
7305
7303
7306
7304
cdef mpz_ptr o_mpz = < mpz_ptr> ((< Integer> o).value)
7307
7305
7308
- if integer_pool_count < integer_pool_size:
7306
+ # If we are recovering from an interrupt, throw the mpz_t away
7307
+ # without recycling or freeing it because it might be in an
7308
+ # inconsistent state (see Trac #24986).
7309
+ if sig_occurred() is NULL :
7310
+ if integer_pool_count < integer_pool_size:
7311
+ # Here we free any extra memory used by the mpz_t by
7312
+ # setting it to a single limb.
7313
+ if o_mpz._mp_alloc > 10 :
7314
+ _mpz_realloc(o_mpz, 1 )
7309
7315
7310
- # Here we free any extra memory used by the mpz_t by
7311
- # setting it to a single limb.
7312
- if o_mpz._mp_alloc > 10 :
7313
- _mpz_realloc(o_mpz, 1 )
7316
+ # It's cheap to zero out an integer, so do it here.
7317
+ o_mpz._mp_size = 0
7314
7318
7315
- # It's cheap to zero out an integer, so do it here.
7316
- o_mpz._mp_size = 0
7319
+ # And add it to the pool.
7320
+ integer_pool[integer_pool_count] = o
7321
+ integer_pool_count += 1
7322
+ return
7317
7323
7318
- # And add it to the pool.
7319
- integer_pool[integer_pool_count] = o
7320
- integer_pool_count += 1
7321
- return
7322
-
7323
- # Again, we move to the mpz_t and clear it. As in fast_tp_new,
7324
- # we free the memory directly.
7325
- sig_free(o_mpz._mp_d)
7324
+ # No space in the pool, so just free the mpz_t.
7325
+ sig_free(o_mpz._mp_d)
7326
7326
7327
7327
# Free the object. This assumes that Py_TPFLAGS_HAVE_GC is not
7328
7328
# set. If it was set another free function would need to be
7329
7329
# called.
7330
7330
PyObject_Free(o)
7331
7331
7332
+
7332
7333
from sage.misc.allocator cimport hook_tp_functions
7333
7334
cdef hook_fast_tp_functions():
7334
7335
"""
0 commit comments