diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2021-12-08 01:59:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-08 01:59:49 (GMT) |
commit | 32a67246b0d1e08cd50fc3bfa58052cfeb515b2e (patch) | |
tree | efd97b5d0ef22b321787f47ad8b38acd352678fa /Include | |
parent | 758b74e71eb22e1e83a9eb937d1c015e461745a1 (diff) | |
download | cpython-32a67246b0d1e08cd50fc3bfa58052cfeb515b2e.zip cpython-32a67246b0d1e08cd50fc3bfa58052cfeb515b2e.tar.gz cpython-32a67246b0d1e08cd50fc3bfa58052cfeb515b2e.tar.bz2 |
bpo-46008: Move Py*State init into distinct functions. (gh-29977)
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
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/pystate.h | 6 | ||||
-rw-r--r-- | Include/internal/pycore_interp.h | 6 | ||||
-rw-r--r-- | Include/internal/pycore_runtime.h | 17 |
3 files changed, 27 insertions, 2 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 5adbf3b..aa51828 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -77,6 +77,12 @@ struct _ts { struct _ts *next; PyInterpreterState *interp; + /* Has been initialized to a safe state. + + In order to be effective, this must be set to 0 during or right + after allocation. */ + int _initialized; + int recursion_remaining; int recursion_limit; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 53938e3..e421aa4 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -240,7 +240,6 @@ struct _is { struct _is *next; struct pythreads { - int _preallocated_used; uint64_t next_unique_id; struct _ts *head; /* Used in Modules/_threadmodule.c. */ @@ -262,6 +261,11 @@ struct _is { int requires_idref; PyThread_type_lock id_mutex; + /* Has been initialized to a safe state. + + In order to be effective, this must be set to 0 during or right + after allocation. */ + int _initialized; int finalizing; struct _ceval_state ceval; diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h index 9df833c..39e30b7 100644 --- a/Include/internal/pycore_runtime.h +++ b/Include/internal/pycore_runtime.h @@ -67,6 +67,12 @@ struct _Py_unicode_runtime_ids { /* Full Python runtime state */ typedef struct pyruntimestate { + /* Has been initialized to a safe state. + + In order to be effective, this must be set to 0 during or right + after allocation. */ + int _initialized; + /* Is running Py_PreInitialize()? */ int preinitializing; @@ -136,9 +142,18 @@ typedef struct pyruntimestate { } _PyRuntimeState; #define _PyRuntimeState_INIT \ - {.preinitialized = 0, .core_initialized = 0, .initialized = 0} + { \ + ._initialized = 0, \ + } /* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */ +static inline void +_PyRuntimeState_reset(_PyRuntimeState *runtime) +{ + /* Make it match _PyRuntimeState_INIT. */ + memset(runtime, 0, sizeof(*runtime)); +} + PyAPI_DATA(_PyRuntimeState) _PyRuntime; |