summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_runtime.h
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] Add debug offsets for free threaded builds (GH-123041) (#123055)Miss Islington (bot)2024-08-181-1/+50
| | | | | | | | | | | | * Add debug offsets for free threaded builds (GH-123041) (cherry picked from commit d7a3df91505faa56c51d169648253bd0d57ddae2) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> * Refresh ABI file --------- Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.13] gh-106597: Remove unnecessary CFrame offsets (GH-121369) (#121370)Miss Islington (bot)2024-07-041-7/+0
| | | | | | gh-106597: Remove unnecessary CFrame offsets (GH-121369) (cherry picked from commit f5c8d67de6c68bea2860d5d96af747c5e95dbf22) Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com>
* [3.13] gh-106597: Add more offsets to _Py_DebugOffsets (GH-121311) (#121312)Miss Islington (bot)2024-07-031-0/+10
| | | | | | | | | | | gh-106597: Add more offsets to _Py_DebugOffsets (GH-121311) Add more offsets to _Py_DebugOffsets We add a few more offsets that are required by some out-of-process tools, such as [Austin](https://github.com/p403n1x87/austin). (cherry picked from commit c9bdfbe86853fcf5f2b7dce3a50b383e23384ed2) Co-authored-by: Gabriele N. Tornetta <P403n1x87@users.noreply.github.com>
* [3.13] gh-115773: Add sizes to debug offset structure (GH-120112) (#121283)Miss Islington (bot)2024-07-021-0/+10
| | | | | | gh-115773: Add sizes to debug offset structure (GH-120112) (cherry picked from commit b180788d4a927d23af54f4b4702ccaf254f64854) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-93502: Add new C-API functions to trace object creation and destruction ↵Pablo Galindo Salgado2024-05-021-0/+7
| | | | (#115945)
* gh-115773: Add tests to exercise the _Py_DebugOffsets structure (#115774)Pablo Galindo Salgado2024-02-281-35/+42
|
* gh-112175: Add `eval_breaker` to `PyThreadState` (#115194)Brett Simmers2024-02-201-0/+3
| | | | | | | | | | | This change adds an `eval_breaker` field to `PyThreadState`. The primary motivation is for performance in free-threaded builds: with thread-local eval breakers, we can stop a specific thread (e.g., for an async exception) without interrupting other threads. The source of truth for the global instrumentation version is stored in the `instrumentation_version` field in PyInterpreterState. Threads usually read the version from their local `eval_breaker`, where it continues to be colocated with the eval breaker bits.
* Fix comment in pycore_runtime.h (GH-110540)He Weidong2024-02-011-1/+1
|
* gh-111964: Implement stop-the-world pauses (gh-112471)Sam Gross2024-01-231-0/+7
| | | | | | | | | | | | | | | | | The `--disable-gil` builds occasionally need to pause all but one thread. Some examples include: * Cyclic garbage collection, where this is often called a "stop the world event" * Before calling `fork()`, to ensure a consistent state for internal data structures * During interpreter shutdown, to ensure that daemon threads aren't accessing Python objects This adds the following functions to implement global and per-interpreter pauses: * `_PyEval_StopTheWorldAll()` and `_PyEval_StartTheWorldAll()` (for the global runtime) * `_PyEval_StopTheWorld()` and `_PyEval_StartTheWorld()` (per-interpreter) (The function names may change.) These functions are no-ops outside of the `--disable-gil` build.
* gh-111924: Use PyMutex for Runtime-global Locks. (gh-112207)Sam Gross2023-12-071-2/+2
| | | | | This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize. This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
* gh-112567: Add _Py_GetTicksPerSecond() function (#112587)Victor Stinner2023-12-011-2/+0
| | | | | | | | | | * Move _PyRuntimeState.time to _posixstate.ticks_per_second and time_module_state.ticks_per_second. * Add time_module_state.clocks_per_second. * Rename _PyTime_GetClockWithInfo() to py_clock(). * Rename _PyTime_GetProcessTimeWithInfo() to py_process_time(). * Add process_time_times() helper function, called by py_process_time(). * os.times() is now always built: no longer rely on HAVE_TIMES.
* gh-111956: Add thread-safe one-time initialization. (gh-111960)Sam Gross2023-11-161-1/+0
|
* gh-76785: Crossinterp utils additions (gh-111530)Eric Snow2023-11-011-2/+2
| | | | | | | | | | | | This moves several general internal APIs out of _xxsubinterpretersmodule.c and into the new Python/crossinterp.c (and the corresponding internal headers). Specifically: * _Py_excinfo, etc.: the initial implementation for non-object exception snapshots (in pycore_pyerrors.h and Python/errors.c) * _PyXI_exception_info, etc.: helpers for passing an exception beween interpreters (wraps _Py_excinfo) * _PyXI_namespace, etc.: helpers for copying a dict of attrs between interpreters * _PyXI_Enter(), _PyXI_Exit(): functions that abstract out the transitions between one interpreter and a second that will do some work temporarily Again, these were all abstracted out of _xxsubinterpretersmodule.c as generalizations. I plan on proposing these as public API at some point.
* gh-76785: Move the Cross-Interpreter Code to Its Own File (gh-111502)Eric Snow2023-10-301-0/+1
| | | This is partly to clear this stuff out of pystate.c, but also in preparation for moving some code out of _xxsubinterpretersmodule.c. This change also moves this stuff to the internal API (new: Include/internal/pycore_crossinterp.h). @vstinner did this previously and I undid it. Now I'm re-doing it. :/
* gh-109094: replace frame->prev_instr by frame->instr_ptr (#109095)Irit Katriel2023-10-261-1/+1
|
* gh-109693: Update pyruntimestate._finalizing to use pyatomic.h (gh-110837)Donghee Na2023-10-131-4/+3
|
* gh-110310: Add a Per-Interpreter XID Registry for Heap Types (gh-110311)Eric Snow2023-10-041-4/+1
| | | | | | | | | | | We do the following: * add a per-interpreter XID registry (PyInterpreterState.xidregistry) * put heap types there (keep static types in _PyRuntimeState.xidregistry) * clear the registries during interpreter/runtime finalization * avoid duplicate entries in the registry (when _PyCrossInterpreterData_RegisterClass() is called more than once for a type) * use Py_TYPE() instead of PyObject_Type() in _PyCrossInterpreterData_Lookup() The per-interpreter registry helps preserve isolation between interpreters. This is important when heap types are registered, which is something we haven't been doing yet but I will likely do soon.
* gh-109793: Allow Switching Interpreters During Finalization (gh-109794)Eric Snow2023-09-271-0/+16
| | | Essentially, we should check the thread ID rather than the thread state pointer.
* gh-106213: Make Emscripten trampolines work with JSPI (GH-106219)Hood Chatham2023-09-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | There is a WIP proposal to enable webassembly stack switching which have been implemented in v8: https://github.com/WebAssembly/js-promise-integration It is not possible to switch stacks that contain JS frames so the Emscripten JS trampolines that allow calling functions with the wrong number of arguments don't work in this case. However, the js-promise-integration proposal requires the [type reflection for Wasm/JS API](https://github.com/WebAssembly/js-types) proposal, which allows us to actually count the number of arguments a function expects. For better compatibility with stack switching, this PR checks if type reflection is available, and if so we use a switch block to decide the appropriate signature. If type reflection is unavailable, we should use the current EMJS trampoline. We cache the function argument counts since when I didn't cache them performance was negatively affected. Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: Brett Cannon <brett@python.org>
* gh-107211: No longer export internal functions (7) (#108425)Victor Stinner2023-08-241-0/+3
| | | | | | | | | No longer export _PyUnicode_FromId() internal C API function. Change comment style to "// comment" and add comment explaining why other functions have to be exported. Update Tools/build/generate_token.py to update Include/internal/pycore_token.h comments.
* gh-108216: Cleanup #include in internal header files (#108228)Victor Stinner2023-08-211-7/+6
| | | | | | | | | | | * Add missing includes. * Remove unused includes. * Update old include/symbol names to newer names. * Mention at least one included symbol. * Sort includes. * Update Tools/cases_generator/generate_cases.py used to generated pycore_opcode_metadata.h. * Update Parser/asdl_c.py used to generate pycore_ast.h. * Cleanup also includes in _testcapimodule.c and _testinternalcapi.c.
* GH-108035: Remove the `_PyCFrame` struct as it is no longer needed for ↵Mark Shannon2023-08-171-1/+1
| | | | performance. (GH-108036)
* gh-106931: Intern Statically Allocated Strings Globally (gh-107272)Eric Snow2023-07-271-0/+1
| | | | | We tried this before with a dict and for all interned strings. That ran into problems due to interpreter isolation. However, exclusively using a per-interpreter cache caused some inconsistency that can eliminate the benefit of interning. Here we circle back to using a global cache, but only for statically allocated strings. We also use a more-basic _Py_hashtable_t for that global cache instead of a dict. Ideally we would only have the global cache, but the optional isolation of each interpreter's allocator means that a non-static string object must not outlive its interpreter. Thus we would have to store a copy of each such interned string in the global cache, tied to the main interpreter.
* gh-107211: No longer export internal functions (2) (#107214)Victor Stinner2023-07-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No longer export these 43 internal C API functions: * _PyDict_CheckConsistency() * _PyErr_ChainStackItem() * _PyErr_CheckSignals() * _PyErr_CheckSignalsTstate() * _PyErr_Clear() * _PyErr_ExceptionMatches() * _PyErr_Fetch() * _PyErr_Format() * _PyErr_FormatFromCauseTstate() * _PyErr_GetExcInfo() * _PyErr_GetHandledException() * _PyErr_GetTopmostException() * _PyErr_NoMemory() * _PyErr_NormalizeException() * _PyErr_Restore() * _PyErr_SetHandledException() * _PyErr_SetNone() * _PyErr_SetObject() * _PyErr_SetString() * _PyErr_StackItemToExcInfoTuple() * _PyExc_CreateExceptionGroup() * _PyExc_PrepReraiseStar() * _PyException_AddNote() * _PyInterpreterState_Enable() * _PyLong_FormatAdvancedWriter() * _PyLong_FormatBytesWriter() * _PyLong_FormatWriter() * _PyMem_GetAllocatorName() * _PyMem_SetDefaultAllocator() * _PyMem_SetupAllocators() * _PyOS_InterruptOccurred() * _PyRuntimeState_Fini() * _PyRuntimeState_Init() * _PyRuntime_Finalize() * _PyRuntime_Initialize() * _PyThreadState_Bind() * _PyThreadState_DeleteExcept() * _PyThreadState_New() * _PyThreadState_Swap() * _PyType_CheckConsistency() * _PyUnicodeTranslateError_Create() * _Py_DumpExtensionModules() * _Py_FatalErrorFormat()
* gh-106597: Add debugging struct with offsets for out-of-process tools (#106598)Pablo Galindo Salgado2023-07-111-0/+89
|
* gh-106140: Reorder some fields to facilitate out-of-process inspection (#106143)Pablo Galindo Salgado2023-06-271-8/+14
| | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-100227: Lock Around Adding Global Audit Hooks (gh-105515)Eric Snow2023-06-081-1/+4
| | | The risk of a race with this state is relatively low, but we play it safe anyway.
* Revert "Move observability-relevant structure fields to the top" (#105512)Pablo Galindo Salgado2023-06-081-12/+8
|
* Move observability-relevant structure fields to the top (#105271)Gabriele N. Tornetta2023-06-081-8/+12
|
* gh-99113: A Per-Interpreter GIL! (gh-104210)Eric Snow2023-05-081-2/+0
| | | | | This is the culmination of PEP 684 (and of my 8-year long multi-core Python project)! Each subinterpreter may now be created with its own GIL (via Py_NewInterpreterFromConfig()). If not so configured then the interpreter will share with the main interpreter--the status quo since subinterpreters were added decades ago. The main interpreter always has its own GIL and subinterpreters from Py_NewInterpreter() will always share with the main interpreter.
* gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)Eric Snow2023-04-241-2/+1
| | | | | | | | | | | | | | This is strictly about moving the "obmalloc" runtime state from `_PyRuntimeState` to `PyInterpreterState`. Doing so improves isolation between interpreters, specifically most of the memory (incl. objects) allocated for each interpreter's use. This is important for a per-interpreter GIL, but such isolation is valuable even without it. FWIW, a per-interpreter obmalloc is the proverbial canary-in-the-coalmine when it comes to the isolation of objects between interpreters. Any object that leaks (unintentionally) to another interpreter is highly likely to cause a crash (on debug builds at least). That's a useful thing to know, relative to interpreter isolation.
* gh-95795: Move types.next_version_tag to PyInterpreterState (gh-102343)Eric Snow2023-04-241-7/+2
| | | | | | Core static types will continue to use the global value. All other types will use the per-interpreter value. They all share the same range, where the global types use values < 2^16 and each interpreter uses values higher than that.
* gh-103323: Get the "Current" Thread State from a Thread-Local Variable ↵Eric Snow2023-04-241-3/+0
| | | | | | | | | | | (gh-103324) We replace _PyRuntime.tstate_current with a thread-local variable. As part of this change, we add a _Py_thread_local macro in pyport.h (only for the core runtime) to smooth out the compiler differences. The main motivation here is in support of a per-interpreter GIL, but this change also provides some performance improvement opportunities. Note that we do not provide a fallback to the thread-local, either falling back to the old tstate_current or to thread-specific storage (PyThread_tss_*()). If that proves problematic then we can circle back. I consider it unlikely, but will run the buildbots to double-check. Also note that this does not change any of the code related to the GILState API, where it uses a thread state stored in thread-specific storage. I suspect we can combine that with _Py_tss_tstate (from here). However, that can be addressed separately and is not urgent (nor critical). (While this change was mostly done independently, I did take some inspiration from earlier (~2020) work by @markshannon (main...markshannon:threadstate_in_tls) and @vstinner (#23976).)
* gh-101659: Add _Py_AtExit() (gh-103298)Eric Snow2023-04-061-3/+2
| | | | | The function is like Py_AtExit() but for a single interpreter. This is a companion to the atexit module's register() function, taking a C callback instead of a Python one. We also update the _xxinterpchannels module to use _Py_AtExit(), which is the motivating case. (This is inspired by pain points felt while working on gh-101660.)
* gh-100227: Move the Dict of Interned Strings to PyInterpreterState (gh-102339)Eric Snow2023-03-281-1/+0
| | | | | We can revisit the options for keeping it global later, if desired. For now the approach seems quite complex, so we've gone with the simpler isolation solution in the meantime. https://github.com/python/cpython/issues/100227
* gh-102304: Move _Py_RefTotal to _PyRuntimeState (gh-102543)Eric Snow2023-03-201-0/+2
| | | | | | | The essentially eliminates the global variable, with the associated benefits. This is also a precursor to isolating this bit of state to PyInterpreterState. Folks that currently read _Py_RefTotal directly would have to start using _Py_GetGlobalRefTotal() instead. https://github.com/python/cpython/issues/102304
* gh-100227: Move dict_state.global_version to PyInterpreterState (gh-102338)Eric Snow2023-03-091-2/+0
| | | https://github.com/python/cpython/issues/100227
* gh-100227: Move func_state.next_version to PyInterpreterState (gh-102334)Eric Snow2023-03-081-2/+0
| | | https://github.com/python/cpython/issues/100227
* gh-100227: Move the dtoa State to PyInterpreterState (gh-102331)Eric Snow2023-02-281-2/+0
| | | https://github.com/python/cpython/issues/100227
* gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State ↵Eric Snow2023-01-231-0/+3
| | | | | | | | | | | | (gh-101209) We've factored out a struct from the two PyThreadState fields. This accomplishes two things: * make it clear that the trashcan-related code doesn't need any other parts of PyThreadState * allows us to use the trashcan mechanism even when there isn't a "current" thread state We still expect the caller to hold the GIL. https://github.com/python/cpython/issues/59956
* gh-59956: Clarify GILState-related Code (gh-101161)Eric Snow2023-01-191-4/+6
| | | | | | | | | | The objective of this change is to help make the GILState-related code easier to understand. This mostly involves moving code around and some semantically equivalent refactors. However, there are a also a small number of slight changes in structure and behavior: * tstate_current is moved out of _PyRuntimeState.gilstate * autoTSSkey is moved out of _PyRuntimeState.gilstate * autoTSSkey is initialized earlier * autoTSSkey is re-initialized (after fork) earlier https://github.com/python/cpython/issues/59956
* gh-90111: Minor Cleanup for Runtime-Global Objects (gh-100254)Eric Snow2022-12-141-1/+1
| | | | | | | | * move _PyRuntime.global_objects.interned to _PyRuntime.cached_objects.interned_strings (and use _Py_CACHED_OBJECT()) * rename _PyRuntime.global_objects to _PyRuntime.static_objects (This also relates to gh-96075.) https://github.com/python/cpython/issues/90111
* gh-81057: Move Signal-Related Globals to _PyRuntimeState (gh-100085)Eric Snow2022-12-121-5/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move faulthandler Globals to _PyRuntimeState (gh-100152)Eric Snow2022-12-121-0/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move tracemalloc Globals to _PyRuntimeState (gh-100151)Eric Snow2022-12-121-3/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move Threading-Related Globals to _PyRuntimeState (#100084)Eric Snow2022-12-091-0/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move Ceval Trampoline Globals to _PyRuntimeState (gh-100083)Eric Snow2022-12-091-10/+1
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move time Globals to _PyRuntimeState (gh-100122)Eric Snow2022-12-081-2/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move OS-Related Globals to _PyRuntimeState (gh-100082)Eric Snow2022-12-081-0/+2
| | | https://github.com/python/cpython/issues/81057
* gh-81057: Move More Globals to _PyRuntimeState (gh-100092)Eric Snow2022-12-071-0/+5
| | | https://github.com/python/cpython/issues/81057