summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
Commit message (Collapse)AuthorAgeFilesLines
* GH-101578: Normalize the current exception (GH-101607)Mark Shannon2023-02-081-3/+1
| | | | | | | | | | * Make sure that the current exception is always normalized. * Remove redundant type and traceback fields for the current exception. * Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException * Add new API functions: PyException_GetArgs, PyException_SetArgs
* gh-59956: Partial Fix for GILState API Compatibility with Subinterpreters ↵Eric Snow2023-02-061-21/+4
| | | | | | | | | | | (gh-101431) The GILState API (PEP 311) implementation from 2003 made the assumption that only one thread state would ever be used for any given OS thread, explicitly disregarding the case of subinterpreters. However, PyThreadState_Swap() still facilitated switching between subinterpreters, meaning the "current" thread state (holding the GIL), and the GILState thread state could end up out of sync, causing problems (including crashes). This change addresses the issue by keeping the two in sync in PyThreadState_Swap(). I verified the fix against gh-99040. Note that the other GILState-subinterpreter incompatibility (with autoInterpreterState) is not resolved here. https://github.com/python/cpython/issues/59956
* gh-59956: Clarify Runtime State Status Expectations (gh-101308)Eric Snow2023-01-301-145/+346
| | | | | | | | | | | | | A PyThreadState can be in one of many states in its lifecycle, represented by some status value. Those statuses haven't been particularly clear, so we're addressing that here. Specifically: * made the distinct lifecycle statuses clear on PyThreadState * identified expectations of how various lifecycle-related functions relate to status * noted the various places where those expectations don't match the actual behavior At some point we'll need to address the mismatches. (This change also includes some cleanup.) https://github.com/python/cpython/issues/59956
* Fix typos in pystate.c file (#101348)Виталий Дмитриев2023-01-261-5/+5
|
* gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State ↵Eric Snow2023-01-231-0/+16
| | | | | | | | | | | | (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-101181: Fix `unused-variable` warning in `pystate.c` (#101188)Nikita Sobolev2023-01-201-0/+3
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-59956: Fix Function Groupings in pystate.c (gh-101172)Eric Snow2023-01-201-237/+352
| | | | | This is a follow-up to gh-101161. The objective is to make it easier to read Python/pystate.c by grouping the functions there in a consistent way. This exclusively involves moving code around and adding various kinds of comments. https://github.com/python/cpython/issues/59956
* gh-59956: Clarify GILState-related Code (gh-101161)Eric Snow2023-01-191-201/+329
| | | | | | | | | | 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-100892: consolidate `HEAD_LOCK/HEAD_UNLOCK` macros (#100953)Kumar Aditya2023-01-151-4/+0
|
* GH-100126: Skip incomplete frames in more places (GH-100613)Brandt Bucher2023-01-091-7/+2
|
* GH-100000: Cleanup and polish various watchers code (GH-99998)Itamar Ostricher2022-12-141-0/+4
| | | | | | * Initialize `type_watchers` array to `NULL`s * Optimize code watchers notification * Optimize func watchers notification
* gh-99741: Implement Multi-Phase Init for the _xxsubinterpreters Module ↵Eric Snow2022-12-051-56/+128
| | | | | | | (gh-99742) _xxsubinterpreters is an internal module used for testing. https://github.com/python/cpython/issues/99741
* gh-99741: Clean Up the _xxsubinterpreters Module (gh-99940)Eric Snow2022-12-021-9/+11
| | | | | This cleanup up resolves a few subtle bugs and makes the implementation for multi-phase init much cleaner. https://github.com/python/cpython/issues/99741
* gh-99741: Fix the Cross-Interpreter Data API (gh-99939)Eric Snow2022-12-021-23/+84
| | | | | There were some minor issues that showed up while I was working on porting _xxsubinterpreters to multi-phase init. This fixes them. https://github.com/python/cpython/issues/99741
* GH-91054: Add code object watchers API (GH-99859)Itamar Ostricher2022-12-021-0/+5
| | | | | | * Add API to allow extensions to set callback function on creation and destruction of PyCodeObject Co-authored-by: Ye11ow-Flash <janshah@cs.stonybrook.edu>
* gh-91053: Add an optional callback that is invoked whenever a function is ↵mpage2022-11-221-0/+5
| | | | modified (#98175)
* gh-99377: Revert audit events for thread state creation and free, because ↵Steve Dower2022-11-171-18/+1
| | | | the GIL is not properly held at these times (GH-99543)
* gh-81057: Move the global Dict-Related Versions to _PyRuntimeState (gh-99497)Eric Snow2022-11-161-1/+1
| | | | | We also move the global func version. https://github.com/python/cpython/issues/81057
* gh-99377: Add audit events for thread creation and clear (GH-99378)Steve Dower2022-11-161-6/+25
|
* gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)Eric Snow2022-11-161-5/+5
| | | https://github.com/python/cpython/issues/81057
* GH-99205: remove `_static` field from `PyThreadState` and ↵Kumar Aditya2022-11-151-10/+6
| | | | `PyInterpreterState` (GH-99385)
* gh-81057: Move the Allocators to _PyRuntimeState (gh-99217)Eric Snow2022-11-111-2/+5
| | | | | The global allocators were stored in 3 static global variables: _PyMem_Raw, _PyMem, and _PyObject. State for the "small block" allocator was stored in another 13. That makes a total of 16 global variables. We are moving all 16 to the _PyRuntimeState struct as part of the work for gh-81057. (If PEP 684 is accepted then we will follow up by moving them all to PyInterpreterState.) https://github.com/python/cpython/issues/81057
* GH-96421: Insert shim frame on entry to interpreter (GH-96319)Mark Shannon2022-11-101-0/+1
| | | | | | * 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-99300: Use Py_NewRef() in Python/ directory (#99302)Victor Stinner2022-11-101-14/+7
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Python/ directory.
* GH-99205: Mark new interpreters and threads as non-static (GH-99268)Brandt Bucher2022-11-091-0/+8
|
* gh-98608: Change _Py_NewInterpreter() to _Py_NewInterpreterFromConfig() ↵Eric Snow2022-10-261-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | (gh-98609) (see https://github.com/python/cpython/issues/98608) This change does the following: 1. change the argument to a new `_PyInterpreterConfig` struct 2. rename the function to `_Py_NewInterpreterFromConfig()`, inspired by `Py_InitializeFromConfig()` (takes a `_PyInterpreterConfig` instead of `isolated_subinterpreter`) 3. split up the boolean `isolated_subinterpreter` into the corresponding multiple granular settings * allow_fork * allow_subprocess * allow_threads 4. add `PyInterpreterState.feature_flags` to store those settings 5. add a function for checking if a feature is enabled on an opaque `PyInterpreterState *` 6. drop `PyConfig._isolated_interpreter` The existing default (see `Py_NewInterpeter()` and `Py_Initialize*()`) allows fork, subprocess, and threads and the optional "isolated" interpreter (see the `_xxsubinterpreters` module) disables all three. None of that changes here; the defaults are preserved. Note that the given `_PyInterpreterConfig` will not be used outside `_Py_NewInterpreterFromConfig()`, nor preserved. This contrasts with how `PyConfig` is currently preserved, used, and even modified outside `Py_InitializeFromConfig()`. I'd rather just avoid that mess from the start for `_PyInterpreterConfig`. We can preserve it later if we find an actual need. This change allows us to follow up with a number of improvements (e.g. stop disallowing subprocess and support disallowing exec instead). (Note that this PR adds "private" symbols. We'll probably make them public, and add docs, in a separate change.)
* GH-91052: Add C API for watching dictionaries (GH-31787)Carl Meyer2022-10-071-0/+4
|
* GH-91079: Decouple C stack overflow checks from Python recursion checks. ↵Mark Shannon2022-10-051-2/+3
| | | | (GH-96510)
* GH-96754: Check whether the interpreter frame is complete before creating ↵Mark Shannon2022-09-131-0/+3
| | | | frame object. (GH-96776)
* Fix possible NULL pointer dereference in _PyThread_CurrentFrames (GH-96584)Kumar Aditya2022-09-091-1/+6
|
* GH-96569: Add two NULL checks to avoid undefined behavior. (GH-96585)Mark Shannon2022-09-061-8/+5
|
* GH-96071: fix deadlock in PyGILState_Ensure (GH-96124)Kumar Aditya2022-08-191-11/+16
| | | Alternative of #96107
* GH-95909: Make `_PyArg_Parser` initialization thread safe (GH-95958)Kumar Aditya2022-08-161-6/+21
|
* GH-95818: Skip incomplete frames in `PyThreadState_GetFrame` (GH-95886)Mark Shannon2022-08-111-2/+6
|
* GH-93897: Store frame size in code object and de-opt if insufficient space ↵Mark Shannon2022-06-201-1/+1
| | | | on thread frame stack. (GH-93908)
* gh-77782: Py_FdIsInteractive() now uses PyConfig.interactive (#93916)Victor Stinner2022-06-171-0/+1
|
* bpo-40514: Drop EXPERIMENTAL_ISOLATED_SUBINTERPRETERS (gh-93185)Eric Snow2022-05-271-17/+0
| | | | | | | This was added for bpo-40514 (gh-84694) to test out a per-interpreter GIL. However, it has since proven unnecessary to keep the experiment in the repo. (It can be done as a branch in a fork like normal.) So here we are removing: * the configure option * the macro * the code enabled by the macro
* bpo-46864: Suppress deprecation warnings for ob_shash. (GH-32042)Inada Naoki2022-03-231-1/+4
|
* bpo-45923: Decouple suspension of tracing from tracing flag. (GH-31908)Mark Shannon2022-03-151-17/+0
|
* bpo-46836: Rename InterpreterFrame to _PyInterpreterFrame (GH-31583)Victor Stinner2022-02-251-4/+4
| | | | | Rename also struct _interpreter_frame to struct _PyInterpreterFrame. Reduce risk of name conflicts if a project includes pycore_frame.h.
* bpo-45459: C API uses type names rather than structure names (GH-31528)Victor Stinner2022-02-241-4/+4
| | | | Thanks to the new pytypedefs.h, it becomes to use type names like PyObject rather like structure names like "struct _object".
* Pass reference to func, as well as args, when pushing frame. (GH-31100)Mark Shannon2022-02-031-20/+0
|
* bpo-46072: Add some frame stats. (GH-31060)Mark Shannon2022-02-021-0/+2
|
* bpo-45953: Preserve backward compatibility on some PyThreadState field ↵Eric Snow2022-02-011-4/+4
| | | | | names. (GH-31038) The gevent project is using the two `PyThreadState` fields I renamed in gh-30590. This PR fixes the names. See #msg412046.
* bpo-45953: Statically initialize all the non-object PyInterpreterState ↵Eric Snow2022-01-141-9/+0
| | | | | fields we can. (gh-30589) https://bugs.python.org/issue45953
* bpo-45953: Statically initialize all the PyThreadState fields we can. (gh-30590)Eric Snow2022-01-141-7/+5
| | | https://bugs.python.org/issue45953
* Statically initialize _PyRuntimeState fields. (gh-30588)Eric Snow2022-01-131-10/+0
| | | https://bugs.python.org/issue45953
* bpo-46370: Move the static initializer for _PyRuntime to its own header ↵Eric Snow2022-01-131-0/+1
| | | | | file. (gh-30587) https://bugs.python.org/issue46370
* bpo-45953: Statically allocate the main interpreter (and initial thread ↵Eric Snow2022-01-121-16/+33
| | | | | | | | | state). (gh-29883) Previously, the main interpreter was allocated on the heap during runtime initialization. Here we instead embed it into _PyRuntimeState, which means it is statically allocated as part of the _PyRuntime global. The same goes for the initial thread state (of each interpreter, including the main one). Consequently there are fewer allocations during runtime/interpreter init, fewer possible failures, and better memory locality. FYI, this also helps efforts to consolidate globals, which in turns helps work on subinterpreter isolation. https://bugs.python.org/issue45953
* bpo-46090: Allow PyThreadState.datastack_* members to be NULL (GH-30234)Brandt Bucher2021-12-281-21/+17
|