gh-124160: Pass main_tstate to update_global_state_for_extension() (#124164)

This commit is contained in:
luk1337 2024-09-19 18:05:20 +02:00 committed by GitHub
parent 8f82d9aa21
commit 7331d0f70b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Fix crash when importing modules containing state and single-phase
initialization in a subinterpreter.

View File

@ -95,6 +95,14 @@ static void _testembed_Py_Initialize(void)
} }
static int test_import_in_subinterpreters(void)
{
_testembed_Py_InitializeFromConfig();
PyThreadState_Swap(Py_NewInterpreter());
return PyRun_SimpleString("import readline"); // gh-124160
}
/***************************************************** /*****************************************************
* Test repeated initialisation and subinterpreters * Test repeated initialisation and subinterpreters
*****************************************************/ *****************************************************/
@ -2398,6 +2406,7 @@ static struct TestCase TestCases[] = {
{"test_repeated_init_exec", test_repeated_init_exec}, {"test_repeated_init_exec", test_repeated_init_exec},
{"test_repeated_simple_init", test_repeated_simple_init}, {"test_repeated_simple_init", test_repeated_simple_init},
{"test_forced_io_encoding", test_forced_io_encoding}, {"test_forced_io_encoding", test_forced_io_encoding},
{"test_import_in_subinterpreters", test_import_in_subinterpreters},
{"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters}, {"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters},
{"test_repeated_init_and_inittab", test_repeated_init_and_inittab}, {"test_repeated_init_and_inittab", test_repeated_init_and_inittab},
{"test_pre_initialization_api", test_pre_initialization_api}, {"test_pre_initialization_api", test_pre_initialization_api},

View File

@ -2045,7 +2045,7 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
singlephase.m_init = p0; singlephase.m_init = p0;
} }
cached = update_global_state_for_extension( cached = update_global_state_for_extension(
tstate, info->path, info->name, def, &singlephase); main_tstate, info->path, info->name, def, &singlephase);
if (cached == NULL) { if (cached == NULL) {
assert(PyErr_Occurred()); assert(PyErr_Occurred());
goto main_finally; goto main_finally;