summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-28 17:01:31 (GMT)
committerGitHub <noreply@github.com>2020-04-28 17:01:31 (GMT)
commita42ca74fa30227e2f89a619332557cf093a937d5 (patch)
treea3097e76897d8f8a0f054cab0736fd3cff80f8da /Doc
parentb8f704d2190125a7750b50cd9b67267b9c20fd43 (diff)
downloadcpython-a42ca74fa30227e2f89a619332557cf093a937d5.zip
cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.gz
cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.bz2
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.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/init.rst6
-rw-r--r--Doc/c-api/reflection.rst9
-rw-r--r--Doc/whatsnew/3.9.rst4
3 files changed, 17 insertions, 2 deletions
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 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
.. 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 @@ Reflection
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.
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 8b8aa9a..e3751fa 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -537,6 +537,10 @@ Optimizations
Build and C API Changes
=======================
+* New :c:func:`PyFrame_GetCode` function: return a borrowed reference to the
+ frame code.
+ (Contributed by Victor Stinner in :issue:`40421`.)
+
* Add :c:func:`PyFrame_GetLineNumber` to the limited C API.
(Contributed by Victor Stinner in :issue:`40421`.)