mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
GH-99205: Mark new interpreters and threads as non-static (GH-99268)
(cherry picked from commit 283ab0e1c0
)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This commit is contained in:
parent
014940ac70
commit
7c9c993945
2 changed files with 10 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Fix an issue that prevented :c:type:`PyThreadState` and
|
||||||
|
:c:type:`PyInterpreterState` memory from being freed properly.
|
|
@ -341,6 +341,7 @@ PyInterpreterState_New(void)
|
||||||
interp = &runtime->_main_interpreter;
|
interp = &runtime->_main_interpreter;
|
||||||
assert(interp->id == 0);
|
assert(interp->id == 0);
|
||||||
assert(interp->next == NULL);
|
assert(interp->next == NULL);
|
||||||
|
assert(interp->_static);
|
||||||
|
|
||||||
interpreters->main = interp;
|
interpreters->main = interp;
|
||||||
}
|
}
|
||||||
|
@ -355,6 +356,9 @@ PyInterpreterState_New(void)
|
||||||
// Set to _PyInterpreterState_INIT.
|
// Set to _PyInterpreterState_INIT.
|
||||||
memcpy(interp, &initial._main_interpreter,
|
memcpy(interp, &initial._main_interpreter,
|
||||||
sizeof(*interp));
|
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) {
|
if (id < 0) {
|
||||||
/* overflow or Py_Initialize() not called yet! */
|
/* overflow or Py_Initialize() not called yet! */
|
||||||
|
@ -817,6 +821,7 @@ new_threadstate(PyInterpreterState *interp)
|
||||||
assert(id == 1);
|
assert(id == 1);
|
||||||
used_newtstate = 0;
|
used_newtstate = 0;
|
||||||
tstate = &interp->_initial_thread;
|
tstate = &interp->_initial_thread;
|
||||||
|
assert(tstate->_static);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Every valid interpreter must have at least one thread.
|
// Every valid interpreter must have at least one thread.
|
||||||
|
@ -828,6 +833,9 @@ new_threadstate(PyInterpreterState *interp)
|
||||||
memcpy(tstate,
|
memcpy(tstate,
|
||||||
&initial._main_interpreter._initial_thread,
|
&initial._main_interpreter._initial_thread,
|
||||||
sizeof(*tstate));
|
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;
|
interp->threads.head = tstate;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue