diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-02-16 01:16:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-16 01:16:00 (GMT) |
commit | 89ac665891dec1988bedec2ce9b2c4d016502a49 (patch) | |
tree | 246997ab21e8b587b8a3f58ac93d7b278c9d0938 /Include/cpython | |
parent | 3dea4ba6c1b9237893d23574f931f33c940b74e8 (diff) | |
download | cpython-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 'Include/cpython')
-rw-r--r-- | Include/cpython/initconfig.h | 3 | ||||
-rw-r--r-- | Include/cpython/pystate.h | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index 6ce42b4..a070fa9 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -248,6 +248,7 @@ typedef struct { int allow_exec; int allow_threads; int allow_daemon_threads; + int check_multi_interp_extensions; } _PyInterpreterConfig; #define _PyInterpreterConfig_INIT \ @@ -256,6 +257,7 @@ typedef struct { .allow_exec = 0, \ .allow_threads = 1, \ .allow_daemon_threads = 0, \ + .check_multi_interp_extensions = 1, \ } #define _PyInterpreterConfig_LEGACY_INIT \ @@ -264,6 +266,7 @@ typedef struct { .allow_exec = 1, \ .allow_threads = 1, \ .allow_daemon_threads = 1, \ + .check_multi_interp_extensions = 0, \ } /* --- Helper functions --------------------------------------- */ diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index be1fcb6..3efb241 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -11,6 +11,9 @@ is available in a given context. For example, forking the process might not be allowed in the current interpreter (i.e. os.fork() would fail). */ +/* Set if import should check a module for subinterpreter support. */ +#define Py_RTFLAGS_MULTI_INTERP_EXTENSIONS (1UL << 8) + /* Set if threads are allowed. */ #define Py_RTFLAGS_THREADS (1UL << 10) |