Skip to content

Commit 7822f15

Browse files
Issue #26811: gc.get_objects() no longer contains a broken tuple with NULL
pointer.
1 parent 422cf2b commit 7822f15

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #26811: gc.get_objects() no longer contains a broken tuple with NULL
14+
pointer.
15+
1316
- Issue #20120: Use RawConfigParser for .pypirc parsing,
1417
removing support for interpolation unintentionally added
1518
with move to Python 3. Behavior no longer does any

‎Objects/descrobject.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,27 +1386,27 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
13861386
return NULL;
13871387
}
13881388
args = cached_args;
1389-
if (!args || Py_REFCNT(args) != 1) {
1390-
Py_CLEAR(cached_args);
1391-
if (!(cached_args = args = PyTuple_New(1)))
1389+
cached_args = NULL;
1390+
if (!args) {
1391+
args = PyTuple_New(1);
1392+
if (!args)
13921393
return NULL;
1394+
_PyObject_GC_UNTRACK(args);
13931395
}
1394-
Py_INCREF(args);
1395-
assert (Py_REFCNT(args) == 2);
13961396
Py_INCREF(obj);
13971397
PyTuple_SET_ITEM(args, 0, obj);
13981398
ret = PyObject_Call(gs->prop_get, args, NULL);
1399-
if (args == cached_args) {
1400-
if (Py_REFCNT(args) == 2) {
1401-
obj = PyTuple_GET_ITEM(args, 0);
1402-
PyTuple_SET_ITEM(args, 0, NULL);
1403-
Py_XDECREF(obj);
1404-
}
1405-
else {
1406-
Py_CLEAR(cached_args);
1407-
}
1399+
if (cached_args == NULL && Py_REFCNT(args) == 1) {
1400+
assert(Py_SIZE(args) == 1);
1401+
assert(PyTuple_GET_ITEM(args, 0) == obj);
1402+
cached_args = args;
1403+
Py_DECREF(obj);
1404+
}
1405+
else {
1406+
assert(Py_REFCNT(args) >= 1);
1407+
_PyObject_GC_TRACK(args);
1408+
Py_DECREF(args);
14081409
}
1409-
Py_DECREF(args);
14101410
return ret;
14111411
}
14121412

0 commit comments

Comments
 (0)