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.
This commit is contained in:
Mark Shannon 2022-03-25 12:57:50 +00:00 committed by GitHub
parent b68431fadb
commit d7163bb35d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 10 deletions

View file

@ -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.