Skip to content

Commit bc0222e

Browse files
committed
adjust cfgs for windows 3.9
1 parent f17e703 commit bc0222e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pytests/tests/test_misc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ def test_multiple_imports_same_interpreter_ok():
3333
def test_import_in_subinterpreter_forbidden():
3434
import _xxsubinterpreters
3535

36+
if sys.version_info < (3, 12):
37+
expected_error = "PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576"
38+
else:
39+
expected_error = "module pyo3_pytests.pyo3_pytests does not support loading in subinterpreters"
40+
3641
sub_interpreter = _xxsubinterpreters.create()
3742
with pytest.raises(
3843
_xxsubinterpreters.RunFailedError,
39-
match="PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576",
44+
match=expected_error,
4045
):
4146
_xxsubinterpreters.run_string(
4247
sub_interpreter, "import pyo3_pytests.pyo3_pytests"

src/impl_/pymodule.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct ModuleDef {
1515
ffi_def: UnsafeCell<ffi::PyModuleDef>,
1616
initializer: ModuleInitializer,
1717
/// Interpreter ID where module was initialized (not applicable on PyPy).
18-
#[cfg(all(not(PyPy), Py_3_9))]
18+
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
1919
interpreter: AtomicI64,
2020
/// Initialized module object, cached to avoid reinitialization.
2121
module: GILOnceCell<Py<PyModule>>,
@@ -58,7 +58,7 @@ impl ModuleDef {
5858
ffi_def,
5959
initializer,
6060
// -1 is never expected to be a valid interpreter ID
61-
#[cfg(all(not(PyPy), Py_3_9))]
61+
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
6262
interpreter: AtomicI64::new(-1),
6363
module: GILOnceCell::new(),
6464
}
@@ -86,7 +86,9 @@ impl ModuleDef {
8686
// PyPy does not have subinterpreters, so no need to check interpreter ID.
8787
#[cfg(not(PyPy))]
8888
{
89-
#[cfg(Py_3_9)]
89+
// PyInterpreterState_Get is only available on 3.9 and later, but is missing
90+
// from python3.dll for Windows stable API on 3.9
91+
#[cfg(all(Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
9092
{
9193
let current_interpreter =
9294
unsafe { ffi::PyInterpreterState_GetID(ffi::PyInterpreterState_Get()) };
@@ -104,7 +106,7 @@ impl ModuleDef {
104106
}
105107
}
106108
}
107-
#[cfg(not(Py_3_9))]
109+
#[cfg(not(all(Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))))))]
108110
{
109111
// CPython before 3.9 does not have APIs to check the interpreter ID, so best that can be
110112
// done to guard against subinterpreters is fail if the module is initialized twice

0 commit comments

Comments
 (0)