diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b7959e0d0..8240d9ae7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Remove FFI definition `PyCFunction_ClearFreeList` for Python 3.9 and later. [#1425](https://github.com/PyO3/pyo3/pull/1425) - `PYO3_CROSS_LIB_DIR` enviroment variable no long required when compiling for x86-64 Python from macOS arm64 and reverse. [#1428](https://github.com/PyO3/pyo3/pull/1428) - Fix FFI definition `_PyEval_RequestCodeExtraIndex` which took an argument of the wrong type. [#1429](https://github.com/PyO3/pyo3/pull/1429) +- Fix FFI definition `PyIndex_Check` missing with the `abi3` feature. [#1436](https://github.com/PyO3/pyo3/pull/1436) ## [0.13.2] - 2021-02-12 ### Packaging diff --git a/src/ffi/objectabstract.rs b/src/ffi/abstract_.rs similarity index 93% rename from src/ffi/objectabstract.rs rename to src/ffi/abstract_.rs index c2403e1f526..e4ee4eadfe9 100644 --- a/src/ffi/objectabstract.rs +++ b/src/ffi/abstract_.rs @@ -51,6 +51,9 @@ extern "C" { ... ) -> *mut PyObject; + // skipped _PyObject_CallFunction_SizeT + // skipped _PyObject_CallMethod_SizeT + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] @@ -84,16 +87,30 @@ extern "C" { pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; +} - // PyIter_Check for unlimited API is in cpython/abstract_.rs - #[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; +// Defined as this macro in Python 3.6, 3.7 limited API, but relies on +// non-limited PyTypeObject. Don't expose this since it cannot be used. +#[cfg(not(any(Py_LIMITED_API, PyPy)))] +#[inline] +pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { + (match (*crate::ffi::Py_TYPE(o)).tp_iternext { + Some(tp_iternext) => { + tp_iternext as *const std::os::raw::c_void + != crate::ffi::_PyObject_NextNotImplemented as _ + } + None => false, + }) as c_int } extern "C" { + #[cfg(any(all(Py_3_8, Py_LIMITED_API), PyPy))] + #[cfg_attr(PyPy, link_name = "PyPyIter_Check")] + pub fn PyIter_Check(obj: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; + // skipped non-limited / 3.10 PyIter_Send #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; @@ -134,12 +151,10 @@ extern "C" { pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - - #[cfg(PyPy)] - #[link_name = "PyPyIndex_Check"] - pub fn PyIndex_Check(o: *mut PyObject) -> c_int; } +// Defined as this macro in Python 3.6, 3.7 limited API, but relies on +// non-limited PyTypeObject. Don't expose this since it cannot be used. #[cfg(not(any(Py_LIMITED_API, PyPy)))] #[inline] pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { @@ -148,6 +163,10 @@ pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { } extern "C" { + #[cfg(any(all(Py_3_8, Py_LIMITED_API), PyPy))] + #[link_name = "PyPyIndex_Check"] + pub fn PyIndex_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] @@ -232,7 +251,9 @@ extern "C" { pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) -> *mut PyObject; - // TODO: PySequence_Fast macros + // skipped PySequenc_Fast_GET_SIZE + // skipped PySequenc_Fast_GET_ITEM + // skipped PySequenc_Fast_GET_ITEMS pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int; diff --git a/src/ffi/cpython/abstract_.rs b/src/ffi/cpython/abstract_.rs index 3dd33c49c94..b86ed1a7008 100644 --- a/src/ffi/cpython/abstract_.rs +++ b/src/ffi/cpython/abstract_.rs @@ -266,16 +266,11 @@ extern "C" { pub fn PyBuffer_Release(view: *mut Py_buffer); } -#[inline] -#[cfg(not(any(all(Py_3_8, Py_LIMITED_API), PyPy)))] -pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { - (match (*crate::ffi::Py_TYPE(o)).tp_iternext { - Some(tp_iternext) => { - tp_iternext as *const c_void != crate::ffi::_PyObject_NextNotImplemented as _ - } - None => false, - }) as c_int -} +// PyIter_Check defined in ffi/abstract_.rs +// PyIndex_Check defined in ffi/abstract_.rs +// Not defined here because this file is not compiled under the +// limited API, but the macros need to be defined for 3.6, 3.7 which +// predate the limited API changes. // skipped PySequence_ITEM diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 73fa2e3e547..bc739b681db 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -12,6 +12,7 @@ macro_rules! opaque_struct { }; } +pub use self::abstract_::*; pub use self::bltinmodule::*; pub use self::boolobject::*; pub use self::bytearrayobject::*; @@ -47,7 +48,6 @@ pub use self::methodobject::*; pub use self::modsupport::*; pub use self::moduleobject::*; pub use self::object::*; -pub use self::objectabstract::*; // FIXME: no matching objectabstract.h in cpython master pub use self::objimpl::*; pub use self::osmodule::*; pub use self::pyarena::*; @@ -76,8 +76,7 @@ pub use self::weakrefobject::*; #[cfg(not(Py_LIMITED_API))] pub use self::cpython::*; - -// skipped abstract.h +mod abstract_; // skipped asdl.h // skipped ast.h mod bltinmodule; @@ -200,8 +199,6 @@ mod pythonrun; // TODO some functions need to be moved to pylifecycle mod osmodule; mod sysmodule; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod objectabstract; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 - // mod pyctype; TODO excluded by PEP-384 mod pystrtod; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // mod pystrcmp; TODO nothing interesting for Rust? diff --git a/src/ffi/pyerrors.rs b/src/ffi/pyerrors.rs index 4bd08d66d1d..f5b99fe1f2e 100644 --- a/src/ffi/pyerrors.rs +++ b/src/ffi/pyerrors.rs @@ -1,9 +1,5 @@ use crate::ffi::object::*; -#[cfg(PyPy)] -use crate::ffi::objectabstract::PyObject_CallFunction; use crate::ffi::pyport::Py_ssize_t; -#[cfg(PyPy)] -use std::ffi::CStr; use std::os::raw::{c_char, c_int}; #[repr(C)] @@ -162,9 +158,11 @@ pub unsafe fn PyUnicodeDecodeError_Create( end: Py_ssize_t, _reason: *const c_char, ) -> *mut PyObject { - return PyObject_CallFunction( + return crate::ffi::PyObject_CallFunction( PyExc_UnicodeDecodeError, - CStr::from_bytes_with_nul(b"sy#nns\0").unwrap().as_ptr(), + std::ffi::CStr::from_bytes_with_nul(b"sy#nns\0") + .unwrap() + .as_ptr(), encoding, object, length,