Skip to content
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

GH-99205: remove _static field from PyThreadState and PyInterpreterState #99385

Merged
merged 3 commits into from
Nov 15, 2022
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
3 changes: 0 additions & 3 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ struct _ts {
after allocation. */
int _initialized;

/* Was this thread state statically allocated? */
int _static;

int py_recursion_remaining;
int py_recursion_limit;

Expand Down
3 changes: 0 additions & 3 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ struct _is {
int _initialized;
int finalizing;

/* Was this interpreter statically allocated? */
bool _static;

struct _ceval_state ceval;
struct _gc_runtime_state gc;

Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ extern "C" {

#define _PyInterpreterState_INIT \
{ \
._static = 1, \
.id_refcount = -1, \
DLOPENFLAGS_INIT \
.ceval = { \
Expand All @@ -67,7 +66,6 @@ extern "C" {

#define _PyThreadState_INIT \
{ \
._static = 1, \
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
.context_ver = 1, \
}
Expand Down
16 changes: 6 additions & 10 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ alloc_interpreter(void)
static void
free_interpreter(PyInterpreterState *interp)
{
if (!interp->_static) {
// The main interpreter is statically allocated so
// should not be freed.
if (interp != &_PyRuntime._main_interpreter) {
PyMem_RawFree(interp);
}
}
Expand Down Expand Up @@ -356,7 +358,6 @@ PyInterpreterState_New(void)
interp = &runtime->_main_interpreter;
assert(interp->id == 0);
assert(interp->next == NULL);
assert(interp->_static);

interpreters->main = interp;
}
Expand All @@ -371,9 +372,6 @@ PyInterpreterState_New(void)
// Set to _PyInterpreterState_INIT.
memcpy(interp, &initial._main_interpreter,
sizeof(*interp));
// We need to adjust any fields that are different from the initial
// interpreter (as defined in _PyInterpreterState_INIT):
interp->_static = false;

if (id < 0) {
/* overflow or Py_Initialize() not called yet! */
Expand Down Expand Up @@ -759,7 +757,9 @@ alloc_threadstate(void)
static void
free_threadstate(PyThreadState *tstate)
{
if (!tstate->_static) {
// The initial thread state of the interpreter is allocated
// as part of the interpreter state so should not be freed.
if (tstate != &tstate->interp->_initial_thread) {
PyMem_RawFree(tstate);
}
}
Expand Down Expand Up @@ -842,7 +842,6 @@ new_threadstate(PyInterpreterState *interp)
assert(id == 1);
used_newtstate = 0;
tstate = &interp->_initial_thread;
assert(tstate->_static);
}
else {
// Every valid interpreter must have at least one thread.
Expand All @@ -854,9 +853,6 @@ new_threadstate(PyInterpreterState *interp)
memcpy(tstate,
&initial._main_interpreter._initial_thread,
sizeof(*tstate));
// We need to adjust any fields that are different from the initial
// thread (as defined in _PyThreadState_INIT):
tstate->_static = false;
}
interp->threads.head = tstate;

Expand Down