Merge pull request #2144 from davidhewitt/cleanup-ffi-call

chore: cleanup old todo
This commit is contained in:
David Hewitt 2022-02-05 10:00:18 +00:00 committed by GitHub
commit 02b7f99d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View File

@ -580,12 +580,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! {
// TODO: Use PyObject_CallNoArgs instead after https://bugs.python.org/issue42415.
// Once the issue is resolved, we can enable this optimization for limited API.
if #[cfg(all(Py_3_9, not(Py_LIMITED_API)))] {
if #[cfg(Py_3_9)] {
// Optimized path on python 3.9+
unsafe {
PyObject::from_owned_ptr_or_err(py, ffi::_PyObject_CallNoArg(self.as_ptr()))
PyObject::from_owned_ptr_or_err(py, ffi::PyObject_CallNoArgs(self.as_ptr()))
}
} else {
self.call(py, (), None)
@ -923,7 +921,23 @@ impl PyObject {
mod tests {
use super::{Py, PyObject};
use crate::types::PyDict;
use crate::Python;
use crate::{Python, ToPyObject};
#[test]
fn test_call0() {
Python::with_gil(|py| {
let obj = py.get_type::<PyDict>().to_object(py);
assert_eq!(
obj.call0(py)
.unwrap()
.as_ref(py)
.repr()
.unwrap()
.to_string_lossy(),
"{}"
);
})
}
#[test]
fn test_call_for_non_existing_method() {

View File

@ -333,12 +333,10 @@ impl PyAny {
/// This is equivalent to the Python expression `help()`.
pub fn call0(&self) -> PyResult<&PyAny> {
cfg_if::cfg_if! {
// TODO: Use PyObject_CallNoArgs instead after https://bugs.python.org/issue42415.
// Once the issue is resolved, we can enable this optimization for limited API.
if #[cfg(all(Py_3_9, not(Py_LIMITED_API)))] {
if #[cfg(Py_3_9)] {
// Optimized path on python 3.9+
unsafe {
self.py().from_owned_ptr_or_err(ffi::_PyObject_CallNoArg(self.as_ptr()))
self.py().from_owned_ptr_or_err(ffi::PyObject_CallNoArgs(self.as_ptr()))
}
} else {
self.call((), None)