Skip to content

Commit dea8fa2

Browse files
luk1337hroncok
authored andcommitted
00440: pythongh-124160: Pass main_tstate to update_global_state_for_extension()
(cherry picked from commit 7331d0f)
1 parent 0ec030e commit dea8fa2

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash when importing modules containing state and single-phase
2+
initialization in a subinterpreter.

Programs/_testembed.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ static void _testembed_Py_Initialize(void)
9494
}
9595

9696

97+
static int test_import_in_subinterpreters(void)
98+
{
99+
_testembed_Py_InitializeFromConfig();
100+
PyThreadState_Swap(Py_NewInterpreter());
101+
return PyRun_SimpleString("import readline"); // gh-124160
102+
}
103+
104+
97105
/*****************************************************
98106
* Test repeated initialisation and subinterpreters
99107
*****************************************************/
@@ -2184,6 +2192,7 @@ static struct TestCase TestCases[] = {
21842192
{"test_repeated_init_exec", test_repeated_init_exec},
21852193
{"test_repeated_simple_init", test_repeated_simple_init},
21862194
{"test_forced_io_encoding", test_forced_io_encoding},
2195+
{"test_import_in_subinterpreters", test_import_in_subinterpreters},
21872196
{"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters},
21882197
{"test_repeated_init_and_inittab", test_repeated_init_and_inittab},
21892198
{"test_pre_initialization_api", test_pre_initialization_api},

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
20442044
singlephase.m_init = p0;
20452045
}
20462046
cached = update_global_state_for_extension(
2047-
tstate, info->path, info->name, def, &singlephase);
2047+
main_tstate, info->path, info->name, def, &singlephase);
20482048
if (cached == NULL) {
20492049
assert(PyErr_Occurred());
20502050
goto main_finally;

0 commit comments

Comments
 (0)