Fix proc macro scoping for pyo3

This commit is contained in:
konstin 2018-06-15 22:50:26 +02:00
parent fd6ab73924
commit e374b5dd1d
6 changed files with 189 additions and 197 deletions

View File

@ -149,11 +149,11 @@ pub const CONTEXT: Proto = Proto {
py_methods: &[
PyMethod {
name: "__enter__",
proto: "_pyo3::class::context::PyContextEnterProtocolImpl",
proto: "::pyo3::class::context::PyContextEnterProtocolImpl",
},
PyMethod {
name: "__exit__",
proto: "_pyo3::class::context::PyContextExitProtocolImpl",
proto: "::pyo3::class::context::PyContextExitProtocolImpl",
},
],
};
@ -200,11 +200,11 @@ pub const DESCR: Proto = Proto {
py_methods: &[
PyMethod {
name: "__del__",
proto: "_pyo3::class::context::PyDescrDelProtocolImpl",
proto: "::pyo3::class::context::PyDescrDelProtocolImpl",
},
PyMethod {
name: "__set_name__",
proto: "_pyo3::class::context::PyDescrNameProtocolImpl",
proto: "::pyo3::class::context::PyDescrNameProtocolImpl",
},
],
};
@ -594,51 +594,51 @@ pub const NUM: Proto = Proto {
py_methods: &[
PyMethod {
name: "__radd__",
proto: "_pyo3::class::number::PyNumberRAddProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRAddProtocolImpl"},
PyMethod {
name: "__rsub__",
proto: "_pyo3::class::number::PyNumberRSubProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRSubProtocolImpl"},
PyMethod {
name: "__rmul__",
proto: "_pyo3::class::number::PyNumberRMulProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRMulProtocolImpl"},
PyMethod {
name: "__rmatmul__",
proto: "_pyo3::class::number::PyNumberRMatmulProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRMatmulProtocolImpl"},
PyMethod {
name: "__rtruediv__",
proto: "_pyo3::class::number::PyNumberRTruedivProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRTruedivProtocolImpl"},
PyMethod {
name: "__rfloordiv__",
proto: "_pyo3::class::number::PyNumberRFloordivProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRFloordivProtocolImpl"},
PyMethod {
name: "__rmod__",
proto: "_pyo3::class::number::PyNumberRModProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRModProtocolImpl"},
PyMethod {
name: "__rdivmod__",
proto: "_pyo3::class::number::PyNumberRDivmodProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRDivmodProtocolImpl"},
PyMethod {
name: "__rpow__",
proto: "_pyo3::class::number::PyNumberRPowProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRPowProtocolImpl"},
PyMethod {
name: "__rlshift__",
proto: "_pyo3::class::number::PyNumberRLShiftProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRLShiftProtocolImpl"},
PyMethod {
name: "__rrshift__",
proto: "_pyo3::class::number::PyNumberRRShiftProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRRShiftProtocolImpl"},
PyMethod {
name: "__rand__",
proto: "_pyo3::class::number::PyNumberRAndProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRAndProtocolImpl"},
PyMethod {
name: "__rxor__",
proto: "_pyo3::class::number::PyNumberRXorProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRXorProtocolImpl"},
PyMethod {
name: "__ror__",
proto: "_pyo3::class::number::PyNumberROrProtocolImpl"},
proto: "::pyo3::class::number::PyNumberROrProtocolImpl"},
PyMethod {
name: "__complex__",
proto: "_pyo3::class::number::PyNumberComplexProtocolImpl"},
proto: "::pyo3::class::number::PyNumberComplexProtocolImpl"},
PyMethod {
name: "__round__",
proto: "_pyo3::class::number::PyNumberRoundProtocolImpl"},
proto: "::pyo3::class::number::PyNumberRoundProtocolImpl"},
]
};

View File

@ -243,21 +243,20 @@ pub fn add_fn_to_module(
let tokens = quote! {
fn #function_wrapper_ident(py: ::pyo3::Python) -> ::pyo3::PyObject {
use std;
use pyo3 as _pyo3;
#wrapper
let _def = _pyo3::class::PyMethodDef {
let _def = ::pyo3::class::PyMethodDef {
ml_name: stringify!(#python_name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: #doc,
};
let function = unsafe {
_pyo3::PyObject::from_owned_ptr_or_panic(
::pyo3::PyObject::from_owned_ptr_or_panic(
py,
_pyo3::ffi::PyCFunction_New(
::pyo3::ffi::PyCFunction_New(
Box::into_raw(Box::new(_def.as_method_def())),
std::ptr::null_mut()
)
@ -294,20 +293,20 @@ fn function_c_wrapper(name: &syn::Ident, spec: &method::FnSpec) -> TokenStream {
quote! {
#[allow(unused_variables, unused_imports)]
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#name), "()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
}

View File

@ -47,7 +47,6 @@ pub fn build_py_class(
unused_qualifications, unused_variables, non_camel_case_types)]
const #dummy_const: () = {
use std;
use pyo3 as _pyo3;
#tokens
};
@ -105,36 +104,36 @@ fn impl_class(
let extra = if let Some(token) = token {
Some(quote! {
impl _pyo3::PyObjectWithToken for #cls {
impl ::pyo3::PyObjectWithToken for #cls {
#[inline(always)]
fn py<'p>(&'p self) -> _pyo3::Python<'p> {
fn py<'p>(&'p self) -> ::pyo3::Python<'p> {
self.#token.py()
}
}
impl _pyo3::ToPyObject for #cls {
impl ::pyo3::ToPyObject for #cls {
#[inline]
fn to_object<'p>(&self, py: _pyo3::Python<'p>) -> _pyo3::PyObject {
unsafe { _pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr()) }
fn to_object<'p>(&self, py: ::pyo3::Python<'p>) -> ::pyo3::PyObject {
unsafe { ::pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr()) }
}
}
impl _pyo3::ToBorrowedObject for #cls {
impl ::pyo3::ToBorrowedObject for #cls {
#[inline]
fn with_borrowed_ptr<F, R>(&self, _py: _pyo3::Python, f: F) -> R
where F: FnOnce(*mut _pyo3::ffi::PyObject) -> R
fn with_borrowed_ptr<F, R>(&self, _py: ::pyo3::Python, f: F) -> R
where F: FnOnce(*mut ::pyo3::ffi::PyObject) -> R
{
f(self.as_ptr())
}
}
impl<'a> _pyo3::ToPyObject for &'a mut #cls {
impl<'a> ::pyo3::ToPyObject for &'a mut #cls {
#[inline]
fn to_object<'p>(&self, py: _pyo3::Python<'p>) -> _pyo3::PyObject {
unsafe { _pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr()) }
fn to_object<'p>(&self, py: ::pyo3::Python<'p>) -> ::pyo3::PyObject {
unsafe { ::pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr()) }
}
}
impl<'a> _pyo3::ToBorrowedObject for &'a mut #cls {
impl<'a> ::pyo3::ToBorrowedObject for &'a mut #cls {
#[inline]
fn with_borrowed_ptr<F, R>(&self, _py: _pyo3::Python, f: F) -> R
where F: FnOnce(*mut _pyo3::ffi::PyObject) -> R
fn with_borrowed_ptr<F, R>(&self, _py: ::pyo3::Python, f: F) -> R
where F: FnOnce(*mut ::pyo3::ffi::PyObject) -> R
{
f(self.as_ptr())
}
@ -145,12 +144,12 @@ fn impl_class(
unsafe{std::mem::transmute(ob)}
}
}
impl _pyo3::ToPyPointer for #cls {
impl ::pyo3::ToPyPointer for #cls {
#[inline]
fn as_ptr(&self) -> *mut _pyo3::ffi::PyObject {
fn as_ptr(&self) -> *mut ::pyo3::ffi::PyObject {
unsafe {
{self as *const _ as *mut u8}
.offset(-<#cls as _pyo3::typeob::PyTypeInfo>::OFFSET) as *mut _pyo3::ffi::PyObject
.offset(-<#cls as ::pyo3::typeob::PyTypeInfo>::OFFSET) as *mut ::pyo3::ffi::PyObject
}
}
}
@ -176,16 +175,16 @@ fn impl_class(
let extra = {
if let Some(freelist) = params.get("freelist") {
Some(quote! {
impl _pyo3::freelist::PyObjectWithFreeList for #cls {
impl ::pyo3::freelist::PyObjectWithFreeList for #cls {
#[inline]
fn get_free_list() -> &'static mut _pyo3::freelist::FreeList<*mut _pyo3::ffi::PyObject> {
static mut FREELIST: *mut _pyo3::freelist::FreeList<*mut _pyo3::ffi::PyObject> = 0 as *mut _;
fn get_free_list() -> &'static mut ::pyo3::freelist::FreeList<*mut ::pyo3::ffi::PyObject> {
static mut FREELIST: *mut ::pyo3::freelist::FreeList<*mut ::pyo3::ffi::PyObject> = 0 as *mut _;
unsafe {
if FREELIST.is_null() {
FREELIST = Box::into_raw(Box::new(
_pyo3::freelist::FreeList::with_capacity(#freelist)));
::pyo3::freelist::FreeList::with_capacity(#freelist)));
<#cls as _pyo3::typeob::PyTypeObject>::init_type();
<#cls as ::pyo3::typeob::PyTypeObject>::init_type();
}
&mut *FREELIST
}
@ -215,26 +214,26 @@ fn impl_class(
let mut has_dict = false;
for f in flags.iter() {
if let syn::Expr::Path(ref epath) = f {
if epath.path == parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_WEAKREF} {
if epath.path == parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_WEAKREF} {
has_weakref = true;
} else if epath.path == parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_DICT} {
} else if epath.path == parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_DICT} {
has_dict = true;
}
}
}
let weakref = if has_weakref {
quote!{std::mem::size_of::<*const _pyo3::ffi::PyObject>()}
quote!{std::mem::size_of::<*const ::pyo3::ffi::PyObject>()}
} else {
quote!{0}
};
let dict = if has_dict {
quote!{std::mem::size_of::<*const _pyo3::ffi::PyObject>()}
quote!{std::mem::size_of::<*const ::pyo3::ffi::PyObject>()}
} else {
quote!{0}
};
quote! {
impl _pyo3::typeob::PyTypeInfo for #cls {
impl ::pyo3::typeob::PyTypeInfo for #cls {
type Type = #cls;
type BaseType = #base;
@ -249,35 +248,35 @@ fn impl_class(
const OFFSET: isize = {
// round base_size up to next multiple of align
(
(<#base as _pyo3::typeob::PyTypeInfo>::SIZE +
(<#base as ::pyo3::typeob::PyTypeInfo>::SIZE +
std::mem::align_of::<#cls>() - 1) /
std::mem::align_of::<#cls>() * std::mem::align_of::<#cls>()
) as isize
};
#[inline]
unsafe fn type_object() -> &'static mut _pyo3::ffi::PyTypeObject {
static mut TYPE_OBJECT: _pyo3::ffi::PyTypeObject = _pyo3::ffi::PyTypeObject_INIT;
unsafe fn type_object() -> &'static mut ::pyo3::ffi::PyTypeObject {
static mut TYPE_OBJECT: ::pyo3::ffi::PyTypeObject = ::pyo3::ffi::PyTypeObject_INIT;
&mut TYPE_OBJECT
}
}
impl _pyo3::typeob::PyTypeObject for #cls {
impl ::pyo3::typeob::PyTypeObject for #cls {
#[inline(always)]
fn init_type() {
static START: std::sync::Once = std::sync::ONCE_INIT;
START.call_once(|| {
let ty = unsafe{<#cls as _pyo3::typeob::PyTypeInfo>::type_object()};
let ty = unsafe{<#cls as ::pyo3::typeob::PyTypeInfo>::type_object()};
if (ty.tp_flags & _pyo3::ffi::Py_TPFLAGS_READY) == 0 {
let gil = _pyo3::Python::acquire_gil();
if (ty.tp_flags & ::pyo3::ffi::Py_TPFLAGS_READY) == 0 {
let gil = ::pyo3::Python::acquire_gil();
let py = gil.python();
// automatically initialize the class on-demand
_pyo3::typeob::initialize_type::<#cls>(py, None)
::pyo3::typeob::initialize_type::<#cls>(py, None)
.map_err(|e| e.print(py))
.expect(format!("An error occurred while initializing class {}",
<#cls as _pyo3::typeob::PyTypeInfo>::NAME).as_ref());
<#cls as ::pyo3::typeob::PyTypeInfo>::NAME).as_ref());
}
});
}
@ -299,7 +298,7 @@ fn impl_descriptors(
FnType::Getter(_) => {
quote! {
impl #cls {
fn #name(&self) -> _pyo3::PyResult<#field_ty> {
fn #name(&self) -> ::pyo3::PyResult<#field_ty> {
Ok(self.#name.clone())
}
}
@ -309,7 +308,7 @@ fn impl_descriptors(
let setter_name = syn::Ident::new(&format!("set_{}", name), Span::call_site());
quote! {
impl #cls {
fn #setter_name(&mut self, value: #field_ty) -> _pyo3::PyResult<()> {
fn #setter_name(&mut self, value: #field_ty) -> ::pyo3::PyResult<()> {
self.#name = value;
Ok(())
}
@ -364,9 +363,9 @@ fn impl_descriptors(
let tokens = quote! {
#(#methods)*
impl _pyo3::class::methods::PyPropMethodsProtocolImpl for #cls {
fn py_methods() -> &'static [_pyo3::class::PyMethodDefType] {
static METHODS: &'static [_pyo3::class::PyMethodDefType] = &[
impl ::pyo3::class::methods::PyPropMethodsProtocolImpl for #cls {
fn py_methods() -> &'static [::pyo3::class::PyMethodDefType] {
static METHODS: &'static [::pyo3::class::PyMethodDefType] = &[
#(#py_methods),*
];
METHODS
@ -381,14 +380,12 @@ fn impl_descriptors(
_ => "CLS_METHODS".to_string()
};
let dummy_const = syn::Ident::new(&format!("_IMPL_PYO3_DESCRIPTORS_{}", n), Span::call_site());
let dummy_const = syn::Ident::new(&format!("_IMPL_pyo3_DESCRIPTORS_{}", n), Span::call_site());
quote! {
#[feature(specialization)]
#[allow(non_upper_case_globals, unused_attributes,
unused_qualifications, unused_variables, unused_imports)]
const #dummy_const: () = {
use pyo3 as _pyo3;
#tokens
};
}
@ -416,7 +413,7 @@ fn parse_attribute(
let mut params = HashMap::new();
let mut flags = vec![syn::Expr::Lit(parse_quote!{0})];
let mut base: syn::TypePath = parse_quote!{_pyo3::PyObjectRef};
let mut base: syn::TypePath = parse_quote!{::pyo3::PyObjectRef};
for expr in args.iter() {
match expr {
@ -425,16 +422,16 @@ fn parse_attribute(
syn::Expr::Path(ref exp) if exp.path.segments.len() == 1 => {
match exp.path.segments.first().unwrap().value().ident.to_string().as_str() {
"gc" => {
flags.push(syn::Expr::Path(parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_GC}));
flags.push(syn::Expr::Path(parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_GC}));
}
"weakref" => {
flags.push(syn::Expr::Path(parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_WEAKREF}));
flags.push(syn::Expr::Path(parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_WEAKREF}));
}
"subclass" => {
flags.push(syn::Expr::Path(parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_BASETYPE}));
flags.push(syn::Expr::Path(parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_BASETYPE}));
}
"dict" => {
flags.push(syn::Expr::Path(parse_quote!{_pyo3::typeob::PY_TYPE_FLAG_DICT}));
flags.push(syn::Expr::Path(parse_quote!{::pyo3::typeob::PY_TYPE_FLAG_DICT}));
}
param => {
println!("Unsupported parameter: {}", param);

View File

@ -26,9 +26,9 @@ pub fn impl_methods(ty: &syn::Type, impls: &mut Vec<syn::ImplItem>) -> TokenStre
}
let tokens = quote! {
impl _pyo3::class::methods::PyMethodsProtocolImpl for #ty {
fn py_methods() -> &'static [_pyo3::class::PyMethodDefType] {
static METHODS: &'static [_pyo3::class::PyMethodDefType] = &[
impl ::pyo3::class::methods::PyMethodsProtocolImpl for #ty {
fn py_methods() -> &'static [::pyo3::class::PyMethodDefType] {
static METHODS: &'static [::pyo3::class::PyMethodDefType] = &[
#(#methods),*
];
METHODS
@ -48,8 +48,6 @@ pub fn impl_methods(ty: &syn::Type, impls: &mut Vec<syn::ImplItem>) -> TokenStre
#[allow(non_upper_case_globals, unused_attributes,
unused_qualifications, unused_variables, unused_imports)]
const #dummy_const: () = {
use pyo3 as _pyo3;
#tokens
};
}

View File

@ -66,17 +66,17 @@ pub fn impl_wrap(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec, noargs: bool
quote! {
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(
stringify!(#cls), ".", stringify!(#name), "()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
#body_to_result
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
} else {
@ -85,22 +85,22 @@ pub fn impl_wrap(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec, noargs: bool
quote! {
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
use pyo3::ToPyPointer;
const _LOCATION: &'static str = concat!(
stringify!(#cls), ".", stringify!(#name), "()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
}
@ -114,22 +114,22 @@ pub fn impl_proto_wrap(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Tok
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
let _result = {
#body
};
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
}
@ -149,20 +149,20 @@ pub fn impl_wrap_new(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Token
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_cls: *mut _pyo3::ffi::PyTypeObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_cls: *mut ::pyo3::ffi::PyTypeObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
use std::ptr;
use pyo3::typeob::PyTypeInfo;
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
match _pyo3::typeob::PyRawObject::new(_py, #cls::type_object(), _cls) {
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
match ::pyo3::typeob::PyRawObject::new(_py, #cls::type_object(), _cls) {
Ok(_obj) => {
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
@ -199,16 +199,16 @@ fn impl_wrap_init(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> TokenStr
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> _pyo3::c_int
_slf: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> ::pyo3::c_int
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
match _result {
@ -237,20 +237,20 @@ pub fn impl_wrap_class(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Tok
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_cls: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_cls: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _cls = _pyo3::PyType::from_type_ptr(_py, _cls as *mut _pyo3::ffi::PyTypeObject);
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _cls = ::pyo3::PyType::from_type_ptr(_py, _cls as *mut ::pyo3::ffi::PyTypeObject);
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
}
@ -270,19 +270,19 @@ pub fn impl_wrap_static(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> To
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject,
_args: *mut ::pyo3::ffi::PyObject,
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _args = _py.from_borrowed_ptr::<::pyo3::PyTuple>(_args);
let _kwargs = ::pyo3::argparse::get_kwargs(_py, _kwargs);
#body_to_result
_pyo3::callback::cb_convert(
_pyo3::callback::PyObjectCallbackConverter, _py, _result)
::pyo3::callback::cb_convert(
::pyo3::callback::PyObjectCallbackConverter, _py, _result)
}
}
}
@ -291,13 +291,13 @@ pub fn impl_wrap_static(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> To
pub(crate) fn impl_wrap_getter(cls: &syn::Type, name: &syn::Ident) -> TokenStream {
quote! {
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject, _: *mut _pyo3::c_void) -> *mut _pyo3::ffi::PyObject
_slf: *mut ::pyo3::ffi::PyObject, _: *mut ::pyo3::c_void) -> *mut ::pyo3::ffi::PyObject
{
use std;
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
match _slf.#name() {
@ -323,16 +323,16 @@ pub(crate) fn impl_wrap_setter(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec
quote! {
#[allow(unused_mut)]
unsafe extern "C" fn __wrap(
_slf: *mut _pyo3::ffi::PyObject,
_value: *mut _pyo3::ffi::PyObject, _: *mut _pyo3::c_void) -> _pyo3::c_int
_slf: *mut ::pyo3::ffi::PyObject,
_value: *mut ::pyo3::ffi::PyObject, _: *mut ::pyo3::c_void) -> ::pyo3::c_int
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = _pyo3::GILPool::new();
let _py = _pyo3::Python::assume_gil_acquired();
let _pool = ::pyo3::GILPool::new();
let _py = ::pyo3::Python::assume_gil_acquired();
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _value = _py.from_borrowed_ptr(_value);
let _result = match <#val_ty as _pyo3::FromPyObject>::extract(_value) {
let _result = match <#val_ty as ::pyo3::FromPyObject>::extract(_value) {
Ok(_val) => _slf.#name(_val),
Err(e) => Err(e)
};
@ -392,7 +392,7 @@ pub fn impl_arg_params(spec: &FnSpec, body: TokenStream) -> TokenStream {
params.push(
quote! {
_pyo3::argparse::ParamDescription{
::pyo3::argparse::ParamDescription{
name: stringify!(#name), is_optional: #opt, kw_only: #kwonly}
}
);
@ -419,12 +419,12 @@ pub fn impl_arg_params(spec: &FnSpec, body: TokenStream) -> TokenStream {
// create array of arguments, and then parse
quote! {
const _PARAMS: &'static [_pyo3::argparse::ParamDescription<'static>] = &[
const _PARAMS: &'static [::pyo3::argparse::ParamDescription<'static>] = &[
#(#params),*
];
let mut _output = [#(#placeholders),*];
match _pyo3::argparse::parse_args(Some(_LOCATION), _PARAMS, &_args,
match ::pyo3::argparse::parse_args(Some(_LOCATION), _PARAMS, &_args,
_kwargs, #accept_args, #accept_kwargs, &mut _output)
{
Ok(_) => {
@ -527,26 +527,26 @@ pub fn impl_py_method_def(name: &syn::Ident, doc: syn::Lit, spec: &FnSpec, wrapp
{
if spec.args.is_empty() {
quote! {
_pyo3::class::PyMethodDefType::Method({
::pyo3::class::PyMethodDefType::Method({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyNoArgsFunction(__wrap),
ml_flags: _pyo3::ffi::METH_NOARGS,
ml_meth: ::pyo3::class::PyMethodType::PyNoArgsFunction(__wrap),
ml_flags: ::pyo3::ffi::METH_NOARGS,
ml_doc: #doc,
}
})
}
} else {
quote! {
_pyo3::class::PyMethodDefType::Method({
::pyo3::class::PyMethodDefType::Method({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: #doc,
}
})
@ -557,13 +557,13 @@ pub fn impl_py_method_def(name: &syn::Ident, doc: syn::Lit, spec: &FnSpec, wrapp
pub fn impl_py_method_def_new(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenStream) -> TokenStream
{
quote! {
_pyo3::class::PyMethodDefType::New({
::pyo3::class::PyMethodDefType::New({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyNewFunc(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyNewFunc(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: #doc,
}
})
@ -573,13 +573,13 @@ pub fn impl_py_method_def_new(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenS
pub fn impl_py_method_def_init(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenStream) -> TokenStream
{
quote! {
_pyo3::class::PyMethodDefType::Init({
::pyo3::class::PyMethodDefType::Init({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyInitFunc(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyInitFunc(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: #doc,
}
})
@ -589,14 +589,14 @@ pub fn impl_py_method_def_init(name: &syn::Ident, doc: syn::Lit, wrapper: &Token
pub fn impl_py_method_def_class(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenStream) -> TokenStream
{
quote! {
_pyo3::class::PyMethodDefType::Class({
::pyo3::class::PyMethodDefType::Class({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS |
_pyo3::ffi::METH_CLASS,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS |
::pyo3::ffi::METH_CLASS,
ml_doc: #doc,
}
})
@ -606,13 +606,13 @@ pub fn impl_py_method_def_class(name: &syn::Ident, doc: syn::Lit, wrapper: &Toke
pub fn impl_py_method_def_static(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenStream) -> TokenStream
{
quote! {
_pyo3::class::PyMethodDefType::Static({
::pyo3::class::PyMethodDefType::Static({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS | _pyo3::ffi::METH_STATIC,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS | ::pyo3::ffi::METH_STATIC,
ml_doc: #doc,
}
})
@ -622,13 +622,13 @@ pub fn impl_py_method_def_static(name: &syn::Ident, doc: syn::Lit, wrapper: &Tok
pub fn impl_py_method_def_call(name: &syn::Ident, doc: syn::Lit, wrapper: &TokenStream) -> TokenStream
{
quote! {
_pyo3::class::PyMethodDefType::Call({
::pyo3::class::PyMethodDefType::Call({
#wrapper
_pyo3::class::PyMethodDef {
::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: #doc,
}
})
@ -650,10 +650,10 @@ pub(crate) fn impl_py_setter_def(name: &syn::Ident, doc: syn::Lit, setter: &Opti
};
quote! {
_pyo3::class::PyMethodDefType::Setter({
::pyo3::class::PyMethodDefType::Setter({
#wrapper
_pyo3::class::PySetterDef {
::pyo3::class::PySetterDef {
name: #n,
meth: __wrap,
doc: #doc,
@ -677,10 +677,10 @@ pub(crate) fn impl_py_getter_def(name: &syn::Ident, doc: syn::Lit, getter: &Opti
};
quote! {
_pyo3::class::PyMethodDefType::Getter({
::pyo3::class::PyMethodDefType::Getter({
#wrapper
_pyo3::class::PyGetterDef {
::pyo3::class::PyGetterDef {
name: #n,
meth: __wrap,
doc: #doc,

View File

@ -89,13 +89,13 @@ fn impl_proto_impl(
impl #proto for #ty
{
#[inline]
fn #name() -> Option<_pyo3::class::methods::PyMethodDef> {
fn #name() -> Option<::pyo3::class::methods::PyMethodDef> {
#meth
Some(_pyo3::class::PyMethodDef {
Some(::pyo3::class::PyMethodDef {
ml_name: stringify!(#name),
ml_meth: _pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: _pyo3::ffi::METH_VARARGS | _pyo3::ffi::METH_KEYWORDS,
ml_meth: ::pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap),
ml_flags: ::pyo3::ffi::METH_VARARGS | ::pyo3::ffi::METH_KEYWORDS,
ml_doc: ""})
}
}
@ -123,8 +123,6 @@ fn impl_proto_impl(
unused_qualifications, unused_variables,
unused_imports)]
const #dummy_const: () = {
use pyo3 as _pyo3;
#tokens
#(#py_methods)*