summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* bpo-45711: Remove type and traceback from exc_info (GH-30122)Irit Katriel2021-12-171-2/+0
| | | | | | | | * Do not PUSH/POP traceback or type to the stack as part of exc_info * Remove exc_traceback and exc_type from _PyErr_StackItem * Add to what's new, because this change breaks things like Cython
* bpo-46008: Move Py*State init into distinct functions. (gh-29977)Eric Snow2021-12-081-101/+272
| | | | | Previously, basic initialization of PyInterprterState happened in PyInterpreterState_New() (along with allocation and adding the new interpreter to the runtime state). This prevented us from initializing interpreter states that were allocated separately (e.g. statically or in a free list). We've addressed that here by factoring out a separate function just for initialization. We've done the same for PyThreadState. _PyRuntimeState was sorted out when we added it since _PyRuntime is statically allocated. However, here we update the existing init code to line up with the functions for PyInterpreterState and PyThreadState. https://bugs.python.org/issue46008
* bpo-46008: Add _PyInterpreterState_Main(). (gh-29978)Eric Snow2021-12-081-1/+1
| | | | | PyInterpreterState_Main() is a plain function exposed in the public C-API. For internal usage we can take the more efficient approach in this PR. https://bugs.python.org/issue46008
* bpo-46008: Stop calling _PyThreadState_Init() in new_threadstate(). (gh-29973)Eric Snow2021-12-081-7/+13
| | | | | This simplifies new_threadstate(). We also rename _PyThreadState_Init() to _PyThreadState_SetCurrent() to reflect what it actually does. https://bugs.python.org/issue46008
* bpo-46008: Use PyMem_RawCalloc() to allocate PyThreadState. (GH-29972)Eric Snow2021-12-071-38/+2
| | | | | Doing so allows us to stop assigning various fields to `NULL` and 0. It also more closely matches the behavior of a static initializer. Automerge-Triggered-By: GH:ericsnowcurrently
* bpo-46008: Move thread-related interpreter state into a sub-struct. (gh-29971)Eric Snow2021-12-071-14/+14
| | | | | This parallels _PyRuntimeState.interpreters. Doing this helps make it more clear what part of PyInterpreterState relates to its threads. https://bugs.python.org/issue46008
* bpo-46008: Return void from _PyEval_InitState(). (gh-29970)Eric Snow2021-12-071-1/+3
| | | | | This falls into the category of keep-allocation-and-initialization separate. It also allows us to use _PyEval_InitState() safely in functions that return void. https://bugs.python.org/issue46008
* bpo-45711: use exc_value instead of exc_type to determine if exc_info is ↵Irit Katriel2021-11-251-5/+1
| | | | valid. Add more assertions. (GH-29627)
* bpo-44525: Copy free variables in bytecode to allow calls to inner functions ↵Mark Shannon2021-11-231-3/+3
| | | | | | | | | | | 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-42540: reallocation of id_mutex should not force default allocator ↵Sam Gross2021-11-171-1/+4
| | | | | | | (GH-29564) Unlike the other locks reinitialized by _PyRuntimeState_ReInitThreads, the "interpreters.main->id_mutex" is not freed by _PyRuntimeState_Fini and should not force the default raw allocator.
* bpo-45753: Make recursion checks more efficient. (GH-29524)Mark Shannon2021-11-161-2/+2
| | | | * Uses recursion remaining, instead of recursion depth to speed up check against recursion limit.
* bpo-45256: Rationalize code around Python-to-Python calls a bit. (GH-29235)Mark Shannon2021-10-281-6/+16
|
* bpo-45637: Store the frame pointer in the cframe (GH-29267)Mark Shannon2021-10-281-5/+5
| | | * Rename 'frame' to 'current_frame'
* bpo-43760: Rename _PyThreadState_DisableTracing() (GH-29032)Victor Stinner2021-10-181-2/+2
| | | | | | * Rename _PyThreadState_DisableTracing() to _PyThreadState_PauseTracing() * Rename _PyThreadState_ResetTracing() to _PyThreadState_ResumeTracing()
* bpo-43760: Add PyThreadState_EnterTracing() (GH-28542)Victor Stinner2021-10-151-0/+16
| | | | | | | | | | Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing() functions to the limited C API to suspend and resume tracing and profiling. Add an unit test on the PyThreadState C API to _testcapi. Add also internal _PyThreadState_DisableTracing() and _PyThreadState_ResetTracing().
* pycore_pystate.h no longer redefines PyThreadState_GET() (GH-28921)Victor Stinner2021-10-131-2/+5
| | | | | | | | | | | | | | | | | | | | | | Redefining the PyThreadState_GET() macro in pycore_pystate.h is useless since it doesn't affect files not including it. Either use _PyThreadState_GET() directly, or don't use pycore_pystate.h internal C API. For example, the _testcapi extension don't use the internal C API, but use the public PyThreadState_Get() function instead. Replace PyThreadState_Get() with _PyThreadState_GET(). The _PyThreadState_GET() macro is more efficient than PyThreadState_Get() and PyThreadState_GET() function calls which call fail with a fatal Python error. posixmodule.c and _ctypes extension now include <windows.h> before pycore header files (like pycore_call.h). _PyTraceback_Add() now uses _PyErr_Fetch()/_PyErr_Restore() instead of PyErr_Fetch()/PyErr_Restore(). The _decimal and _xxsubinterpreters extensions are now built with the Py_BUILD_CORE_MODULE macro defined to get access to the internal C API.
* Restore PEP 523 functionality. (GH-28871)Mark Shannon2021-10-111-2/+10
|
* bpo-44990: Change layout of evaluation frames. "Layout B" (GH-27933)Mark Shannon2021-08-251-10/+10
| | | Places the locals between the specials and stack. This is the more "natural" layout for a C struct, makes the code simpler and gives a slight speedup (~1%)
* bpo-44590: Lazily allocate frame objects (GH-27077)Mark Shannon2021-07-261-29/+52
| | | | | | | | | | | | | | * Convert "specials" array to InterpreterFrame struct, adding f_lasti, f_state and other non-debug FrameObject fields to it. * Refactor, calls pushing the call to the interpreter upward toward _PyEval_Vector. * Compute f_back when on thread stack, only filling in value when frame object outlives stack invocation. * Move ownership of InterpreterFrame in generator from frame object to generator object. * Do not create frame objects for Python calls. * Do not create frame objects for generators.
* bpo-44348: Move trace-info to thread-state (GH-26623)Mark Shannon2021-06-101-0/+2
| | | | | * Move trace-info to thread state. * Correct output for pdb when turning on tracing in middle of line
* bpo-43879: Add native_thread_id field to PyThreadState (GH-25458)Gabriele N. Tornetta2021-05-261-0/+5
|
* bpo-44032: Delay deletion of stack chunks until thread state is deleted. ↵Mark Shannon2021-05-241-7/+7
| | | | (GH-26285)