summaryrefslogtreecommitdiffstats
path: root/Objects/frameobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-031-12/+16
| | | | | | | | | | | | | | | | | | * Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-041-6/+8
| | | | | | | | | `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-125837: Split `LOAD_CONST` into three. (GH-125972)Mark Shannon2024-10-291-2/+0
| | | | | | | | * Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
* gh-124218: Avoid refcount contention on builtins module (GH-125847)Sam Gross2024-10-241-20/+4
| | | | | | | This replaces `_PyEval_BuiltinsFromGlobals` with `_PyDict_LoadBuiltinsFromGlobals`, which returns a new reference instead of a borrowed reference. Internally, the new function uses per-thread reference counting when possible to avoid contention on the refcount fields on the builtins module.
* gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals ↵Tian Gao2024-10-211-6/+70
| | | | (#125616)
* gh-124513: Check args in framelocalsproxy_new() (#124515)Victor Stinner2024-09-251-3/+20
| | | | Fix a crash in FrameLocalsProxy constructor: check the number of arguments.
* gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (#124026)Sam Gross2024-09-241-4/+5
| | | | | | 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-121-6/+1
| | | | | | | | (#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-118093: Make `CALL_ALLOC_AND_ENTER_INIT` suitable for tier 2. (GH-123140)Mark Shannon2024-08-201-2/+1
| | | | | * Convert CALL_ALLOC_AND_ENTER_INIT to micro-ops such that tier 2 supports it * Allow inexact arguments for CALL_ALLOC_AND_ENTER_INIT.
* GH-122390: Replace `_Py_GetbaseOpcode` with `_Py_GetBaseCodeUnit` (GH-122942)Mark Shannon2024-08-131-8/+9
|
* gh-122058: `Lib/inspect`: Update docstrings for `isfunction`, `isgenerator`, ↵Kirill Podoprigora2024-08-061-1/+1
| | | | | | `isframe`, `iscode`. (#122059) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-120906: Support arbitrary hashable keys in FrameLocalsProxy (GH-122309)Petr Viktorin2024-07-301-60/+80
| | | Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* GH-120024: Use pointer for stack pointer (GH-121923)Mark Shannon2024-07-181-11/+13
|
* gh-118934: Make PyEval_GetLocals return borrowed reference (#119769)Tian Gao2024-07-161-0/+4
| | | Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* gh-117139: Convert the evaluation stack to stack refs (#118450)Ken Jin2024-06-261-28/+29
| | | | | | | | | | | | | | | | | 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-241-3/+3
|
* GH-120097: Make FrameLocalsProxy a mapping (#120101)Mark Shannon2024-06-191-1/+1
| | | | | * Register FrameLocalsProxy as a subclass of collections.abc.Mapping * Allow FrameLocalsProxy to matching mapping patterns
* gh-74929: PEP 667 C API documentation (gh-119379)Alyssa Coghlan2024-06-011-2/+7
| | | | | | | | * Add docs for new APIs * Add soft-deprecation notices * Add What's New porting entries * Update comments referencing `PyFrame_LocalsToFast()` to mention the proxy instead * Other related cleanups found when looking for refs to the deprecated APIs
* gh-109176: replace _PyFrame_OpAlreadyRan by an assertion that the frame is ↵Irit Katriel2024-05-211-33/+2
| | | | complete. (#119234)
* gh-118921: Add `copy()` method for `FrameLocalsProxy` (#118923)Tian Gao2024-05-101-0/+19
|
* gh-118746: Fix crash in frame_getlocals and _PyFrame_GetLocals (#118748)Tian Gao2024-05-081-0/+18
| | | | We don't know how to create an unoptimized frame with f_locals == NULL, but they are seen in the wild, and this fixes the crash.
* GH-115709: Invalidate executors when a local variable is changed via ↵Mark Shannon2024-05-061-1/+2
| | | | | frame.f_locals (#118639) Also fix unrelated assert in debug Tier2/JIT builds.
* gh-118609: Add proper error check for framelocalsproxy (#118615)Tian Gao2024-05-061-46/+99
|
* gh-74929: Make containment checks more efficient in `FrameLocalsProxy` (#118624)Tian Gao2024-05-061-10/+19
| | | Properly implement the `sq_contains` slot for frame locals proxy containment checks.
* gh-118605: Fix reference leak in FrameLocalsProxy (#118607)Tian Gao2024-05-051-3/+28
| | | Also add some error checks.
* gh-74929: Remove undesirable DECREF in PEP 667 implementation (#118583)Tian Gao2024-05-051-1/+0
| | | | With tests.
* gh-74929: Implement PEP 667 (GH-115153)Tian Gao2024-05-041-199/+661
|
* gh-107674: Lazy load line number to improve performance of tracing (GH-118127)Tian Gao2024-04-291-4/+12
|
* GH-118095: Handle `RETURN_GENERATOR` in tier 2 (GH-118180)Mark Shannon2024-04-251-5/+0
|
* gh-115756: make PyCode_GetFirstFree an unstable API (GH-115781)Bogdan Romanyuk2024-03-191-1/+1
|
* gh-113939: Frame clear, clear locals (#113940)Albert Zeyer2024-01-311-0/+1
|
* gh-111375: Use `NULL` rather than `None` in the exception stack to indicate ↵Carey Metcalfe2023-12-211-1/+1
| | | | that an exception was handled (#113302)
* gh-79932: raise exception if frame.clear() is called on a suspended frame ↵Irit Katriel2023-11-071-0/+7
| | | | (#111792)
* simplify code to pop exception in frame_setlineno (#111702)Irit Katriel2023-11-061-5/+2
|
* gh-103615: Use local events for opcode tracing (GH-109472)Tian Gao2023-11-031-1/+7
| | | | | | | * Use local monitoring for opcode trace * Remove f_opcode_trace_set * Add test for setting f_trace_opcodes after settrace
* gh-111354: Simplify _PyGen_yf by moving some of its work to the compiler and ↵Irit Katriel2023-11-031-1/+1
| | | | frame state (#111648)
* gh-109094: replace frame->prev_instr by frame->instr_ptr (#109095)Irit Katriel2023-10-261-4/+4
|
* GH-94438: Restore ability to jump over None tests (GH-111237)Savannah Ostrowski2023-10-241-0/+2
|
* GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)Brandt Bucher2023-09-131-12/+2
|
* gh-108732: include comprehension locals in frame.f_locals (#109026)Carl Meyer2023-09-071-4/+10
| | | | Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-108991: replace _PyFrame_GetState by two simpler functions (#108992)Irit Katriel2023-09-061-31/+20
|
* gh-105481: remove regen-opcode. Generated _PyOpcode_Caches in regen-cases. ↵Irit Katriel2023-08-231-2/+1
| | | | (#108367)
* gh-105481: generate op IDs from bytecode.c instead of hard coding them in ↵Irit Katriel2023-08-161-0/+2
| | | | opcode.py (#107971)
* gh-106092: Fix use-after-free crash in frame_dealloc (#106875)Anders Kaseorg2023-08-011-6/+7
| | | | | | | | | It was possible for the trashcan to delay the deallocation of a PyFrameObject until after its corresponding _PyInterpreterFrame has already been freed. So frame_dealloc needs to avoid dereferencing the f_frame pointer unless it first checks that the pointer still points to the interpreter frame within the frame object. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-105340: include hidden fast-locals in locals() (#105715)Carl Meyer2023-07-051-5/+60
| | | * gh-105340: include hidden fast-locals in locals()
* Fix duplicate word typos in comments (#106225)Md Sadman Chowdhury2023-07-011-1/+1
|
* GH-100987: Allow objects other than code objects as the "executable" of an ↵Mark Shannon2023-06-141-19/+20
| | | | | | | | | | 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-104584: Plugin optimizer API (GH-105100)Mark Shannon2023-06-021-1/+1
|
* GH-103082: Filter LINE events in VM, to simplify tool implementation. ↵Mark Shannon2023-05-121-3/+0
| | | | | | | | (GH-104387) When monitoring LINE events, instrument all instructions that can have a predecessor on a different line. Then check that the a new line has been hit in the instrumentation code. This brings the behavior closer to that of 3.11, simplifying implementation and porting of tools.