https://github.com/python/cpython/commit/0adc7289c3ab097b5608c0d288d91e1f5f236469
commit: 0adc7289c3ab097b5608c0d288d91e1f5f236469
branch: main
author: Stan Ulbrych <[email protected]>
committer: colesbury <[email protected]>
date: 2026-03-12T21:53:29-04:00
summary:
Revert "gh-143050: Remove redundant decref in _PyLong_Negate (gh-143051)"
(#145891)
OSS Fuzzer caught an assertion failure.
This reverts commit 5197ecb5e4df30ba0f6792d8bc0e36846154f58a.
files:
M Objects/longobject.c
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 185226db43a92a..7ce5d0535b884e 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -48,17 +48,6 @@ _Py_DECREF_INT(PyLongObject *op)
_Py_DECREF_SPECIALIZED((PyObject *)op, _PyLong_ExactDealloc);
}
-static inline int
-/// Return 1 if the object is one of the immortal small ints
-_long_is_small_int(PyObject *op)
-{
- assert(PyLong_Check(op));
- PyLongObject *long_object = (PyLongObject *)op;
- int is_small_int = (long_object->long_value.lv_tag & IMMORTALITY_BIT_MASK)
!= 0;
- assert((!is_small_int) || PyLong_CheckExact(op));
- return is_small_int;
-}
-
static inline int
is_medium_int(stwodigits x)
{
@@ -355,6 +344,8 @@ medium_from_stwodigits(stwodigits x)
}
+/* If a freshly-allocated int is already shared, it must
+ be a small integer, so negating it must go to PyLong_FromLong */
Py_LOCAL_INLINE(void)
_PyLong_Negate(PyLongObject **x_p)
{
@@ -366,10 +357,8 @@ _PyLong_Negate(PyLongObject **x_p)
return;
}
- /* If a freshly-allocated int is already shared, it must
- be a small integer, so negating it will fit a single digit */
- assert(_long_is_small_int((PyObject *)x));
- *x_p = (PyLongObject *)_PyLong_FromSTwoDigits(-medium_value(x));
+ *x_p = _PyLong_FromSTwoDigits(-medium_value(x));
+ Py_DECREF(x);
}
#define PYLONG_FROM_INT(UINT_TYPE, INT_TYPE, ival)
\
@@ -3633,6 +3622,16 @@ long_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_RICHCOMPARE(result, 0, op);
}
+static inline int
+/// Return 1 if the object is one of the immortal small ints
+_long_is_small_int(PyObject *op)
+{
+ PyLongObject *long_object = (PyLongObject *)op;
+ int is_small_int = (long_object->long_value.lv_tag & IMMORTALITY_BIT_MASK)
!= 0;
+ assert((!is_small_int) || PyLong_CheckExact(op));
+ return is_small_int;
+}
+
void
_PyLong_ExactDealloc(PyObject *self)
{
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]