@@ -483,6 +483,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
483
483
"""
484
484
485
485
def __cinit__ (self ):
486
+ # this function is only called to create global_dummy_Integer,
487
+ # after that it will be replaced by fast_tp_new
486
488
global the_integer_ring
487
489
mpz_init(self .value)
488
490
self ._parent = the_integer_ring
@@ -7542,8 +7544,6 @@ cdef int sizeof_Integer
7542
7544
# from. DO NOT INITIALIZE IT AGAIN and DO NOT REFERENCE IT!
7543
7545
cdef Integer global_dummy_Integer
7544
7546
global_dummy_Integer = Integer()
7545
- # Reallocate to one limb to fix :issue:`31340` and :issue:`33081`
7546
- _mpz_realloc(global_dummy_Integer.value, 1 )
7547
7547
7548
7548
7549
7549
def _check_global_dummy_Integer ():
@@ -7559,7 +7559,7 @@ def _check_global_dummy_Integer():
7559
7559
# Check that it has exactly one limb allocated
7560
7560
# This is assumed later in fast_tp_new() :issue:`33081`
7561
7561
cdef mpz_ptr dummy = global_dummy_Integer.value
7562
- if dummy._mp_alloc == 1 and dummy._mp_size == 0 :
7562
+ if dummy._mp_alloc == 0 and dummy._mp_size == 0 :
7563
7563
return True
7564
7564
7565
7565
raise AssertionError (
@@ -7589,7 +7589,6 @@ cdef PyObject* fast_tp_new(type t, args, kwds) except NULL:
7589
7589
global integer_pool, integer_pool_count, total_alloc, use_pool
7590
7590
7591
7591
cdef PyObject* new
7592
- cdef mpz_ptr new_mpz
7593
7592
7594
7593
# for profiling pool usage
7595
7594
# total_alloc += 1
@@ -7622,12 +7621,10 @@ cdef PyObject* fast_tp_new(type t, args, kwds) except NULL:
7622
7621
# created before this tp_new started to operate.
7623
7622
memcpy(new, (< void * > global_dummy_Integer), sizeof_Integer)
7624
7623
7625
- # We allocate memory for the _mp_d element of the value of this
7626
- # new Integer. We allocate one limb. Normally, one would use
7627
- # mpz_init() for this, but we allocate the memory directly.
7628
- # This saves time both by avoiding extra function calls and
7629
- # because the rest of the mpz struct was already initialized
7630
- # fully using the memcpy above.
7624
+ # In sufficiently new versions of GMP, mpz_init() does not allocate
7625
+ # any memory. We assume that memcpy a newly-initialized mpz results
7626
+ # in a valid new mpz. Normally, one would use mpz_init() for this.
7627
+ # This saves time by avoiding extra function calls.
7631
7628
#
7632
7629
# What is done here is potentially very dangerous as it reaches
7633
7630
# deeply into the internal structure of GMP. Consequently things
@@ -7639,10 +7636,6 @@ cdef PyObject* fast_tp_new(type t, args, kwds) except NULL:
7639
7636
# various internals described here may change in future GMP releases.
7640
7637
# Applications expecting to be compatible with future releases should use
7641
7638
# only the documented interfaces described in previous chapters."
7642
- #
7643
- # NOTE: This assumes global_dummy_Integer.value._mp_alloc == 1
7644
- new_mpz = < mpz_ptr> ((< Integer> new).value)
7645
- new_mpz._mp_d = < mp_ptr> check_malloc(GMP_LIMB_BITS >> 3 )
7646
7639
7647
7640
# This line is only needed if Python is compiled in debugging mode
7648
7641
# './configure --with-pydebug' or SAGE_DEBUG=yes. If that is the
@@ -7692,7 +7685,7 @@ cdef void fast_tp_dealloc(PyObject* o) noexcept:
7692
7685
return
7693
7686
7694
7687
# No space in the pool, so just free the mpz_t.
7695
- sig_free (o_mpz._mp_d )
7688
+ mpz_clear (o_mpz)
7696
7689
7697
7690
# Free the object. This assumes that Py_TPFLAGS_HAVE_GC is not
7698
7691
# set. If it was set another free function would need to be
0 commit comments