summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-09-23 23:16:41 (GMT)
committerGitHub <noreply@github.com>2024-09-23 23:16:41 (GMT)
commit9bae6815a36073860f8c9334229e732adeb05a5a (patch)
treef28a90b826280bb6dc6751424b673b86ccf09799
parent848a21007b98d2f0efd8bbace46d9ed70173e53d (diff)
downloadcpython-9bae6815a36073860f8c9334229e732adeb05a5a.zip
cpython-9bae6815a36073860f8c9334229e732adeb05a5a.tar.gz
cpython-9bae6815a36073860f8c9334229e732adeb05a5a.tar.bz2
[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 7331d0f70bc9fbac177b76b6ec03486430383425) Co-authored-by: luk1337 <priv.luk@gmail.com>
-rw-r--r--Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst2
-rw-r--r--Programs/_testembed.c9
-rw-r--r--Python/import.c2
3 files changed, 12 insertions, 1 deletions
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
index 0000000..26e7aef
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst
@@ -0,0 +1,2 @@
+Fix crash when importing modules containing state and single-phase
+initialization in a subinterpreter.
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index e341f0c..96dbfab 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -94,6 +94,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
*****************************************************/
@@ -2184,6 +2192,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},
diff --git a/Python/import.c b/Python/import.c
index e0eb740..2ec5968 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2051,7 +2051,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;