Skip to content

Commit

Permalink
Fix PyObject_CallNoArgs python version cfg (#2476)
Browse files Browse the repository at this point in the history
* 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 <andrew.burkett@crowdstrike.com>
  • Loading branch information
drewkett and Andrew Burkett authored Jun 23, 2022
1 parent bde5102 commit 3fd0c0e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/abstract_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 4 additions & 1 deletion src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,10 @@ impl<T> Py<T> {
/// This is equivalent to the Python expression `self()`.
pub fn call0(&self, py: Python<'_>) -> PyResult<PyObject> {
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()))
Expand Down
5 changes: 4 additions & 1 deletion src/types/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 3fd0c0e

Please sign in to comment.