aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/frame.c
Commit message (Collapse)AuthorAge
* gh-131173: Improve exception handling during take_ownership processing (#132620)Alper2025-04-17
| | | | | | Save and restore exceptions during take_ownership processing to preserve exceptions currently being raised. Co-authored-by: alperyoney <alperyoney@fb.com>
* gh-128421: Avoid TSAN warnings in `sys._current_frames()` (gh-131548)Sam Gross2025-03-24
| | | | | | | | | | | | This tells TSAN not to sanitize `PyUnstable_InterpreterFrame_GetLine()`. There's a possible data race on the access to the frame's `instr_ptr` if the frame is currently executing. We don't really care about the race. In theory, we could use relaxed atomics for every access to `instr_ptr`, but that would create more code churn and current compilers are overly conservative with optimizations around relaxed atomic accesses. We also don't sanitize `_PyFrame_IsIncomplete()` because it accesses `instr_ptr` and is called from assertions within PyFrame_GetCode().
* gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h (#131560)Victor Stinner2025-03-21
| | | | | | | * Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h. * Remove pycore_interpframe.h include from pycore_genobject.h. * Remove now useless includes from C files. * Add pycore_interpframe_structs.h to Makefile.pre.in and pythoncore.vcxproj.
* gh-128421: Add locking to most frame object functions (gh-131479)Sam Gross2025-03-21
| | | | | | | | | This makes more operations on frame objects thread-safe in the free threaded build, which fixes some data races that occurred when passing exceptions between threads. However, accessing local variables from another thread while its running is still not thread-safe and may crash the interpreter.
* GH-131238: More refactoring of core header files (GH-131351)Mark Shannon2025-03-17
| | | | Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
* GH-127705: Use `_PyStackRef`s in the default build. (GH-127875)Mark Shannon2025-03-10
|
* GH-128563: Add new frame owner type for interpreter entry frames (GH-129078)Mark Shannon2025-01-21
| | | Add new frame owner type for interpreter entry frames
* Remove asserts that confuse `enum _framestate` with `enum _frameowner` ↵Anders Kaseorg2025-01-02
| | | | | | | | | | | | (GH-124148) The `owner` field of `_PyInterpreterFrame` is supposed to be a member of `enum _frameowner`, but `FRAME_CLEARED` is a member of `enum _framestate`. At present, it happens that `FRAME_CLEARED` is not numerically equal to any member of `enum _frameowner`, but that could change in the future. The code that incorrectly assigned `owner = FRAME_CLEARED` was deleted in commit a53cc3f49463e50cb3e2b839b3a82e6bf7f73fee (GH-116687). Remove the incorrect checks for `owner != FRAME_CLEARED` as well.
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-04
| | | | | | | | | `BINARY_OP` (#123926) Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads. Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization. Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
* gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (#124026)Sam Gross2024-09-24
| | | | | | Use a `_PyStackRef` and defer the reference to `f_funcobj` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
* gh-123923: Defer refcounting for `f_executable` in `_PyInterpreterFrame` ↵Sam Gross2024-09-12
| | | | | | | | (#123924) Use a `_PyStackRef` and defer the reference to `f_executable` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
* gh-117139: Garbage collector support for deferred refcounting (#122956)Sam Gross2024-08-15
| | | | | | | | | | The free-threaded GC now visits interpreter stacks to keep objects that use deferred reference counting alive. Interpreter frames are zero initialized in the free-threaded GC so that the GC doesn't see garbage data. This is a temporary measure until stack spilling around escaping calls is implemented. Co-authored-by: Ken Jin <kenjin@python.org>
* GH-120024: Use pointer for stack pointer (GH-121923)Mark Shannon2024-07-18
|
* gh-117139: Convert the evaluation stack to stack refs (#118450)Ken Jin2024-06-27
| | | | | | | | | | | | | | | | | This PR sets up tagged pointers for CPython. The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly. Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out. This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it. The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs. Please read Include/internal/pycore_stackref.h for more information! --------- Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
* gh-120834: fix type of *_iframe field in _PyGenObject_HEAD declaration (#120835)Irit Katriel2024-06-24
|
* gh-118272: set stacktop to 0 before freeing contents, to avoid access to ↵Irit Katriel2024-05-01
| | | | invalid objects during GC (#118478)
* gh-118272: Clear generator frame's locals when the generator is closed (#118277)Irit Katriel2024-04-30
| | | Co-authored-by: Thomas Grainger <tagrain@gmail.com>
* GH-118095: Handle `RETURN_GENERATOR` in tier 2 (GH-118180)Mark Shannon2024-04-25
|
* GH-116098: Remove dead frame object creation code (GH-116687)Tian Gao2024-03-12
|
* Remove unused Py_XDECREF from _PyFrame_ClearExceptCode (GH-106158)Anders Kaseorg2024-02-01
| | | | | | frame->frame_obj was set to NULL a few lines earlier. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
* gh-109094: replace frame->prev_instr by frame->instr_ptr (#109095)Irit Katriel2023-10-26
|
* gh-107149: Make PyUnstable_ExecutableKinds public (#108440)Victor Stinner2023-08-31
| | | | | | Move PyUnstable_ExecutableKinds and associated macros from the internal C API to the public C API. Rename constants: replace "PY_" prefix with "PyUnstable_" prefix.
* GH-108035: Remove the `_PyCFrame` struct as it is no longer needed for ↵Mark Shannon2023-08-17
| | | | performance. (GH-108036)
* GH-100987: Allow objects other than code objects as the "executable" of an ↵Mark Shannon2023-06-14
| | | | | | | | | | internal frame. (GH-105727) * Add table describing possible executable classes for out-of-process debuggers. * Remove shim code object creation code as it is no longer needed. * Make lltrace a bit more robust w.r.t. non-standard frames.
* GH-96803: Document and test new unstable internal frame API functions ↵Mark Shannon2023-05-18
| | | | | | (GH-104211) Weaken contract of PyUnstable_InterpreterFrame_GetCode to return PyObject*.
* GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque ↵Mark Shannon2023-05-05
| | | | for users of PEP 523. (GH-96849)
* gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-02-28
| | | | (in Python/) (#102193)
* GH-100719: Remove redundant `gi_code` field from generator object. (GH-100749)Mark Shannon2023-02-23
|
* GH-100126: Skip incomplete frames in more places (GH-100613)Brandt Bucher2023-01-09
|
* GH-99729: Unlink frames before clearing them (GH-100030)Brandt Bucher2022-12-06
|
* GH-96421: Insert shim frame on entry to interpreter (GH-96319)Mark Shannon2022-11-10
| | | | | | * Adds EXIT_INTERPRETER instruction to exit PyEval_EvalDefault() * Simplifies RETURN_VALUE, YIELD_VALUE and RETURN_GENERATOR instructions as they no longer need to check for entry frames.
* GH-97002: Prevent `_PyInterpreterFrame`s from backing more than one ↵Brandt Bucher2022-10-07
| | | | `PyFrameObject` (GH-97996)
* GH-97779: Ensure that *all* frame objects are backed by "complete" frames ↵Brandt Bucher2022-10-04
| | | | (GH-97845)
* GH-97752: Clear the `previous` member of newly-created generator/coroutine ↵Brandt Bucher2022-10-04
| | | | frames (GH-97795)
* GH-96237: Allow non-functions as reference-holder in frames. (GH-96238)Mark Shannon2022-08-25
|
* GH-94262: Don't create frame objects for frames that aren't yet complete. ↵Mark Shannon2022-07-01
| | | | (GH-94371)
* GH-93897: Store frame size in code object and de-opt if insufficient space ↵Mark Shannon2022-06-20
| | | | on thread frame stack. (GH-93908)
* gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)Victor Stinner2022-06-19
| | | | | | | | | | | | | | | | Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions: * PyFrame_Check() * PyFrame_GetBack() * PyFrame_GetBuiltins() * PyFrame_GetGenerator() * PyFrame_GetGlobals() * PyFrame_GetLasti() * PyFrame_GetLocals() * PyFrame_Type Remove #include "frameobject.h" from many C files. It's no longer needed.
* Split refcount stats into 'interpreter' and 'non-interpreter' (GH-92919)Mark Shannon2022-05-18
|
* bpo-47177: Replace `f_lasti` with `prev_instr` (GH-32208)Brandt Bucher2022-04-07
|
* bpo-47045: Remove `f_state` field (GH-31963)Mark Shannon2022-03-22
| | | | | * Remove the f_state field from _PyInterpreterFrame * Make ownership of the frame explicit, replacing the is_generator field with an owner field.
* bpo-46836: Rename InterpreterFrame to _PyInterpreterFrame (GH-31583)Victor Stinner2022-02-25
| | | | | Rename also struct _interpreter_frame to struct _PyInterpreterFrame. Reduce risk of name conflicts if a project includes pycore_frame.h.
* Pass reference to func, as well as args, when pushing frame. (GH-31100)Mark Shannon2022-02-03
|
* bpo-46072: Add some frame stats. (GH-31060)Mark Shannon2022-02-02
|
* bpo-46329: Split calls into precall and call instructions. (GH-30855)Mark Shannon2022-01-28
| | | | | | | | | | | | | | * Add PRECALL_FUNCTION opcode. * Move 'call shape' varaibles into struct. * Replace CALL_NO_KW and CALL_KW with KW_NAMES and CALL instructions. * Specialize for builtin methods taking using the METH_FASTCALL | METH_KEYWORDS protocol. * Allow kwnames for specialized calls to builtin types. * Specialize calls to tuple(arg) and str(arg).
* bpo-46409: Make generators in bytecode (GH-30633)Mark Shannon2022-01-20
| | | | | | | | | | | | * Add RETURN_GENERATOR and JUMP_NO_INTERRUPT opcodes. * Trim frame and generator by word each. * Minor refactor of frame.c * Update test.test_sys to account for smaller frames. * Treat generator functions as normal functions when evaluating and specializing.
* bpo-45963: Make space for the InterpreterFrame of a generator in that ↵Mark Shannon2021-12-06
| | | | | | | generator. (GH-29891) * Make generator, coroutine and async gen structs all the same size. * Store interpreter frame in generator (and coroutine). Reduces the number of allocations neeeded for a generator from two to one.
* bpo-45786: Allocate space for frame in frame object. (GH-29729)Mark Shannon2021-11-29
|
* bpo-44525: Copy free variables in bytecode to allow calls to inner functions ↵Mark Shannon2021-11-23
| | | | | | | | | | | to be specialized (GH-29595) * Make internal APIs that take PyFrameConstructor take a PyFunctionObject instead. * Add reference to function to frame, borrow references to builtins and globals. * Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
* bpo-45813: Make sure that frame->generator is NULLed when generator is ↵Mark Shannon2021-11-22
| | | | deallocated. (GH-29700)