]> granicus.if.org Git - python/commitdiff
Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
authorMichael W. Hudson <mwh@python.net>
Mon, 2 Aug 2004 14:50:43 +0000 (14:50 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 2 Aug 2004 14:50:43 +0000 (14:50 +0000)
have differing refcount semantics.  If anyone sees a prettier way to
acheive the same ends, then please go for it.

I think this is the first time I've ever used Py_XINCREF.

Python/ceval.c

index 3a462afbed0723b507d0c0a9f7cdc1ec9e781794..6c457e125c1405ff866570c27666ba0b28afa18b 100644 (file)
@@ -1742,8 +1742,10 @@ PyEval_EvalFrame(PyFrameObject *f)
                                             PyObject_REPR(w));
                                break;
                        }
-                       if (PyDict_CheckExact(v))
+                       if (PyDict_CheckExact(v)) {
                                x = PyDict_GetItem(v, w);
+                               Py_XINCREF(x);
+                       }
                        else {
                                x = PyObject_GetItem(v, w);
                                if (x == NULL && PyErr_Occurred()) {
@@ -1763,8 +1765,8 @@ PyEval_EvalFrame(PyFrameObject *f)
                                                break;
                                        }
                                }
+                               Py_INCREF(x);
                        }
-                       Py_INCREF(x);
                        PUSH(x);
                        continue;