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: Mark new interpreters and threads as non-static #99268

Merged
merged 4 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an issue that prevented :c:type:`PyThreadState` and
:c:type:`PyInterpreterState` memory from being freed properly.
4 changes: 4 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ PyInterpreterState_New(void)
interp = &runtime->_main_interpreter;
assert(interp->id == 0);
assert(interp->next == NULL);
assert(interp->_static);
brandtbucher marked this conversation as resolved.
Show resolved Hide resolved

interpreters->main = interp;
}
Expand All @@ -370,6 +371,7 @@ PyInterpreterState_New(void)
// Set to _PyInterpreterState_INIT.
memcpy(interp, &initial._main_interpreter,
sizeof(*interp));
interp->_static = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, a note pointing to PyInterpreterState_INIT().


if (id < 0) {
/* overflow or Py_Initialize() not called yet! */
Expand Down Expand Up @@ -837,6 +839,7 @@ 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 @@ -848,6 +851,7 @@ new_threadstate(PyInterpreterState *interp)
memcpy(tstate,
&initial._main_interpreter._initial_thread,
sizeof(*tstate));
tstate->_static = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note pointing to PyThreadState_INIT() and indicating that fields set there should be adjusted here as appropriate.

}
interp->threads.head = tstate;

Expand Down