diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-01-12 23:28:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 23:28:46 (GMT) |
commit | ed57b36c32e521162dbb97199e64a340d3bff827 (patch) | |
tree | fab825ae903723e4dc748e7b89cb78f3b226c816 /Include/cpython | |
parent | 0bbf30e2b910bc9c5899134ae9d73a8df968da35 (diff) | |
download | cpython-ed57b36c32e521162dbb97199e64a340d3bff827.zip cpython-ed57b36c32e521162dbb97199e64a340d3bff827.tar.gz cpython-ed57b36c32e521162dbb97199e64a340d3bff827.tar.bz2 |
bpo-45953: Statically allocate the main interpreter (and initial thread 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
Diffstat (limited to 'Include/cpython')
-rw-r--r-- | Include/cpython/pystate.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index c37123c..bcb1bb2 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -2,6 +2,9 @@ # error "this header file must not be included directly" #endif +#include <stdbool.h> + + PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int); @@ -83,6 +86,9 @@ struct _ts { after allocation. */ int _initialized; + /* Was this thread state statically allocated? */ + bool _static; + int recursion_remaining; int recursion_limit; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ @@ -175,9 +181,11 @@ struct _ts { PyObject **datastack_top; PyObject **datastack_limit; /* XXX signal handlers should also be here */ - }; + +/* other API */ + // Alias for backward compatibility with Python 3.8 #define _PyInterpreterState_Get PyInterpreterState_Get |