adjust cfgs for windows 3.9
This commit is contained in:
parent
f17e703167
commit
1a349c2eb7
|
@ -33,10 +33,15 @@ def test_multiple_imports_same_interpreter_ok():
|
||||||
def test_import_in_subinterpreter_forbidden():
|
def test_import_in_subinterpreter_forbidden():
|
||||||
import _xxsubinterpreters
|
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()
|
sub_interpreter = _xxsubinterpreters.create()
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
_xxsubinterpreters.RunFailedError,
|
_xxsubinterpreters.RunFailedError,
|
||||||
match="PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576",
|
match=expected_error,
|
||||||
):
|
):
|
||||||
_xxsubinterpreters.run_string(
|
_xxsubinterpreters.run_string(
|
||||||
sub_interpreter, "import pyo3_pytests.pyo3_pytests"
|
sub_interpreter, "import pyo3_pytests.pyo3_pytests"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
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};
|
use std::sync::atomic::{AtomicI64, Ordering};
|
||||||
|
|
||||||
#[cfg(not(PyPy))]
|
#[cfg(not(PyPy))]
|
||||||
|
@ -15,7 +15,7 @@ pub struct ModuleDef {
|
||||||
ffi_def: UnsafeCell<ffi::PyModuleDef>,
|
ffi_def: UnsafeCell<ffi::PyModuleDef>,
|
||||||
initializer: ModuleInitializer,
|
initializer: ModuleInitializer,
|
||||||
/// Interpreter ID where module was initialized (not applicable on PyPy).
|
/// 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,
|
interpreter: AtomicI64,
|
||||||
/// Initialized module object, cached to avoid reinitialization.
|
/// Initialized module object, cached to avoid reinitialization.
|
||||||
module: GILOnceCell<Py<PyModule>>,
|
module: GILOnceCell<Py<PyModule>>,
|
||||||
|
@ -58,7 +58,7 @@ impl ModuleDef {
|
||||||
ffi_def,
|
ffi_def,
|
||||||
initializer,
|
initializer,
|
||||||
// -1 is never expected to be a valid interpreter ID
|
// -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),
|
interpreter: AtomicI64::new(-1),
|
||||||
module: GILOnceCell::new(),
|
module: GILOnceCell::new(),
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,9 @@ impl ModuleDef {
|
||||||
// PyPy does not have subinterpreters, so no need to check interpreter ID.
|
// PyPy does not have subinterpreters, so no need to check interpreter ID.
|
||||||
#[cfg(not(PyPy))]
|
#[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 =
|
let current_interpreter =
|
||||||
unsafe { ffi::PyInterpreterState_GetID(ffi::PyInterpreterState_Get()) };
|
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
|
// 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
|
// done to guard against subinterpreters is fail if the module is initialized twice
|
||||||
|
|
Loading…
Reference in a new issue