Skip to content

Commit 21ad52a

Browse files
committed
Replace PyFunction_New with extern C function.
PyFunction_New was previously implemented as a Rust function wrapper around a call to the extern C function PyFunction_NewExt with a hard-coded third argument. This commit removes the Rust wrapper and directly exposes the function from the CPython API.
1 parent ffe543f commit 21ad52a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/ffi/methodobject.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ffi::object::{PyObject, PyTypeObject, Py_TYPE};
2+
use std::mem;
23
use std::os::raw::{c_char, c_int};
3-
use std::{mem, ptr};
44

55
#[cfg_attr(windows, link(name = "pythonXY"))]
66
extern "C" {
@@ -96,19 +96,16 @@ impl Default for PyMethodDef {
9696
}
9797
}
9898

99-
#[inline]
100-
pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject {
101-
#[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")]
102-
PyCFunction_NewEx(ml, slf, ptr::null_mut())
103-
}
104-
10599
extern "C" {
106100
#[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")]
107101
pub fn PyCFunction_NewEx(
108-
arg1: *mut PyMethodDef,
109-
arg2: *mut PyObject,
110-
arg3: *mut PyObject,
102+
ml: *mut PyMethodDef,
103+
slf: *mut PyObject,
104+
module: *mut PyObject,
111105
) -> *mut PyObject;
106+
107+
#[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")]
108+
pub fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject;
112109
}
113110

114111
/* Flag passed to newmethodobject */

0 commit comments

Comments
 (0)