diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 261e02180d1..deea11aad05 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -330,8 +330,11 @@ impl InterpreterConfig { PythonImplementation::RustPython => out.push("cargo:rustc-cfg=RustPython".to_owned()), } - // If Py_GIL_DISABLED is set, do not build with limited API support - if self.abi3 && !self.is_free_threaded() { + // RustPython always builds with limited API support. + // If Py_GIL_DISABLED is set, do not build with limited API support. + if (self.abi3 && !self.is_free_threaded()) + || self.implementation == PythonImplementation::RustPython + { out.push("cargo:rustc-cfg=Py_LIMITED_API".to_owned()); } @@ -3188,6 +3191,22 @@ mod tests { "cargo:rustc-cfg=PyPy".to_owned(), ] ); + + let interpreter_config = + InterpreterConfigBuilder::new(PythonImplementation::RustPython, version) + .finalize() + .unwrap(); + assert_eq!( + interpreter_config.build_script_outputs(), + [ + "cargo:rustc-cfg=Py_3_8".to_owned(), + "cargo:rustc-cfg=Py_3_9".to_owned(), + "cargo:rustc-cfg=Py_3_10".to_owned(), + "cargo:rustc-cfg=Py_3_11".to_owned(), + "cargo:rustc-cfg=RustPython".to_owned(), + "cargo:rustc-cfg=Py_LIMITED_API".to_owned(), + ] + ); } #[test] diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index 8f63e7f26ed..1eb98a0e458 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -600,8 +600,8 @@ mod weakrefobject; pub mod structmember; // "Limited API" definitions matching Python's `include/cpython` directory. -#[cfg(not(Py_LIMITED_API))] +#[cfg(not(any(Py_LIMITED_API, RustPython)))] mod cpython; -#[cfg(not(Py_LIMITED_API))] +#[cfg(not(any(Py_LIMITED_API, RustPython)))] pub use self::cpython::*; diff --git a/src/types/dict.rs b/src/types/dict.rs index a65d5c557f1..29e07e18320 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -36,9 +36,8 @@ pyobject_native_type!( ); #[cfg(RustPython)] -pyobject_native_type!( +pyobject_native_type_core!( PyDict, - ffi::PyDictObject, |py| { static TYPE: PyOnceLock> = PyOnceLock::new(); TYPE.import(py, "builtins", "dict").unwrap().as_type_ptr()