]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124160: Pass main_tstate to update_global_state_for_extension() (#124164)
authorluk1337 <priv.luk@gmail.com>
Thu, 19 Sep 2024 16:05:20 +0000 (18:05 +0200)
committerGitHub <noreply@github.com>
Thu, 19 Sep 2024 16:05:20 +0000 (21:35 +0530)
Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst [new file with mode: 0644]
Programs/_testembed.c
Python/import.c

diff --git a/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst b/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst
new file mode 100644 (file)
index 0000000..26e7aef
--- /dev/null
@@ -0,0 +1,2 @@
+Fix crash when importing modules containing state and single-phase
+initialization in a subinterpreter.
index 342cc91cc58ced2f4d0b4ccd7d0b7a92d5f756da..10ee6b7be23e2104a341f8d983228f0e976149b6 100644 (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
  *****************************************************/
@@ -2398,6 +2406,7 @@ static struct TestCase TestCases[] = {
     {"test_repeated_init_exec", test_repeated_init_exec},
     {"test_repeated_simple_init", test_repeated_simple_init},
     {"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_inittab", test_repeated_init_and_inittab},
     {"test_pre_initialization_api", test_pre_initialization_api},
index a5ea0e2f81df57ae27920d0d4417e648147f7137..26ad84372cea68bc588ef3a522da44f91aab5897 100644 (file)
@@ -2045,7 +2045,7 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
                 singlephase.m_init = p0;
             }
             cached = update_global_state_for_extension(
-                    tstate, info->path, info->name, def, &singlephase);
+                    main_tstate, info->path, info->name, def, &singlephase);
             if (cached == NULL) {
                 assert(PyErr_Occurred());
                 goto main_finally;