Skip to content

Commit 30c8b24

Browse files
Avoid using PyDictObject when compiling for RustPython (#6057)
* Avoid using `PyDictObject` when compiling for RustPython * Always disable cpython ffi functions when compiling for RustPython * Force enable `Py_LIMITED_API` when compiling for `RustPython`
1 parent d566a2d commit 30c8b24

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

pyo3-build-config/src/impl_.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,11 @@ impl InterpreterConfig {
330330
PythonImplementation::RustPython => out.push("cargo:rustc-cfg=RustPython".to_owned()),
331331
}
332332

333-
// If Py_GIL_DISABLED is set, do not build with limited API support
334-
if self.abi3 && !self.is_free_threaded() {
333+
// RustPython always builds with limited API support.
334+
// If Py_GIL_DISABLED is set, do not build with limited API support.
335+
if (self.abi3 && !self.is_free_threaded())
336+
|| self.implementation == PythonImplementation::RustPython
337+
{
335338
out.push("cargo:rustc-cfg=Py_LIMITED_API".to_owned());
336339
}
337340

@@ -3188,6 +3191,22 @@ mod tests {
31883191
"cargo:rustc-cfg=PyPy".to_owned(),
31893192
]
31903193
);
3194+
3195+
let interpreter_config =
3196+
InterpreterConfigBuilder::new(PythonImplementation::RustPython, version)
3197+
.finalize()
3198+
.unwrap();
3199+
assert_eq!(
3200+
interpreter_config.build_script_outputs(),
3201+
[
3202+
"cargo:rustc-cfg=Py_3_8".to_owned(),
3203+
"cargo:rustc-cfg=Py_3_9".to_owned(),
3204+
"cargo:rustc-cfg=Py_3_10".to_owned(),
3205+
"cargo:rustc-cfg=Py_3_11".to_owned(),
3206+
"cargo:rustc-cfg=RustPython".to_owned(),
3207+
"cargo:rustc-cfg=Py_LIMITED_API".to_owned(),
3208+
]
3209+
);
31913210
}
31923211

31933212
#[test]

pyo3-ffi/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ mod weakrefobject;
603603
pub mod structmember;
604604

605605
// "Limited API" definitions matching Python's `include/cpython` directory.
606-
#[cfg(not(Py_LIMITED_API))]
606+
#[cfg(not(any(Py_LIMITED_API, RustPython)))]
607607
mod cpython;
608608

609-
#[cfg(not(Py_LIMITED_API))]
609+
#[cfg(not(any(Py_LIMITED_API, RustPython)))]
610610
pub use self::cpython::*;

src/types/dict.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ pyobject_native_type!(
3636
);
3737

3838
#[cfg(RustPython)]
39-
pyobject_native_type!(
39+
pyobject_native_type_core!(
4040
PyDict,
41-
ffi::PyDictObject,
4241
|py| {
4342
static TYPE: PyOnceLock<Py<PyType>> = PyOnceLock::new();
4443
TYPE.import(py, "builtins", "dict").unwrap().as_type_ptr()

0 commit comments

Comments
 (0)