add agr extraction for setters, allow non snake vars
This commit is contained in:
parent
93c3d9cebf
commit
7a4a736d92
|
@ -39,7 +39,8 @@ pub fn build_py_class(ast: &mut syn::DeriveInput) -> Tokens {
|
||||||
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_CLS_{}", ast.ident));
|
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_CLS_{}", ast.ident));
|
||||||
quote! {
|
quote! {
|
||||||
#[feature(specialization)]
|
#[feature(specialization)]
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes,
|
||||||
|
unused_qualifications, unused_variables, non_camel_case_types)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
extern crate pyo3 as _pyo3;
|
extern crate pyo3 as _pyo3;
|
||||||
use std;
|
use std;
|
||||||
|
@ -86,7 +87,7 @@ fn impl_storage(cls: &syn::Ident, base: &syn::Ident, fields: &Vec<syn::Field>) -
|
||||||
}
|
}
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
struct #storage {
|
pub struct #storage {
|
||||||
#(#fields),*
|
#(#fields),*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,8 @@ fn impl_methods(ty: &Box<syn::Ty>, impls: &mut Vec<syn::ImplItem>) -> Tokens {
|
||||||
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_METHODS_{}", n));
|
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_METHODS_{}", n));
|
||||||
quote! {
|
quote! {
|
||||||
#[feature(specialization)]
|
#[feature(specialization)]
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes,
|
||||||
|
unused_qualifications, unused_variables)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
extern crate pyo3 as _pyo3;
|
extern crate pyo3 as _pyo3;
|
||||||
|
|
||||||
|
|
|
@ -331,7 +331,10 @@ fn impl_wrap_getter(cls: &Box<syn::Ty>,
|
||||||
|
|
||||||
/// Generate functiona wrapper (PyCFunction, PyCFunctionWithKeywords)
|
/// Generate functiona wrapper (PyCFunction, PyCFunctionWithKeywords)
|
||||||
fn impl_wrap_setter(cls: &Box<syn::Ty>,
|
fn impl_wrap_setter(cls: &Box<syn::Ty>,
|
||||||
name: &syn::Ident, _args: Vec<Arg>, _spec: Vec<FnSpec>) -> Tokens {
|
name: &syn::Ident, args: Vec<Arg>, _spec: Vec<FnSpec>) -> Tokens {
|
||||||
|
|
||||||
|
let val_ty = args[0].ty;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
unsafe extern "C" fn wrap(slf: *mut _pyo3::ffi::PyObject,
|
unsafe extern "C" fn wrap(slf: *mut _pyo3::ffi::PyObject,
|
||||||
value: *mut _pyo3::ffi::PyObject,
|
value: *mut _pyo3::ffi::PyObject,
|
||||||
|
@ -345,10 +348,17 @@ fn impl_wrap_setter(cls: &Box<syn::Ty>,
|
||||||
let slf = _pyo3::PyObject::from_borrowed_ptr(py, slf)
|
let slf = _pyo3::PyObject::from_borrowed_ptr(py, slf)
|
||||||
.unchecked_cast_into::<#cls>();
|
.unchecked_cast_into::<#cls>();
|
||||||
let value = _pyo3::PyObject::from_borrowed_ptr(py, value);
|
let value = _pyo3::PyObject::from_borrowed_ptr(py, value);
|
||||||
let ret = slf.#name(py, &value);
|
|
||||||
|
let ret = match <#val_ty as _pyo3::FromPyObject>::extract(py, &value) {
|
||||||
|
Ok(val) => {
|
||||||
|
let ret = slf.#name(py, val);
|
||||||
|
ret.map(|o| ())
|
||||||
|
}
|
||||||
|
Err(e) => Err(e)
|
||||||
|
};
|
||||||
_pyo3::PyDrop::release_ref(slf, py);
|
_pyo3::PyDrop::release_ref(slf, py);
|
||||||
_pyo3::PyDrop::release_ref(value, py);
|
_pyo3::PyDrop::release_ref(value, py);
|
||||||
ret.map(|o| ())
|
ret
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,8 @@ fn impl_proto_impl(ty: &Box<syn::Ty>, impls: &mut Vec<syn::ImplItem>, proto: &Pr
|
||||||
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_{}_{}", n, p));
|
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_{}_{}", n, p));
|
||||||
quote! {
|
quote! {
|
||||||
#[feature(specialization)]
|
#[feature(specialization)]
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes,
|
||||||
|
unused_qualifications, unused_variables)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
extern crate pyo3 as _pyo3;
|
extern crate pyo3 as _pyo3;
|
||||||
|
|
||||||
|
@ -244,7 +245,8 @@ fn impl_protocol(name: &'static str,
|
||||||
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_{}", name));
|
let dummy_const = syn::Ident::new(format!("_IMPL_PYO3_{}", name));
|
||||||
quote! {
|
quote! {
|
||||||
#[feature(specialization)]
|
#[feature(specialization)]
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes,
|
||||||
|
unused_qualifications, unused_variables)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
extern crate pyo3 as _pyo3;
|
extern crate pyo3 as _pyo3;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue