Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48aa4b1

Browse files
committed
Get the ref counting for static allocated longs right.
1 parent cd5da7d commit 48aa4b1

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

Objects/longobject.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,17 +3714,15 @@ _PyLong_Init(void)
37143714
/* The element is already initialized, most likely
37153715
* the Python interpreter was initialized before.
37163716
*/
3717-
/* _Py_NewReference((PyObject*)v);
3718-
* XXX: It sets the ref count to 1 but it may be
3719-
* larger. Emulate new reference w/o setting refcnt
3720-
* to 1.
3721-
*/
3717+
Py_ssize_t refcnt;
37223718
PyObject* op = (PyObject*)v;
3723-
_Py_INC_REFTOTAL;
3724-
op->ob_refcnt = (op->ob_refcnt < 1) ? 1 : op->ob_refcnt;
3725-
_Py_AddToAllObjects(op, 1);
3726-
_Py_INC_TPALLOCS(op);
37273719

3720+
refcnt = Py_REFCNT(op) < 0 ? 0 : Py_REFCNT(op);
3721+
_Py_NewReference(op);
3722+
/* _Py_NewReference sets the ref count to 1 but
3723+
* the ref count might be larger. Set the refcnt
3724+
* to the original refcnt + 1 */
3725+
Py_REFCNT(op) = refcnt + 1;
37283726
assert(Py_SIZE(op) == size);
37293727
assert(v->ob_digit[0] == abs(ival));
37303728
}

0 commit comments

Comments
 (0)