bpo-40429: PyFrame_GetCode() now returns a strong reference (GH-19773)
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 6b3559e..533186b 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -1237,5 +1237,6 @@
assert(frame != NULL);
PyCodeObject *code = frame->f_code;
assert(code != NULL);
+ Py_INCREF(code);
return code;
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f65f053..8f9ab5c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -8031,7 +8031,6 @@
/* Call super(), without args -- fill in from __class__
and first local variable on the stack. */
PyFrameObject *f;
- PyCodeObject *co;
Py_ssize_t i, n;
f = PyThreadState_GetFrame(_PyThreadState_GET());
if (f == NULL) {
@@ -8039,7 +8038,8 @@
"super(): no current frame");
return -1;
}
- co = PyFrame_GetCode(f);
+ PyCodeObject *co = PyFrame_GetCode(f);
+ Py_DECREF(co); // use a borrowed reference
if (co->co_argcount == 0) {
PyErr_SetString(PyExc_RuntimeError,
"super(): no arguments");