Skip to content

bpo-46008: Move Py*State init into distinct functions. #29977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
6 changes: 5 additions & 1 deletion Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
Loading