bpo-40421: Add PyFrame_GetCode() function (GH-19757)
PyFrame_GetCode(frame): return a borrowed reference to the frame
code.
Replace frame->f_code with PyFrame_GetCode(frame) in most code,
except in frameobject.c, genobject.c and ceval.c.
Also add PyFrame_GetLineNumber() to the limited C API.
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 435808f..afde3db 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -1074,8 +1074,10 @@
.. c:function:: PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
- Get the current frame of the Python thread state *tstate*. It can be
- ``NULL`` if no frame is currently executing.
+ Get a borrowed reference to the current frame of the Python thread state
+ *tstate*.
+
+ Return ``NULL`` if no frame is currently executing.
See also :c:func:`PyEval_GetFrame`.
diff --git a/Doc/c-api/reflection.rst b/Doc/c-api/reflection.rst
index 498219f..b313ea3 100644
--- a/Doc/c-api/reflection.rst
+++ b/Doc/c-api/reflection.rst
@@ -31,6 +31,15 @@
See also :c:func:`PyThreadState_GetFrame`.
+.. c:function:: int PyFrame_GetCode(PyFrameObject *frame)
+
+ Return a borrowed reference to the *frame* code.
+
+ *frame* must not be ``NULL``.
+
+ .. versionadded:: 3.9
+
+
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
Return the line number that *frame* is currently executing.