]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26811: gc.get_objects() no longer contains a broken tuple with NULL
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 4 May 2016 18:42:05 +0000 (21:42 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 4 May 2016 18:42:05 +0000 (21:42 +0300)
pointer.

Misc/NEWS
Objects/descrobject.c

index 2993c66331009fa61325a1d8e7da258c257176f0..0a9cfa2b6aa33f250af61d8833daa66aa983d114 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
 Core and Builtins
 -----------------
 
+- Issue #26811: gc.get_objects() no longer contains a broken tuple with NULL
+  pointer.
+
 - Issue #20120: Use RawConfigParser for .pypirc parsing,
   removing support for interpolation unintentionally added
   with move to Python 3. Behavior no longer does any
index ac2752ea061688eb3145b1dc99866e04fd0970a3..da68e3be26786541953d95b592b7d122abb614ad 100644 (file)
@@ -1386,27 +1386,27 @@ property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
         return NULL;
     }
     args = cached_args;
-    if (!args || Py_REFCNT(args) != 1) {
-        Py_CLEAR(cached_args);
-        if (!(cached_args = args = PyTuple_New(1)))
+    cached_args = NULL;
+    if (!args) {
+        args = PyTuple_New(1);
+        if (!args)
             return NULL;
+        _PyObject_GC_UNTRACK(args);
     }
-    Py_INCREF(args);
-    assert (Py_REFCNT(args) == 2);
     Py_INCREF(obj);
     PyTuple_SET_ITEM(args, 0, obj);
     ret = PyObject_Call(gs->prop_get, args, NULL);
-    if (args == cached_args) {
-        if (Py_REFCNT(args) == 2) {
-            obj = PyTuple_GET_ITEM(args, 0);
-            PyTuple_SET_ITEM(args, 0, NULL);
-            Py_XDECREF(obj);
-        }
-        else {
-            Py_CLEAR(cached_args);
-        }
+    if (cached_args == NULL && Py_REFCNT(args) == 1) {
+        assert(Py_SIZE(args) == 1);
+        assert(PyTuple_GET_ITEM(args, 0) == obj);
+        cached_args = args;
+        Py_DECREF(obj);
+    }
+    else {
+        assert(Py_REFCNT(args) >= 1);
+        _PyObject_GC_TRACK(args);
+        Py_DECREF(args);
     }
-    Py_DECREF(args);
     return ret;
 }