Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 13 additions & 69 deletions pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,76 +911,20 @@ impl<'a> FnSpec<'a> {
FnType::FnStatic => quote! { .flags(#pyo3_path::ffi::METH_STATIC) },
_ => quote! {},
};
match self.convention {
CallingConvention::Noargs => quote! {
#pyo3_path::impl_::pymethods::PyMethodDef::noargs(
#python_name,
{
unsafe extern "C" fn trampoline(
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *mut #pyo3_path::ffi::PyObject,
) -> *mut #pyo3_path::ffi::PyObject
{
unsafe {
#pyo3_path::impl_::trampoline::noargs(
_slf,
_args,
#wrapper
)
}
}
trampoline
},
#doc,
) #flags
},
CallingConvention::Fastcall => quote! {
#pyo3_path::impl_::pymethods::PyMethodDef::fastcall_cfunction_with_keywords(
#python_name,
{
unsafe extern "C" fn trampoline(
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *const *mut #pyo3_path::ffi::PyObject,
_nargs: #pyo3_path::ffi::Py_ssize_t,
_kwnames: *mut #pyo3_path::ffi::PyObject
) -> *mut #pyo3_path::ffi::PyObject
{
#pyo3_path::impl_::trampoline::fastcall_with_keywords(
_slf,
_args,
_nargs,
_kwnames,
#wrapper
)
}
trampoline
},
#doc,
) #flags
},
CallingConvention::Varargs => quote! {
#pyo3_path::impl_::pymethods::PyMethodDef::cfunction_with_keywords(
#python_name,
{
unsafe extern "C" fn trampoline(
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *mut #pyo3_path::ffi::PyObject,
_kwargs: *mut #pyo3_path::ffi::PyObject,
) -> *mut #pyo3_path::ffi::PyObject
{
#pyo3_path::impl_::trampoline::cfunction_with_keywords(
_slf,
_args,
_kwargs,
#wrapper
)
}
trampoline
},
#doc,
) #flags
},
let trampoline = match self.convention {
CallingConvention::Noargs => Ident::new("noargs", Span::call_site()),
CallingConvention::Fastcall => {
Ident::new("fastcall_cfunction_with_keywords", Span::call_site())
}
CallingConvention::Varargs => Ident::new("cfunction_with_keywords", Span::call_site()),
CallingConvention::TpNew => unreachable!("tp_new cannot get a methoddef"),
};
quote! {
#pyo3_path::impl_::pymethods::PyMethodDef::#trampoline(
#python_name,
#pyo3_path::impl_::trampoline::get_trampoline_function!(#trampoline, #wrapper),
#doc,
) #flags
}
}

Expand Down
49 changes: 4 additions & 45 deletions pyo3-macros-backend/src/pymethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,22 +376,8 @@ pub fn impl_py_method_def_new(
#pyo3_path::ffi::PyType_Slot {
slot: #pyo3_path::ffi::Py_tp_new,
pfunc: {
unsafe extern "C" fn trampoline(
subtype: *mut #pyo3_path::ffi::PyTypeObject,
args: *mut #pyo3_path::ffi::PyObject,
kwargs: *mut #pyo3_path::ffi::PyObject,
) -> *mut #pyo3_path::ffi::PyObject {

#text_signature_impl

#pyo3_path::impl_::trampoline::newfunc(
subtype,
args,
kwargs,
#cls::#wrapper_ident
)
}
trampoline
#text_signature_impl
#pyo3_path::impl_::trampoline::get_trampoline_function!(newfunc, #cls::#wrapper_ident)
} as #pyo3_path::ffi::newfunc as _
}
};
Expand All @@ -413,22 +399,7 @@ fn impl_call_slot(cls: &syn::Type, mut spec: FnSpec<'_>, ctx: &Ctx) -> Result<Me
let slot_def = quote! {
#pyo3_path::ffi::PyType_Slot {
slot: #pyo3_path::ffi::Py_tp_call,
pfunc: {
unsafe extern "C" fn trampoline(
slf: *mut #pyo3_path::ffi::PyObject,
args: *mut #pyo3_path::ffi::PyObject,
kwargs: *mut #pyo3_path::ffi::PyObject,
) -> *mut #pyo3_path::ffi::PyObject
{
#pyo3_path::impl_::trampoline::ternaryfunc(
slf,
args,
kwargs,
#cls::#wrapper_ident
)
}
trampoline
} as #pyo3_path::ffi::ternaryfunc as _
pfunc: #pyo3_path::impl_::trampoline::get_trampoline_function!(ternaryfunc, #cls::#wrapper_ident) as _
}
};
Ok(MethodAndSlotDef {
Expand Down Expand Up @@ -1371,21 +1342,9 @@ impl SlotDef {
}
};
let slot_def = quote! {{
unsafe extern "C" fn trampoline(
_slf: *mut #pyo3_path::ffi::PyObject,
#(#arg_idents: #arg_types),*
) -> #ret_ty
{
#pyo3_path::impl_::trampoline:: #func_ty (
_slf,
#(#arg_idents,)*
#cls::#wrapper_ident
)
}

#pyo3_path::ffi::PyType_Slot {
slot: #pyo3_path::ffi::#slot,
pfunc: trampoline as #pyo3_path::ffi::#func_ty as _
pfunc: #pyo3_path::impl_::trampoline::get_trampoline_function!(#func_ty, #cls::#wrapper_ident) as #pyo3_path::ffi::#func_ty as _
}
}};
Ok(MethodAndSlotDef {
Expand Down
Loading
Loading