summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-03-25 12:57:50 (GMT)
committerGitHub <noreply@github.com>2022-03-25 12:57:50 (GMT)
commitd7163bb35d1ed46bde9affcd4eb267dfd0b703dd (patch)
tree50ced5b75c3e1579c4e23fd7c404ac33c53b7fc3 /Doc
parentb68431fadb3150134ac6ccbf501cdfeaf4c75678 (diff)
downloadcpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.zip
cpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.tar.gz
cpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.tar.bz2
bpo-42197: Don't create `f_locals` dictionary unless we actually need it. (GH-32055)
* `PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer called during profile and tracing. (Contributed by Fabio Zadrozny) * Make accesses to a frame's `f_locals` safe from C code, not relying on calls to `PyFrame_FastToLocals` or `PyFrame_LocalsToFast`. * Document new `PyFrame_GetLocals` C-API function.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/frame.rst11
-rw-r--r--Doc/whatsnew/3.11.rst8
2 files changed, 18 insertions, 1 deletions
diff --git a/Doc/c-api/frame.rst b/Doc/c-api/frame.rst
index 0e36e6e..0c11bc1 100644
--- a/Doc/c-api/frame.rst
+++ b/Doc/c-api/frame.rst
@@ -41,6 +41,17 @@ See also :ref:`Reflection <reflection>`.
.. versionadded:: 3.9
+.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
+
+ Get the *frame*'s ``f_locals`` attribute (:class:`dict`).
+
+ Return a :term:`strong reference`.
+
+ *frame* must not be ``NULL``.
+
+ .. versionadded:: 3.11
+
+
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
Return the line number that *frame* is currently executing.
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index b2fdb48..8c120ec 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -969,7 +969,7 @@ Porting to Python 3.11
Code using ``f_lasti`` with ``PyCode_Addr2Line()`` must use
:c:func:`PyFrame_GetLineNumber` instead.
* ``f_lineno``: use :c:func:`PyFrame_GetLineNumber`
- * ``f_locals``: use ``PyObject_GetAttrString((PyObject*)frame, "f_locals")``.
+ * ``f_locals``: use :c:func:`PyFrame_GetLocals`.
* ``f_stackdepth``: removed.
* ``f_state``: no public API (renamed to ``f_frame.f_state``).
* ``f_trace``: no public API.
@@ -983,6 +983,12 @@ Porting to Python 3.11
computed lazily. The :c:func:`PyFrame_GetBack` function must be called
instead.
+ Debuggers that accessed the ``f_locals`` directly *must* call
+ `:c:func:`PyFrame_GetLocals` instead. They no longer need to call
+ `:c:func:`PyFrame_FastToLocalsWithError` or :c:func:`PyFrame_LocalsToFast`,
+ in fact they should not call those functions. The necessary updating of the
+ frame is now managed by the virtual machine.
+
Code defining ``PyFrame_GetCode()`` on Python 3.8 and older::
#if PY_VERSION_HEX < 0x030900B1