From 3fd0c0e1421c71b0e5755427eaaa886cc67cd9c1 Mon Sep 17 00:00:00 2001 From: Andrew Burkett Date: Thu, 23 Jun 2022 13:31:44 -0700 Subject: [PATCH] Fix PyObject_CallNoArgs python version cfg (#2476) * Fix PyObject_CallNoArgs python version cfg PyObject_CallNoArgs was added to python 3.9 but not to limited api until 3.10 per https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs * Update change log * Fix uses of PyObject_CallNoArgs Co-authored-by: Andrew Burkett --- CHANGELOG.md | 1 + pyo3-ffi/src/abstract_.rs | 2 +- src/instance.rs | 5 ++++- src/types/any.rs | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6daf92c..d55bec9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix `#[pyo3(from_py_with = "...")]` being ignored for 1-element tuple structs and transparent structs. [#2440](https://github.com/PyO3/pyo3/pull/2440) - Use `memoffset` for computing PyCell offsets [#2450](https://github.com/PyO3/pyo3/pull/2450) - Fix incorrect enum names being returned by `repr` for enums renamed by `#[pyclass(name)]` [#2457](https://github.com/PyO3/pyo3/pull/2457) +- Fix incorrect Python version cfg definition on `PyObject_CallNoArgs`[#2476](https://github.com/PyO3/pyo3/pull/2476) ## [0.16.5] - 2022-05-15 diff --git a/pyo3-ffi/src/abstract_.rs b/pyo3-ffi/src/abstract_.rs index 172396aa..b8306ca9 100644 --- a/pyo3-ffi/src/abstract_.rs +++ b/pyo3-ffi/src/abstract_.rs @@ -23,7 +23,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ extern "C" { #[cfg(all( not(PyPy), - any(not(Py_LIMITED_API), Py_3_9) // Added to limited API in 3.9 + any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // Added to python in 3.9 but to limited API in 3.10 ))] pub fn PyObject_CallNoArgs(func: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] diff --git a/src/instance.rs b/src/instance.rs index cc27156c..9abc9383 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -647,7 +647,10 @@ impl Py { /// This is equivalent to the Python expression `self()`. pub fn call0(&self, py: Python<'_>) -> PyResult { cfg_if::cfg_if! { - if #[cfg(all(Py_3_9, not(PyPy)))] { + if #[cfg(all( + not(PyPy), + any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // PyObject_CallNoArgs was added to python in 3.9 but to limited API in 3.10 + ))] { // Optimized path on python 3.9+ unsafe { PyObject::from_owned_ptr_or_err(py, ffi::PyObject_CallNoArgs(self.as_ptr())) diff --git a/src/types/any.rs b/src/types/any.rs index c6cbf6ae..bdb7a932 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -484,7 +484,10 @@ impl PyAny { /// This is equivalent to the Python expression `help()`. pub fn call0(&self) -> PyResult<&PyAny> { cfg_if::cfg_if! { - if #[cfg(all(Py_3_9, not(PyPy)))] { + if #[cfg(all( + not(PyPy), + any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // PyObject_CallNoArgs was added to python in 3.9 but to limited API in 3.10 + ))] { // Optimized path on python 3.9+ unsafe { self.py().from_owned_ptr_or_err(ffi::PyObject_CallNoArgs(self.as_ptr()))