Skip to content

Commit

Permalink
[review] kngwyu
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 1, 2021
1 parent 3ef6c84 commit 3e2a5a5
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 119 deletions.
2 changes: 1 addition & 1 deletion examples/pyo3_benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn mixed_args<'a>(
}

#[pyfunction]
fn no_args<'a>() { }
fn no_args<'a>() {}

#[pymodule]
fn _pyo3_benchmarks(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
Expand Down
12 changes: 6 additions & 6 deletions pyo3-macros-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::pymethod::get_arg_names;
use crate::utils;
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{spanned::Spanned, Ident};
use syn::{spanned::Spanned, Ident, Result};

/// Generates the function that is called by the python interpreter to initialize the native
/// module
Expand Down Expand Up @@ -197,7 +197,7 @@ pub fn add_fn_to_module(

let name = &func.sig.ident;
let wrapper_ident = format_ident!("__pyo3_raw_{}", name);
let wrapper = function_c_wrapper(name, &wrapper_ident, &spec, pyfn_attrs.pass_module);
let wrapper = function_c_wrapper(name, &wrapper_ident, &spec, pyfn_attrs.pass_module)?;
Ok(quote! {
#wrapper
pub(crate) fn #function_wrapper_ident<'a>(
Expand All @@ -223,7 +223,7 @@ fn function_c_wrapper(
wrapper_ident: &Ident,
spec: &method::FnSpec<'_>,
pass_module: bool,
) -> TokenStream {
) -> Result<TokenStream> {
let names: Vec<Ident> = get_arg_names(&spec);
let cb;
let slf_module;
Expand All @@ -240,8 +240,8 @@ fn function_c_wrapper(
};
slf_module = None;
};
let body = pymethod::impl_arg_params(spec, None, cb);
quote! {
let body = pymethod::impl_arg_params(spec, None, cb)?;
Ok(quote! {
unsafe extern "C" fn #wrapper_ident(
_slf: *mut pyo3::ffi::PyObject,
_args: *mut pyo3::ffi::PyObject,
Expand All @@ -256,5 +256,5 @@ fn function_c_wrapper(
#body
})
}
}
})
}
Loading

0 comments on commit 3e2a5a5

Please sign in to comment.