summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-01 16:56:30 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-01 16:56:30 (GMT)
commit48aa4b15843ba5e2eab3c4295e4e81df26f1192a (patch)
tree73dd328616c8d36160c50ef198b53568c87a0875 /Objects/longobject.c
parentcd5da7d51b43474c2870f7f44c1a1048c9c3139d (diff)
downloadcpython-48aa4b15843ba5e2eab3c4295e4e81df26f1192a.zip
cpython-48aa4b15843ba5e2eab3c4295e4e81df26f1192a.tar.gz
cpython-48aa4b15843ba5e2eab3c4295e4e81df26f1192a.tar.bz2
Get the ref counting for static allocated longs right.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index fe9bf8e..1d4b502 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3714,17 +3714,15 @@ _PyLong_Init(void)
/* The element is already initialized, most likely
* the Python interpreter was initialized before.
*/
- /* _Py_NewReference((PyObject*)v);
- * XXX: It sets the ref count to 1 but it may be
- * larger. Emulate new reference w/o setting refcnt
- * to 1.
- */
+ Py_ssize_t refcnt;
PyObject* op = (PyObject*)v;
- _Py_INC_REFTOTAL;
- op->ob_refcnt = (op->ob_refcnt < 1) ? 1 : op->ob_refcnt;
- _Py_AddToAllObjects(op, 1);
- _Py_INC_TPALLOCS(op);
+ refcnt = Py_REFCNT(op) < 0 ? 0 : Py_REFCNT(op);
+ _Py_NewReference(op);
+ /* _Py_NewReference sets the ref count to 1 but
+ * the ref count might be larger. Set the refcnt
+ * to the original refcnt + 1 */
+ Py_REFCNT(op) = refcnt + 1;
assert(Py_SIZE(op) == size);
assert(v->ob_digit[0] == abs(ival));
}