summaryrefslogtreecommitdiffstats
path: root/Include/cpython/code.h
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-116767: fix crash on 'async with' with many context managers ↵Irit Katriel2024-05-011-1/+1
| | | | | | | | | | | | (GH-118348) (#118477) gh-116767: fix crash on 'async with' with many context managers (GH-118348) Account for `add_stopiteration_handler` pushing a block for `async with`. To allow generator functions that previously almost hit the `CO_MAXBLOCKS` limit by nesting non-async blocks, the limit is increased by 1. This increase allows one more block in non-generator functions. (cherry picked from commit c1bf4874c1e9db2beda1d62c8c241229783c789b)
* [3.12] chore: fix typos (#116345) (#116370)Terry Jan Reedy2024-03-051-1/+1
| | | | Co-authored-by: cui fliter <imcusg@gmail.com> (cherry picked from commit e7ba6e9dbe5433b4a0bcb0658da6a68197c28630)
* [3.12] GH-108390: Prevent non-local events being set with ↵Mark Shannon2023-09-051-6/+13
| | | | | | | | | | | `sys.monitoring.set_local_events()` (GH-108420) (#108899) * GH-108390: Prevent non-local events being set with `sys.monitoring.set_local_events()` (GH-108420) * Restore generated objects * Restore size of monitoring arrays in code object for 3.12 ABI compatibility. * Update ABI file
* [3.12] GH-106897: Add `RERAISE` event to `sys.monitoring`. (GH-107291) ↵Mark Shannon2023-07-281-2/+2
| | | | | | (GH-107346) * Ensures that exception handling events are balanced. Each [re]raise event has a matching unwind/handled event.
* [3.12] GH-103082: Rename PY_MONITORING_EVENTS to _PY_MONITORING_EVENTS ↵Victor Stinner2023-07-221-3/+3
| | | | | | | | | | | | (#107069) (#107075) GH-103082: Rename PY_MONITORING_EVENTS to _PY_MONITORING_EVENTS (#107069) Rename private C API constants: * Rename PY_MONITORING_UNGROUPED_EVENTS to _PY_MONITORING_UNGROUPED_EVENTS * Rename PY_MONITORING_EVENTS to _PY_MONITORING_EVENTS (cherry picked from commit 0927a2b25c059988e237108605ed8ab0c5459c53)
* GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython ↵Mark Shannon2023-04-121-2/+43
| | | | | | | | | | (GH-103083) * The majority of the monitoring code is in instrumentation.c * The new instrumentation bytecodes are in bytecodes.c * legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
* gh-102381: don't call watcher callback with dead object (#102382)Carl Meyer2023-03-081-4/+9
| | | Co-authored-by: T. Wouters <thomas@python.org>
* gh-101101: Unstable C API tier (PEP 689) (GH-101102)Petr Viktorin2023-02-281-8/+39
|
* gh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (GH-101912)Steve Dower2023-02-201-7/+21
| | | | | | * gh-101907: Removes use of non-standard C++ extension from Include/cpython/code.h * Make cases_generator correct on Windows
* GH-100719: Remove the `co_nplaincellvars` field from code objects. (GH-100721)Mark Shannon2023-01-041-1/+5
|
* GH-100222: fix typo _py_set_opocde -> _py_set_opcode (GH-100259)Carl Meyer2022-12-151-1/+1
| | | | | Typo introduced in #100223. Automerge-Triggered-By: GH:brandtbucher
* GH-100222: Redefine _Py_CODEUNIT as a union to clarify structure of code ↵Mark Shannon2022-12-141-14/+17
| | | | unit. (GH-100223)
* GH-98522: Add version number to code objects. (GH-98525)Mark Shannon2022-12-091-0/+1
| | | | | | * Add version number to code object for better versioning of functions. * Improves specialization for closures and list comprehensions.
* GH-91054: Add code object watchers API (GH-99859)Itamar Ostricher2022-12-021-0/+35
| | | | | | * Add API to allow extensions to set callback function on creation and destruction of PyCodeObject Co-authored-by: Ye11ow-Flash <janshah@cs.stonybrook.edu>
* Use _Py_RVALUE() in macros (#99844)Victor Stinner2022-11-281-1/+1
| | | | | | | | | | | | | | The following macros are modified to use _Py_RVALUE(), so they can no longer be used as l-value: * DK_LOG_SIZE() * _PyCode_CODE() * _PyList_ITEMS() * _PyTuple_ITEMS() * _Py_SLIST_HEAD() * _Py_SLIST_ITEM_NEXT() _PyCode_CODE() is private and other macros are part of the internal C API.
* gh-89653: PEP 670: Convert macros to functions (#99843)Victor Stinner2022-11-281-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert macros to static inline functions to avoid macro pitfalls, like duplication of side effects: * DK_ENTRIES() * DK_UNICODE_ENTRIES() * PyCode_GetNumFree() * PyFloat_AS_DOUBLE() * PyInstanceMethod_GET_FUNCTION() * PyMemoryView_GET_BASE() * PyMemoryView_GET_BUFFER() * PyMethod_GET_FUNCTION() * PyMethod_GET_SELF() * PySet_GET_SIZE() * _PyHeapType_GET_MEMBERS() Changes: * PyCode_GetNumFree() casts PyCode_GetNumFree.co_nfreevars from int to Py_ssize_t to be future proof, and because Py_ssize_t is commonly used in the C API. * PyCode_GetNumFree() doesn't cast its argument: the replaced macro already required the exact type PyCodeObject*. * Add assertions in some functions using "CAST" macros to check the arguments type when Python is built with assertions (debug build). * Remove an outdated comment in unicodeobject.h.
* GH-98686: Quicken everything (GH-98687)Brandt Bucher2022-11-021-1/+0
|
* gh-95756: Lazily created cached co_* attrs (GH-97791)Ken Jin2022-10-111-1/+8
|
* gh-94936: C getters: co_varnames, co_cellvars, co_freevars (#95008)Ken Jin2022-08-041-0/+6
|
* gh-93382: Sync up `co_code` changes with 3.11 (GH-94227)Ken Jin2022-06-241-1/+1
| | | Sync up co_code changes with 3.11 commit 852b4d4bcd12b0b6839a015a262ce976b134f6f3.
* gh-87347: Add parenthesis around macro arguments (#93915)Victor Stinner2022-06-201-1/+2
| | | Add unit test on Py_MEMBER_SIZE() and some other macros.
* GH-93516: Speedup line number checks when tracing. (GH-93763)Mark Shannon2022-06-201-1/+3
| | | | * Use a lookup table to reduce overhead of getting line numbers during tracing.
* GH-93897: Store frame size in code object and de-opt if insufficient space ↵Mark Shannon2022-06-201-2/+2
| | | | on thread frame stack. (GH-93908)
* gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815)Victor Stinner2022-06-161-1/+1
|
* GH-93516: Store offset of first traceable instruction in code object (GH-93769)Mark Shannon2022-06-141-0/+1
|
* gh-93382: Cache result of `PyCode_GetCode` in codeobject (GH-93383)Ken Jin2022-06-031-0/+1
| | | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
* gh-92154: Expose PyCode_GetCode in the C API (GH-92168)Ken Jin2022-05-031-0/+3
|
* GH-88116: Use a compact format to represent end line and column offsets. ↵Mark Shannon2022-04-211-13/+19
| | | | | | | | | | | | (GH-91666) * Stores all location info in linetable to conform to PEP 626. * Remove column table from code objects. * Remove end-line table from code objects. * Document new location table format
* bpo-35134: Remove the Include/code.h header file (GH-32385)Victor Stinner2022-04-071-2/+13
| | | | | | Remove the Include/code.h header file. C extensions should only include the main <Python.h> header file. Python.h includes directly Include/cpython/code.h instead.
* bpo-46841: Quicken code in-place (GH-31888)Brandt Bucher2022-03-211-83/+74
| | | | | | | | | | | | | | | | | | | * Moves the bytecode to the end of the corresponding PyCodeObject, and quickens it in-place. * Removes the almost-always-unused co_varnames, co_freevars, and co_cellvars member caches * _PyOpcode_Deopt is a new mapping from all opcodes to their un-quickened forms. * _PyOpcode_InlineCacheEntries is renamed to _PyOpcode_Caches * _Py_IncrementCountAndMaybeQuicken is renamed to _PyCode_Warmup * _Py_Quicken is renamed to _PyCode_Quicken * _co_quickened is renamed to _co_code_adaptive (and is now a read-only memoryview). * Do not emit unused nonzero opargs anymore in the compiler.
* bpo-46841: Add a _Py_SET_OPCODE macro (GH-31780)Brandt Bucher2022-03-121-0/+3
|
* bpo-46841: Use inline caching for calls (GH-31709)Brandt Bucher2022-03-071-1/+1
|
* bpo-45316: Move private PyCode C API to internal C API (GH-31576)Victor Stinner2022-02-251-19/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Rename private functions (no exported), add an underscore prefix: * PyLineTable_InitAddressRange() => _PyLineTable_InitAddressRange() * PyLineTable_NextAddressRange() => _PyLineTable_NextAddressRange() * PyLineTable_PreviousAddressRange() => _PyLineTable_PreviousAddressRange() Move private functions to the internal C API: * _PyCode_Addr2EndLine() * _PyCode_Addr2EndOffset() * _PyCode_Addr2Offset() * _PyCode_InitAddressRange() * _PyCode_InitEndAddressRange( * _PyLineTable_InitAddressRange() * _PyLineTable_NextAddressRange() * _PyLineTable_PreviousAddressRange() No longer export the following internal functions: * _PyCode_GetVarnames() * _PyCode_GetCellvars() * _PyCode_GetFreevars() * _Py_GetSpecializationStats() Add "extern" to pycore_code.h functions to identify them more easiliy (they are still not exported).
* bpo-46841: Use *inline* caching for `BINARY_OP` (GH-31543)Brandt Bucher2022-02-251-1/+1
|
* Remove legacy opcache structs (GH-27164)Ken Jin2021-07-161-2/+0
|
* bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)Gabriele N. Tornetta2021-07-071-4/+5
|
* bpo-43950: Add code.co_positions (PEP 657) (GH-26955)Pablo Galindo2021-07-021-4/+21
| | | | | | | | | | | | | | | This PR is part of PEP 657 and augments the compiler to emit ending line numbers as well as starting and ending columns from the AST into compiled code objects. This allows bytecodes to be correlated to the exact source code ranges that generated them. This information is made available through the following public APIs: * The `co_positions` method on code objects. * The C API function `PyCode_Addr2Location`. Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
* bpo-43693 Get rid of CO_NOFREE -- it's unused (GH-26839)Guido van Rossum2021-06-231-6/+0
| | | | | | All uses of this flag are either setting it or in doc or tests for it. So we should be able to get rid of it completely.
* bpo-43693: Turn localspluskinds into an object (GH-26749)Guido van Rossum2021-06-211-5/+1
| | | Managing it as a bare pointer to malloc'ed bytes is just too awkward in a few places.
* bpo-43693: Eliminate unused "fast locals". (gh-26587)Eric Snow2021-06-151-6/+2
| | | | | Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used. Additionally, using the lower index would be better in some cases, such as with no-arg `super()`. To address this, we update the compiler to fix the offsets so each variable only gets one "fast local". As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function). https://bugs.python.org/issue43693
* bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)Mark Shannon2021-06-141-14/+0
| | | | | | | | | | * Add specializations of LOAD_GLOBAL. * Add more stats. * Remove old opcache; it is no longer used. * Add NEWS
* Add more const modifiers. (GH-26691)Serhiy Storchaka2021-06-121-3/+3
|
* bpo-43693: Un-revert commit f3fa63e. (#26609)Eric Snow2021-06-081-2/+9
| | | | | | | | | This was reverted in GH-26596 (commit 6d518bb) due to some bad memory accesses. * Add the MAKE_CELL opcode. (gh-26396) The memory accesses have been fixed. https://bugs.python.org/issue43693
* Revert "bpo-43693: Add the MAKE_CELL opcode and interleave fast locals ↵Pablo Galindo2021-06-081-9/+2
| | | | | offsets. (gh-26396)" (GH-26597) This reverts commit 631f9938b1604d4f893417ec339b9e0fa9196fb1.
* bpo-43693: Silence some compiler warnings. (gh-26588)Eric Snow2021-06-071-1/+0
| | | | | | | The plan is to eventually make PyCodeObject opaque in the public C-API, with the full struct moved to Include/internal/pycore_code.h. _PyLocalsPlusKinds and _PyLocalsPlusKind started off there but were needed on PyCodeObject, hence the duplication. This led to warnings with some compilers. (Apparently it does not trigger a warning on my install of GCC.) This change eliminates the superfluous typedef. https://bugs.python.org/issue43693
* bpo-43693: Add the MAKE_CELL opcode and interleave fast locals offsets. ↵Eric Snow2021-06-071-2/+9
| | | | | | | (gh-26396) This moves logic out of the frame initialization code and into the compiler and eval loop. Doing so simplifies the runtime code and allows us to optimize it better. https://bugs.python.org/issue43693
* bpo-43693: Un-revert commits 2c1e258 and b2bf2bc. (gh-26577)Eric Snow2021-06-071-6/+18
| | | | | | | | | | These were reverted in gh-26530 (commit 17c4edc) due to refleaks. * 2c1e258 - Compute deref offsets in compiler (gh-25152) * b2bf2bc - Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) This change fixes the refleaks. https://bugs.python.org/issue43693
* bpo-44187: Quickening infrastructure (GH-26264)Mark Shannon2021-06-071-2/+11
| | | | | | | | | | | | | | * Add co_firstinstr field to code object. * Implement barebones quickening. * Use non-quickened bytecode when tracing. * Add NEWS item * Add new file to Windows build. * Don't specialize instructions with EXTENDED_ARG.
* bpo-43693: Revert commits 2c1e2583fdc4db6b43d163239ea42b0e8394171f and ↵Pablo Galindo2021-06-041-15/+5
| | | | | | | | | | | | | b2bf2bc1ece673d387341e06c8d3c2bc6e259747 (GH-26530) * Revert "bpo-43693: Compute deref offsets in compiler (gh-25152)" This reverts commit b2bf2bc1ece673d387341e06c8d3c2bc6e259747. * Revert "bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)" This reverts commit 2c1e2583fdc4db6b43d163239ea42b0e8394171f. These two commits are breaking the refleak buildbots.
* bpo-43693: Add new internal code objects fields: co_fastlocalnames and ↵Eric Snow2021-06-031-5/+15
| | | | | | | | | | | | | | | | | co_fastlocalkinds. (gh-26388) A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs. Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars. At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections. This is something we can easily address in the compiler instead. This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free). These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily). Aside from the (mild) performance impact, there are a number of other benefits: * there's now a clear, direct relationship between locals-plus and variables * code that relies on the locals-plus-to-name mapping is simpler * marshaled code objects are smaller and serialize/de-serialize faster Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs). Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array. It would also allow us to shrink marshaled code objects even further. https://bugs.python.org/issue43693