@@ -3651,32 +3651,25 @@ long_richcompare(PyObject *self, PyObject *other, int op)
3651
3651
}
3652
3652
3653
3653
static inline int
3654
- compact_int_is_small (PyObject * self )
3654
+ /// Return 1 if the object is one of the immortal small ints
3655
+ _long_is_small_int (PyObject * op )
3655
3656
{
3656
- PyLongObject * pylong = (PyLongObject * )self ;
3657
- assert (_PyLong_IsCompact (pylong ));
3658
- stwodigits ival = medium_value (pylong );
3659
- if (IS_SMALL_INT (ival )) {
3660
- PyLongObject * small_pylong = (PyLongObject * )get_small_int ((sdigit )ival );
3661
- if (pylong == small_pylong ) {
3662
- return 1 ;
3663
- }
3664
- }
3665
- return 0 ;
3657
+ PyLongObject * long_object = (PyLongObject * )op ;
3658
+ int is_small_int = (long_object -> long_value .lv_tag & IMMORTALITY_BIT_MASK ) != 0 ;
3659
+ assert ((!is_small_int ) || PyLong_CheckExact (op ));
3660
+ return is_small_int ;
3666
3661
}
3667
3662
3668
3663
void
3669
3664
_PyLong_ExactDealloc (PyObject * self )
3670
3665
{
3671
3666
assert (PyLong_CheckExact (self ));
3667
+ if (_long_is_small_int (self )) {
3668
+ // See PEP 683, section Accidental De-Immortalizing for details
3669
+ _Py_SetImmortal (self );
3670
+ return ;
3671
+ }
3672
3672
if (_PyLong_IsCompact ((PyLongObject * )self )) {
3673
- #ifndef Py_GIL_DISABLED
3674
- if (compact_int_is_small (self )) {
3675
- // See PEP 683, section Accidental De-Immortalizing for details
3676
- _Py_SetImmortal (self );
3677
- return ;
3678
- }
3679
- #endif
3680
3673
_Py_FREELIST_FREE (ints , self , PyObject_Free );
3681
3674
return ;
3682
3675
}
@@ -3686,24 +3679,20 @@ _PyLong_ExactDealloc(PyObject *self)
3686
3679
static void
3687
3680
long_dealloc (PyObject * self )
3688
3681
{
3689
- assert (self );
3690
- if (_PyLong_IsCompact ((PyLongObject * )self )) {
3691
- if (compact_int_is_small (self )) {
3692
- /* This should never get called, but we also don't want to SEGV if
3693
- * we accidentally decref small Ints out of existence. Instead,
3694
- * since small Ints are immortal, re-set the reference count.
3695
- *
3696
- * See PEP 683, section Accidental De-Immortalizing for details
3697
- */
3698
- _Py_SetImmortal (self );
3699
- return ;
3700
- }
3701
- if (PyLong_CheckExact (self )) {
3702
- _Py_FREELIST_FREE (ints , self , PyObject_Free );
3703
- return ;
3704
- }
3682
+ if (_long_is_small_int (self )) {
3683
+ /* This should never get called, but we also don't want to SEGV if
3684
+ * we accidentally decref small Ints out of existence. Instead,
3685
+ * since small Ints are immortal, re-set the reference count.
3686
+ *
3687
+ * See PEP 683, section Accidental De-Immortalizing for details
3688
+ */
3689
+ _Py_SetImmortal (self );
3690
+ return ;
3691
+ }
3692
+ if (PyLong_CheckExact (self ) && _PyLong_IsCompact ((PyLongObject * )self )) {
3693
+ _Py_FREELIST_FREE (ints , self , PyObject_Free );
3694
+ return ;
3705
3695
}
3706
-
3707
3696
Py_TYPE (self )-> tp_free (self );
3708
3697
}
3709
3698
@@ -6065,7 +6054,7 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase)
6065
6054
return NULL ;
6066
6055
}
6067
6056
assert (PyLong_Check (newobj ));
6068
- newobj -> long_value .lv_tag = tmp -> long_value .lv_tag ;
6057
+ newobj -> long_value .lv_tag = tmp -> long_value .lv_tag & ~ IMMORTALITY_BIT_MASK ;
6069
6058
for (i = 0 ; i < n ; i ++ ) {
6070
6059
newobj -> long_value .ob_digit [i ] = tmp -> long_value .ob_digit [i ];
6071
6060
}
0 commit comments