add agr extraction for setters, allow non snake vars

This commit is contained in:
Nikolay Kim 2017-05-18 14:46:29 -07:00
parent 93c3d9cebf
commit 7a4a736d92
4 changed files with 22 additions and 8 deletions

View file

@ -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));
quote! {
#[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: () = {
extern crate pyo3 as _pyo3;
use std;
@ -86,7 +87,7 @@ fn impl_storage(cls: &syn::Ident, base: &syn::Ident, fields: &Vec<syn::Field>) -
}
quote! {
struct #storage {
pub struct #storage {
#(#fields),*
}

View file

@ -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));
quote! {
#[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: () = {
extern crate pyo3 as _pyo3;

View file

@ -331,7 +331,10 @@ fn impl_wrap_getter(cls: &Box<syn::Ty>,
/// Generate functiona wrapper (PyCFunction, PyCFunctionWithKeywords)
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! {
unsafe extern "C" fn wrap(slf: *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)
.unchecked_cast_into::<#cls>();
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(value, py);
ret.map(|o| ())
ret
})
}
}

View file

@ -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));
quote! {
#[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: () = {
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));
quote! {
#[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: () = {
extern crate pyo3 as _pyo3;