From 6c933ba0bfd6ba0e03d64e4ad18625301768cc6c Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 6 Mar 2024 10:52:11 +0100 Subject: [PATCH] PyPy: remove PyCode (PyCode_Type does not exist) --- pyo3-ffi/src/cpython/code.rs | 1 + src/types/code.rs | 14 ++++++++++++++ src/types/mod.rs | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pyo3-ffi/src/cpython/code.rs b/pyo3-ffi/src/cpython/code.rs index 05f21a137b5..498eab59cce 100644 --- a/pyo3-ffi/src/cpython/code.rs +++ b/pyo3-ffi/src/cpython/code.rs @@ -230,6 +230,7 @@ pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000; pub const CO_MAXBLOCKS: usize = 20; +#[cfg(not(PyPy))] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub static mut PyCode_Type: PyTypeObject; diff --git a/src/types/code.rs b/src/types/code.rs index 8956deb1a71..f60e7783aa4 100644 --- a/src/types/code.rs +++ b/src/types/code.rs @@ -10,3 +10,17 @@ pyobject_native_type_core!( pyobject_native_static_type_object!(ffi::PyCode_Type), #checkfunction=ffi::PyCode_Check ); + +#[cfg(test)] +mod tests { + use super::*; + use crate::types::PyTypeMethods; + use crate::{PyTypeInfo, Python}; + + #[test] + fn test_type_object() { + Python::with_gil(|py| { + assert_eq!(PyCode::type_object_bound(py).name().unwrap(), "code"); + }) + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index f0f025ee8e1..fc74b03de5b 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -5,7 +5,7 @@ pub use self::boolobject::{PyBool, PyBoolMethods}; pub use self::bytearray::{PyByteArray, PyByteArrayMethods}; pub use self::bytes::{PyBytes, PyBytesMethods}; pub use self::capsule::{PyCapsule, PyCapsuleMethods}; -#[cfg(not(Py_LIMITED_API))] +#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] pub use self::code::PyCode; pub use self::complex::{PyComplex, PyComplexMethods}; #[allow(deprecated)] @@ -316,7 +316,7 @@ pub(crate) mod boolobject; pub(crate) mod bytearray; pub(crate) mod bytes; pub(crate) mod capsule; -#[cfg(not(Py_LIMITED_API))] +#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] mod code; pub(crate) mod complex; #[cfg(not(Py_LIMITED_API))]