Skip to content

Commit 77db5c3

Browse files
Revert "gh-143050: Remove redundant decref in _PyLong_Negate (gh-143051)"
This reverts commit 5197ecb.
1 parent f105265 commit 77db5c3

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Objects/longobject.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ _Py_DECREF_INT(PyLongObject *op)
4848
_Py_DECREF_SPECIALIZED((PyObject *)op, _PyLong_ExactDealloc);
4949
}
5050

51-
static inline int
52-
/// Return 1 if the object is one of the immortal small ints
53-
_long_is_small_int(PyObject *op)
54-
{
55-
assert(PyLong_Check(op));
56-
PyLongObject *long_object = (PyLongObject *)op;
57-
int is_small_int = (long_object->long_value.lv_tag & IMMORTALITY_BIT_MASK) != 0;
58-
assert((!is_small_int) || PyLong_CheckExact(op));
59-
return is_small_int;
60-
}
61-
6251
static inline int
6352
is_medium_int(stwodigits x)
6453
{
@@ -355,6 +344,8 @@ medium_from_stwodigits(stwodigits x)
355344
}
356345

357346

347+
/* If a freshly-allocated int is already shared, it must
348+
be a small integer, so negating it must go to PyLong_FromLong */
358349
Py_LOCAL_INLINE(void)
359350
_PyLong_Negate(PyLongObject **x_p)
360351
{
@@ -366,10 +357,8 @@ _PyLong_Negate(PyLongObject **x_p)
366357
return;
367358
}
368359

369-
/* If a freshly-allocated int is already shared, it must
370-
be a small integer, so negating it will fit a single digit */
371-
assert(_long_is_small_int((PyObject *)x));
372-
*x_p = (PyLongObject *)_PyLong_FromSTwoDigits(-medium_value(x));
360+
*x_p = _PyLong_FromSTwoDigits(-medium_value(x));
361+
Py_DECREF(x);
373362
}
374363

375364
#define PYLONG_FROM_INT(UINT_TYPE, INT_TYPE, ival) \
@@ -3633,6 +3622,16 @@ long_richcompare(PyObject *self, PyObject *other, int op)
36333622
Py_RETURN_RICHCOMPARE(result, 0, op);
36343623
}
36353624

3625+
static inline int
3626+
/// Return 1 if the object is one of the immortal small ints
3627+
_long_is_small_int(PyObject *op)
3628+
{
3629+
PyLongObject *long_object = (PyLongObject *)op;
3630+
int is_small_int = (long_object->long_value.lv_tag & IMMORTALITY_BIT_MASK) != 0;
3631+
assert((!is_small_int) || PyLong_CheckExact(op));
3632+
return is_small_int;
3633+
}
3634+
36363635
void
36373636
_PyLong_ExactDealloc(PyObject *self)
36383637
{

0 commit comments

Comments
 (0)