Skip to content

Commit

Permalink
adjust cfgs for windows 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Sep 29, 2023
1 parent f17e703 commit 1a349c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pytests/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions src/impl_/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -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>>,
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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()) };
Expand All @@ -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
Expand Down

0 comments on commit 1a349c2

Please sign in to comment.