diff --git a/src/ffi/cpython/abstract_.rs b/src/ffi/cpython/abstract_.rs index a2246708864..9e376e88371 100644 --- a/src/ffi/cpython/abstract_.rs +++ b/src/ffi/cpython/abstract_.rs @@ -1,4 +1,4 @@ -use crate::ffi::{PyObject, Py_TYPE, Py_buffer, Py_ssize_t}; +use crate::ffi::{PyObject, Py_buffer, Py_ssize_t}; use libc::{c_char, c_int, c_void}; #[cfg(all(Py_3_8, not(PyPy)))] @@ -51,7 +51,7 @@ pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t { #[inline(always)] pub unsafe fn PyVectorcall_Function(callable: *mut PyObject) -> Option { assert!(!callable.is_null()); - let tp = Py_TYPE(callable); + let tp = crate::ffi::Py_TYPE(callable); if PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL) == 0 { return None; } @@ -218,7 +218,7 @@ extern "C" { #[cfg(not(any(Py_3_9, PyPy)))] #[inline] pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { - let tp_as_buffer = (*Py_TYPE(o)).tp_as_buffer; + let tp_as_buffer = (*crate::ffi::Py_TYPE(o)).tp_as_buffer; (!tp_as_buffer.is_null() && (*tp_as_buffer).bf_getbuffer.is_some()) as c_int } @@ -267,8 +267,9 @@ extern "C" { } #[inline] +#[cfg(not(any(all(Py_3_8, Py_LIMITED_API), PyPy)))] pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { - (match (*Py_TYPE(o)).tp_iternext { + (match (*crate::ffi::Py_TYPE(o)).tp_iternext { Some(tp_iternext) => { tp_iternext as *const c_void != crate::ffi::object::_PyObject_NextNotImplemented as _ } diff --git a/src/ffi/object.rs b/src/ffi/object.rs index 048b82afbaf..18671cd8900 100644 --- a/src/ffi/object.rs +++ b/src/ffi/object.rs @@ -1,6 +1,4 @@ use crate::ffi::pyport::{Py_hash_t, Py_ssize_t}; -#[cfg(PyPy)] -use std::ffi::CStr; use std::mem; use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; use std::ptr; @@ -75,17 +73,6 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } -#[cfg(PyPy)] -pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { - return crate::ffi::pyerrors::PyErr_Format( - crate::ffi::pyerrors::PyExc_TypeError, - CStr::from_bytes_with_nul(b"'%.200s' object is not iterable\0") - .unwrap() - .as_ptr(), - Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), - ); -} - #[inline] pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type diff --git a/src/ffi/objectabstract.rs b/src/ffi/objectabstract.rs index 0bc7daad628..c2403e1f526 100644 --- a/src/ffi/objectabstract.rs +++ b/src/ffi/objectabstract.rs @@ -86,7 +86,7 @@ extern "C" { pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; // PyIter_Check for unlimited API is in cpython/abstract_.rs - #[cfg(all(Py_LIMITED_API, Py_3_8))] + #[cfg(any(all(Py_LIMITED_API, Py_3_8), PyPy))] #[cfg_attr(PyPy, link_name = "PyPyIter_Check")] pub fn PyIter_Check(obj: *mut PyObject) -> c_int; } diff --git a/src/ffi/pythonrun.rs b/src/ffi/pythonrun.rs index 2f41759c2b6..27bcd9d34f5 100644 --- a/src/ffi/pythonrun.rs +++ b/src/ffi/pythonrun.rs @@ -157,7 +157,7 @@ extern "C" { } #[inline] -#[cfg(not(Py_LIMITED_API))] +#[cfg(any(not(Py_LIMITED_API), PyPy))] pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { #[cfg(not(PyPy))] return Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1);