adjust cfgs for windows 3.9

This commit is contained in:
David Hewitt 2023-09-29 13:08:47 +01:00
parent f17e703167
commit 1a349c2eb7
2 changed files with 13 additions and 6 deletions

View File

@ -33,10 +33,15 @@ def test_multiple_imports_same_interpreter_ok():
def test_import_in_subinterpreter_forbidden():
import _xxsubinterpreters
if sys.version_info < (3, 12):
expected_error = "PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576"
else:
expected_error = "module pyo3_pytests.pyo3_pytests does not support loading in subinterpreters"
sub_interpreter = _xxsubinterpreters.create()
with pytest.raises(
_xxsubinterpreters.RunFailedError,
match="PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576",
match=expected_error,
):
_xxsubinterpreters.run_string(
sub_interpreter, "import pyo3_pytests.pyo3_pytests"

View File

@ -2,7 +2,7 @@
use std::cell::UnsafeCell;
#[cfg(all(not(PyPy), Py_3_9))]
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
use std::sync::atomic::{AtomicI64, Ordering};
#[cfg(not(PyPy))]
@ -15,7 +15,7 @@ pub struct ModuleDef {
ffi_def: UnsafeCell<ffi::PyModuleDef>,
initializer: ModuleInitializer,
/// Interpreter ID where module was initialized (not applicable on PyPy).
#[cfg(all(not(PyPy), Py_3_9))]
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
interpreter: AtomicI64,
/// Initialized module object, cached to avoid reinitialization.
module: GILOnceCell<Py<PyModule>>,
@ -58,7 +58,7 @@ impl ModuleDef {
ffi_def,
initializer,
// -1 is never expected to be a valid interpreter ID
#[cfg(all(not(PyPy), Py_3_9))]
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
interpreter: AtomicI64::new(-1),
module: GILOnceCell::new(),
}
@ -86,7 +86,9 @@ impl ModuleDef {
// PyPy does not have subinterpreters, so no need to check interpreter ID.
#[cfg(not(PyPy))]
{
#[cfg(Py_3_9)]
// PyInterpreterState_Get is only available on 3.9 and later, but is missing
// from python3.dll for Windows stable API on 3.9
#[cfg(all(Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
{
let current_interpreter =
unsafe { ffi::PyInterpreterState_GetID(ffi::PyInterpreterState_Get()) };
@ -104,7 +106,7 @@ impl ModuleDef {
}
}
}
#[cfg(not(Py_3_9))]
#[cfg(not(all(Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))))))]
{
// CPython before 3.9 does not have APIs to check the interpreter ID, so best that can be
// done to guard against subinterpreters is fail if the module is initialized twice