summaryrefslogtreecommitdiffstats
path: root/Python/importdl.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-02-16 01:16:00 (GMT)
committerGitHub <noreply@github.com>2023-02-16 01:16:00 (GMT)
commit89ac665891dec1988bedec2ce9b2c4d016502a49 (patch)
tree246997ab21e8b587b8a3f58ac93d7b278c9d0938 /Python/importdl.c
parent3dea4ba6c1b9237893d23574f931f33c940b74e8 (diff)
downloadcpython-89ac665891dec1988bedec2ce9b2c4d016502a49.zip
cpython-89ac665891dec1988bedec2ce9b2c4d016502a49.tar.gz
cpython-89ac665891dec1988bedec2ce9b2c4d016502a49.tar.bz2
gh-98627: Add an Optional Check for Extension Module Subinterpreter Compatibility (gh-99040)
Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL. This change includes the following: * add tests for extension module subinterpreter compatibility * add _PyInterpreterConfig.check_multi_interp_extensions * add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS * add _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * fail iff the module does not implement multi-phase init and the current interpreter is configured to check https://github.com/python/cpython/issues/98627
Diffstat (limited to 'Python/importdl.c')
-rw-r--r--Python/importdl.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Python/importdl.c b/Python/importdl.c
index 6dafb45..3a3a30d 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_call.h"
+#include "pycore_import.h"
#include "pycore_pystate.h"
#include "pycore_runtime.h"
@@ -203,6 +204,10 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
/* Fall back to single-phase init mechanism */
+ if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
+ goto error;
+ }
+
if (hook_prefix == nonascii_prefix) {
/* don't allow legacy init for non-ASCII module names */
PyErr_Format(