Skip to content

Commit 9bae681

Browse files
[3.13] gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164) (#124250)
gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164) (cherry picked from commit 7331d0f) Co-authored-by: luk1337 <[email protected]>
1 parent 848a210 commit 9bae681

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
@@ -2051,7 +2051,7 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
20512051
singlephase.m_init = p0;
20522052
}
20532053
cached = update_global_state_for_extension(
2054-
tstate, info->path, info->name, def, &singlephase);
2054+
main_tstate, info->path, info->name, def, &singlephase);
20552055
if (cached == NULL) {
20562056
assert(PyErr_Occurred());
20572057
goto main_finally;

0 commit comments

Comments
 (0)