From 9a7fcf1de3471d87e368327dd7814e3c1436d0d8 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 19:13:39 -0800 Subject: [PATCH 01/10] move doc comments for extract! invocations --- src/objects/num.rs | 88 ++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/src/objects/num.rs b/src/objects/num.rs index 0a794ef1..31b27f7e 100644 --- a/src/objects/num.rs +++ b/src/objects/num.rs @@ -125,20 +125,23 @@ macro_rules! int_fits_c_long( } } - /// Converts Python integers to Rust integers. - /// - /// Returns OverflowError if the input integer does not fit the Rust type; - /// or TypeError if the input is not an integer. - extract!(obj to $rust_type; py => { - let val = unsafe { ffi::PyLong_AsLong(obj.as_ptr()) }; - if val == -1 && PyErr::occurred(py) { - return Err(PyErr::fetch(py)); - } - match cast::(val) { - Some(v) => Ok(v), - None => Err(overflow_error(py)) + extract!( + obj to $rust_type; + /// Converts Python integers to Rust integers. + /// + /// Returns OverflowError if the input integer does not fit the Rust type; + /// or TypeError if the input is not an integer. + py => { + let val = unsafe { ffi::PyLong_AsLong(obj.as_ptr()) }; + if val == -1 && PyErr::occurred(py) { + return Err(PyErr::fetch(py)); + } + match cast::(val) { + Some(v) => Ok(v), + None => Err(overflow_error(py)) + } } - }); + ); ) ); @@ -155,17 +158,20 @@ macro_rules! int_fits_larger_int( } } - /// Converts Python integers to Rust integers. - /// - /// Returns OverflowError if the input integer does not fit the Rust type; - /// or TypeError if the input is not an integer. - extract!(obj to $rust_type; py => { - let val = obj.extract::<$larger_type>(py)?; - match cast::<$larger_type, $rust_type>(val) { - Some(v) => Ok(v), - None => Err(overflow_error(py)) + extract!( + obj to $rust_type; + /// Converts Python integers to Rust integers. + /// + /// Returns OverflowError if the input integer does not fit the Rust type; + /// or TypeError if the input is not an integer. + py => { + let val = obj.extract::<$larger_type>(py)?; + match cast::<$larger_type, $rust_type>(val) { + Some(v) => Ok(v), + None => Err(overflow_error(py)) + } } - }); + ); ) ); @@ -293,15 +299,18 @@ impl ToPyObject for f64 { } } -/// Converts Python `float` to Rust `f64`. -extract!(obj to f64; py => { - let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) }; - if v == -1.0 && PyErr::occurred(py) { - Err(PyErr::fetch(py)) - } else { - Ok(v) +extract!( + obj to f64; + /// Converts Python `float` to Rust `f64`. + py => { + let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) }; + if v == -1.0 && PyErr::occurred(py) { + Err(PyErr::fetch(py)) + } else { + Ok(v) + } } -}); +); fn overflow_error(py: Python) -> PyErr { PyErr::new_lazy_init(py.get_type::(), None) @@ -316,13 +325,16 @@ impl ToPyObject for f32 { } } -/// Converts Python `float` to Rust `f32`. -/// -/// This conversion loses precision as the 64-bit float from Python gets -/// converted to a 32-bit float. Out-of-range numbers may also overflow to infinity. -extract!(obj to f32; py => { - Ok(obj.extract::(py)? as f32) -}); +extract!( + obj to f32; + /// Converts Python `float` to Rust `f32`. + /// + /// This conversion loses precision as the 64-bit float from Python gets + /// converted to a 32-bit float. Out-of-range numbers may also overflow to infinity. + py => { + Ok(obj.extract::(py)? as f32) + } +); #[cfg(test)] mod test { From 16043dbe3574c25e8d23a107ad864cd08055b174 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 19:30:38 -0800 Subject: [PATCH 02/10] allow deprecated use of get module filename and provide access to filename object --- src/objects/module.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/objects/module.rs b/src/objects/module.rs index 02624227..d4811d0b 100644 --- a/src/objects/module.rs +++ b/src/objects/module.rs @@ -79,10 +79,24 @@ impl PyModule { /// Gets the module filename. /// /// May fail if the module does not have a `__file__` attribute. + #[allow(deprecated)] pub fn filename<'a>(&'a self, py: Python) -> PyResult<&'a str> { unsafe { self.str_from_ptr(py, ffi::PyModule_GetFilename(self.0.as_ptr())) } } + /// Gets the module filename object. + /// + /// May fail if the module does not have a `__file__` attribute. + #[cfg(feature = "python3-sys")] + pub fn filename_object<'a>(&'a self, py: Python) -> PyResult { + let ptr = unsafe { ffi::PyModule_GetFilenameObject(self.0.as_ptr()) }; + if ptr.is_null() { + Err(PyErr::fetch(py)) + } else { + Ok(unsafe { PyObject::from_borrowed_ptr(py, ptr) }) + } + } + /// Gets a member from the module. /// This is equivalent to the Python expression: `getattr(module, name)` pub fn get(&self, py: Python, name: &str) -> PyResult { From a801f00943f7ed727c3d8705f8949f84396ffce8 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 21:14:23 -0800 Subject: [PATCH 03/10] increase required version of Rust to 1.32 This will allow us to use edition 2018. --- .travis.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03a4f271..a8f8b6a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,13 +7,13 @@ python: - "3.7" - "3.8" env: - - RUST_VERSION=1.30.0 + - RUST_VERSION=1.32.0 - RUST_VERSION=nightly matrix: include: - os: osx language: generic - env: RUST_VERSION=1.30.0 + env: RUST_VERSION=1.32.0 - os: osx language: generic env: RUST_VERSION=nightly diff --git a/README.md b/README.md index a4feb4b0..7bdd4aec 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Supported Python versions: * Python 2.7 * Python 3.3 to 3.8 -Requires Rust 1.30.0 or later. +Requires Rust 1.32.0 or later. # Usage From bf41900e7272d2623c9ddf2e85b4388f6e6917d7 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Wed, 29 Jan 2020 05:41:58 -0800 Subject: [PATCH 04/10] suppress deprecation warning for std::mem::uninitialized Since we are targetting 1.32, and std::mem::MaybeUninit wasn't stabilized until 1.36, suppress the deprecation warning. --- src/err.rs | 2 ++ src/objects/dict.rs | 2 ++ src/objects/string.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/err.rs b/src/err.rs index 833dbb15..e31c73e9 100644 --- a/src/err.rs +++ b/src/err.rs @@ -224,6 +224,8 @@ impl PyErr { /// The error is cleared from the Python interpreter. /// If no error is set, returns a `SystemError`. pub fn fetch(py: Python) -> PyErr { + // TODO: Switch to std::mem::MaybeUninit once available. + #[allow(deprecated)] unsafe { let mut ptype: *mut ffi::PyObject = std::mem::uninitialized(); let mut pvalue: *mut ffi::PyObject = std::mem::uninitialized(); diff --git a/src/objects/dict.rs b/src/objects/dict.rs index 41bac688..a3e20a51 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -118,6 +118,8 @@ impl PyDict { // PyDict_Next() is unsafe to use when the dictionary might be changed // by other python code. let mut vec = Vec::with_capacity(self.len(py)); + // TODO: Switch to std::mem::MaybeUninit once available. + #[allow(deprecated)] unsafe { let mut pos = 0; let mut key: *mut ffi::PyObject = mem::uninitialized(); diff --git a/src/objects/string.rs b/src/objects/string.rs index b4d8ef6d..06c54f53 100644 --- a/src/objects/string.rs +++ b/src/objects/string.rs @@ -282,6 +282,8 @@ impl PyString { fn data_impl(&self, py: Python) -> PyStringData { // TODO: return the original representation instead // of forcing the UTF-8 representation to be created. + // TODO: Switch to std::mem::MaybeUninit once available. + #[allow(deprecated)] unsafe { let mut size: ffi::Py_ssize_t = mem::uninitialized(); let data = ffi::PyUnicode_AsUTF8AndSize(self.as_ptr(), &mut size) as *const u8; From 9d9a32bb04331c1a856c6c46f01956a8b651051c Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 19:32:46 -0800 Subject: [PATCH 05/10] use std::sync::Once::new() --- src/pythonrun.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pythonrun.rs b/src/pythonrun.rs index dbdf2f09..d632d5dd 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -20,7 +20,7 @@ use ffi; use python::Python; use std::{marker, rc, sync}; -static START: sync::Once = sync::ONCE_INIT; +static START: sync::Once = sync::Once::new(); /// Prepares the use of Python in a free-threaded context. /// From 5d096c324af9930f382a22ca978fbdee39bd7200 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 20:19:58 -0800 Subject: [PATCH 06/10] python27-sys: edition 2018 --- python27-sys/Cargo.toml | 1 + python27-sys/src/boolobject.rs | 5 +- python27-sys/src/bufferobject.rs | 5 +- python27-sys/src/bytearrayobject.rs | 5 +- python27-sys/src/bytesobject.rs | 32 ++++----- python27-sys/src/cellobject.rs | 5 +- python27-sys/src/ceval.rs | 11 +-- python27-sys/src/classobject.rs | 5 +- python27-sys/src/cobject.rs | 3 +- python27-sys/src/code.rs | 7 +- python27-sys/src/compile.rs | 7 +- python27-sys/src/complexobject.rs | 5 +- python27-sys/src/descrobject.rs | 7 +- python27-sys/src/dictobject.rs | 5 +- python27-sys/src/enumobject.rs | 2 +- python27-sys/src/eval.rs | 5 +- python27-sys/src/fileobject.rs | 3 +- python27-sys/src/floatobject.rs | 5 +- python27-sys/src/frameobject.rs | 9 +-- python27-sys/src/funcobject.rs | 3 +- python27-sys/src/genobject.rs | 7 +- python27-sys/src/import.rs | 3 +- python27-sys/src/intobject.rs | 7 +- python27-sys/src/iterobject.rs | 3 +- python27-sys/src/lib.rs | 108 ++++++++++++++-------------- python27-sys/src/listobject.rs | 5 +- python27-sys/src/longobject.rs | 7 +- python27-sys/src/marshal.rs | 5 +- python27-sys/src/memoryobject.rs | 5 +- python27-sys/src/methodobject.rs | 4 +- python27-sys/src/modsupport.rs | 7 +- python27-sys/src/moduleobject.rs | 3 +- python27-sys/src/object.rs | 23 +++--- python27-sys/src/objectabstract.rs | 23 +++--- python27-sys/src/objimpl.rs | 5 +- python27-sys/src/pyarena.rs | 3 +- python27-sys/src/pycapsule.rs | 3 +- python27-sys/src/pyerrors.rs | 11 +-- python27-sys/src/pyport.rs | 6 +- python27-sys/src/pystate.rs | 5 +- python27-sys/src/pythonrun.rs | 9 +-- python27-sys/src/rangeobject.rs | 3 +- python27-sys/src/setobject.rs | 5 +- python27-sys/src/sliceobject.rs | 5 +- python27-sys/src/stringobject.rs | 5 +- python27-sys/src/structmember.rs | 5 +- python27-sys/src/sysmodule.rs | 3 +- python27-sys/src/traceback.rs | 7 +- python27-sys/src/tupleobject.rs | 5 +- python27-sys/src/unicodeobject.rs | 5 +- python27-sys/src/warnings.rs | 5 +- python27-sys/src/weakrefobject.rs | 5 +- 52 files changed, 240 insertions(+), 195 deletions(-) diff --git a/python27-sys/Cargo.toml b/python27-sys/Cargo.toml index 577fe696..7f53135c 100644 --- a/python27-sys/Cargo.toml +++ b/python27-sys/Cargo.toml @@ -20,6 +20,7 @@ exclude = [ "/.travis.yml", ] workspace = ".." +edition = "2018" [dependencies] libc = "0.2" diff --git a/python27-sys/src/boolobject.rs b/python27-sys/src/boolobject.rs index 47f1a1dd..fee39ea1 100644 --- a/python27-sys/src/boolobject.rs +++ b/python27-sys/src/boolobject.rs @@ -1,6 +1,7 @@ -use intobject::PyIntObject; use libc::{c_int, c_long}; -use object::*; + +use crate::intobject::PyIntObject; +use crate::object::*; pub type PyBoolObject = PyIntObject; diff --git a/python27-sys/src/bufferobject.rs b/python27-sys/src/bufferobject.rs index 15ce0dae..36ba28d6 100644 --- a/python27-sys/src/bufferobject.rs +++ b/python27-sys/src/bufferobject.rs @@ -1,6 +1,7 @@ use libc::{c_int, c_void}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/bytearrayobject.rs b/python27-sys/src/bytearrayobject.rs index a1069c9c..b8fcdcaf 100644 --- a/python27-sys/src/bytearrayobject.rs +++ b/python27-sys/src/bytearrayobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; /*#[repr(C)] #[deriving(Copy)] diff --git a/python27-sys/src/bytesobject.rs b/python27-sys/src/bytesobject.rs index 8d088633..5005996f 100644 --- a/python27-sys/src/bytesobject.rs +++ b/python27-sys/src/bytesobject.rs @@ -1,16 +1,16 @@ -pub use object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; -pub use stringobject::PyStringObject as PyBytesObject; -pub use stringobject::PyString_AS_STRING as PyBytes_AS_STRING; -pub use stringobject::PyString_AsString as PyBytes_AsString; -pub use stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; -pub use stringobject::PyString_Check as PyBytes_Check; -pub use stringobject::PyString_CheckExact as PyBytes_CheckExact; -pub use stringobject::PyString_Concat as PyBytes_Concat; -pub use stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; -pub use stringobject::PyString_Format as PyBytes_Format; -pub use stringobject::PyString_FromFormat as PyBytes_FromFormat; -pub use stringobject::PyString_FromString as PyBytes_FromString; -pub use stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; -pub use stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; -pub use stringobject::PyString_Size as PyBytes_Size; -pub use stringobject::PyString_Type as PyBytes_Type; +pub use crate::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; +pub use crate::stringobject::PyStringObject as PyBytesObject; +pub use crate::stringobject::PyString_AS_STRING as PyBytes_AS_STRING; +pub use crate::stringobject::PyString_AsString as PyBytes_AsString; +pub use crate::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; +pub use crate::stringobject::PyString_Check as PyBytes_Check; +pub use crate::stringobject::PyString_CheckExact as PyBytes_CheckExact; +pub use crate::stringobject::PyString_Concat as PyBytes_Concat; +pub use crate::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; +pub use crate::stringobject::PyString_Format as PyBytes_Format; +pub use crate::stringobject::PyString_FromFormat as PyBytes_FromFormat; +pub use crate::stringobject::PyString_FromString as PyBytes_FromString; +pub use crate::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; +pub use crate::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; +pub use crate::stringobject::PyString_Size as PyBytes_Size; +pub use crate::stringobject::PyString_Type as PyBytes_Type; diff --git a/python27-sys/src/cellobject.rs b/python27-sys/src/cellobject.rs index fb27eb71..5a02da53 100644 --- a/python27-sys/src/cellobject.rs +++ b/python27-sys/src/cellobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/ceval.rs b/python27-sys/src/ceval.rs index af4122f6..8d19a151 100644 --- a/python27-sys/src/ceval.rs +++ b/python27-sys/src/ceval.rs @@ -1,9 +1,10 @@ -use frameobject::PyFrameObject; use libc::{c_char, c_int, c_void}; -use object::PyObject; -use pyport::Py_ssize_t; -use pystate::{PyThreadState, Py_tracefunc}; -use pythonrun::PyCompilerFlags; + +use crate::frameobject::PyFrameObject; +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; +use crate::pystate::{PyThreadState, Py_tracefunc}; +use crate::pythonrun::PyCompilerFlags; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/classobject.rs b/python27-sys/src/classobject.rs index 51042e48..7a2d4243 100644 --- a/python27-sys/src/classobject.rs +++ b/python27-sys/src/classobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/cobject.rs b/python27-sys/src/cobject.rs index 07720738..891cba1b 100644 --- a/python27-sys/src/cobject.rs +++ b/python27-sys/src/cobject.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_void}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/code.rs b/python27-sys/src/code.rs index 0933992a..99ced168 100644 --- a/python27-sys/src/code.rs +++ b/python27-sys/src/code.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_void}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] @@ -95,5 +96,5 @@ pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { #[inline] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { - ::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) + crate::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } diff --git a/python27-sys/src/compile.rs b/python27-sys/src/compile.rs index a4c75157..777c587b 100644 --- a/python27-sys/src/compile.rs +++ b/python27-sys/src/compile.rs @@ -1,7 +1,8 @@ -use code::*; use libc::{c_char, c_int}; -use pyarena::PyArena; -use pythonrun::*; + +use crate::code::*; +use crate::pyarena::PyArena; +use crate::pythonrun::*; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/complexobject.rs b/python27-sys/src/complexobject.rs index 5afaa1fd..57e7fea9 100644 --- a/python27-sys/src/complexobject.rs +++ b/python27-sys/src/complexobject.rs @@ -1,6 +1,7 @@ use libc::{c_double, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/descrobject.rs b/python27-sys/src/descrobject.rs index 9708c2e4..f91d54d0 100644 --- a/python27-sys/src/descrobject.rs +++ b/python27-sys/src/descrobject.rs @@ -1,7 +1,8 @@ use libc::{c_char, c_int, c_void}; -use methodobject::PyMethodDef; -use object::{PyObject, PyTypeObject, Py_TYPE}; -use structmember::PyMemberDef; + +use crate::methodobject::PyMethodDef; +use crate::object::{PyObject, PyTypeObject, Py_TYPE}; +use crate::structmember::PyMemberDef; pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; diff --git a/python27-sys/src/dictobject.rs b/python27-sys/src/dictobject.rs index 4a0f8fd9..6ff80709 100644 --- a/python27-sys/src/dictobject.rs +++ b/python27-sys/src/dictobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; //pub enum PyDictObject { /* representation hidden */ } diff --git a/python27-sys/src/enumobject.rs b/python27-sys/src/enumobject.rs index fa7df51a..e3f187d1 100644 --- a/python27-sys/src/enumobject.rs +++ b/python27-sys/src/enumobject.rs @@ -1,4 +1,4 @@ -use object::PyTypeObject; +use crate::object::PyTypeObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/eval.rs b/python27-sys/src/eval.rs index e6800fa6..c33edd47 100644 --- a/python27-sys/src/eval.rs +++ b/python27-sys/src/eval.rs @@ -1,6 +1,7 @@ -use code::PyCodeObject; use libc::c_int; -use object::PyObject; + +use crate::code::PyCodeObject; +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/fileobject.rs b/python27-sys/src/fileobject.rs index b1cd434c..b0e0ece6 100644 --- a/python27-sys/src/fileobject.rs +++ b/python27-sys/src/fileobject.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, size_t, FILE}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/floatobject.rs b/python27-sys/src/floatobject.rs index 00fab651..4b06dad4 100644 --- a/python27-sys/src/floatobject.rs +++ b/python27-sys/src/floatobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_double, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/frameobject.rs b/python27-sys/src/frameobject.rs index 5cbeae93..3aeda348 100644 --- a/python27-sys/src/frameobject.rs +++ b/python27-sys/src/frameobject.rs @@ -1,8 +1,9 @@ -use code::{PyCodeObject, CO_MAXBLOCKS}; use libc::c_int; -use object::*; -use pyport::Py_ssize_t; -use pystate::PyThreadState; + +use crate::code::{PyCodeObject, CO_MAXBLOCKS}; +use crate::object::*; +use crate::pyport::Py_ssize_t; +use crate::pystate::PyThreadState; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/funcobject.rs b/python27-sys/src/funcobject.rs index 7eaecb73..86c63607 100644 --- a/python27-sys/src/funcobject.rs +++ b/python27-sys/src/funcobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/genobject.rs b/python27-sys/src/genobject.rs index ccfb3dff..3327e8b7 100644 --- a/python27-sys/src/genobject.rs +++ b/python27-sys/src/genobject.rs @@ -1,7 +1,8 @@ -use frameobject::PyFrameObject; use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::frameobject::PyFrameObject; +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/import.rs b/python27-sys/src/import.rs index f0923830..9b385337 100644 --- a/python27-sys/src/import.rs +++ b/python27-sys/src/import.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_long, c_uchar}; -use object::*; + +use crate::object::*; #[repr(C)] #[derive(Copy)] diff --git a/python27-sys/src/intobject.rs b/python27-sys/src/intobject.rs index 4a7acebf..75acdbb8 100644 --- a/python27-sys/src/intobject.rs +++ b/python27-sys/src/intobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_long, c_ulong, c_ulonglong, size_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] @@ -36,7 +37,7 @@ extern "C" { -> *mut PyObject; #[cfg(py_sys_config = "Py_USING_UNICODE")] pub fn PyInt_FromUnicode( - u: *mut ::unicodeobject::Py_UNICODE, + u: *mut crate::unicodeobject::Py_UNICODE, length: Py_ssize_t, base: c_int, ) -> *mut PyObject; diff --git a/python27-sys/src/iterobject.rs b/python27-sys/src/iterobject.rs index 977b1aae..32c55773 100644 --- a/python27-sys/src/iterobject.rs +++ b/python27-sys/src/iterobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/lib.rs b/python27-sys/src/lib.rs index 0bd1c351..d194f6ac 100644 --- a/python27-sys/src/lib.rs +++ b/python27-sys/src/lib.rs @@ -1,62 +1,60 @@ #![no_std] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] -extern crate libc; - -pub use boolobject::*; -pub use bufferobject::*; -pub use bytearrayobject::*; -pub use bytesobject::*; -pub use cellobject::*; -pub use ceval::*; -pub use classobject::*; -pub use cobject::*; -pub use code::*; -pub use compile::*; -pub use complexobject::*; -pub use descrobject::*; -pub use dictobject::*; -pub use enumobject::*; -pub use eval::*; -pub use fileobject::*; -pub use floatobject::*; -pub use frameobject::PyFrameObject; -pub use funcobject::*; -pub use genobject::*; -pub use import::*; -pub use intobject::*; -pub use iterobject::*; -pub use listobject::*; -pub use longobject::*; -pub use marshal::*; -pub use memoryobject::*; -pub use methodobject::*; -pub use modsupport::*; -pub use moduleobject::*; -pub use object::*; -pub use objectabstract::*; -pub use objimpl::*; -pub use pyarena::*; -pub use pycapsule::*; -pub use pydebug::*; -pub use pyerrors::*; -pub use pymem::*; -pub use pyport::*; -pub use pystate::PyGILState_STATE::*; -pub use pystate::*; -pub use pythonrun::*; -pub use rangeobject::*; -pub use setobject::*; -pub use sliceobject::*; -pub use stringobject::*; -pub use structmember::PyMemberDef; -pub use sysmodule::*; -pub use traceback::*; -pub use tupleobject::*; +pub use crate::boolobject::*; +pub use crate::bufferobject::*; +pub use crate::bytearrayobject::*; +pub use crate::bytesobject::*; +pub use crate::cellobject::*; +pub use crate::ceval::*; +pub use crate::classobject::*; +pub use crate::cobject::*; +pub use crate::code::*; +pub use crate::compile::*; +pub use crate::complexobject::*; +pub use crate::descrobject::*; +pub use crate::dictobject::*; +pub use crate::enumobject::*; +pub use crate::eval::*; +pub use crate::fileobject::*; +pub use crate::floatobject::*; +pub use crate::frameobject::PyFrameObject; +pub use crate::funcobject::*; +pub use crate::genobject::*; +pub use crate::import::*; +pub use crate::intobject::*; +pub use crate::iterobject::*; +pub use crate::listobject::*; +pub use crate::longobject::*; +pub use crate::marshal::*; +pub use crate::memoryobject::*; +pub use crate::methodobject::*; +pub use crate::modsupport::*; +pub use crate::moduleobject::*; +pub use crate::object::*; +pub use crate::objectabstract::*; +pub use crate::objimpl::*; +pub use crate::pyarena::*; +pub use crate::pycapsule::*; +pub use crate::pydebug::*; +pub use crate::pyerrors::*; +pub use crate::pymem::*; +pub use crate::pyport::*; +pub use crate::pystate::PyGILState_STATE::*; +pub use crate::pystate::*; +pub use crate::pythonrun::*; +pub use crate::rangeobject::*; +pub use crate::setobject::*; +pub use crate::sliceobject::*; +pub use crate::stringobject::*; +pub use crate::structmember::PyMemberDef; +pub use crate::sysmodule::*; +pub use crate::traceback::*; +pub use crate::tupleobject::*; #[cfg(py_sys_config = "Py_USING_UNICODE")] -pub use unicodeobject::*; -pub use warnings::*; -pub use weakrefobject::*; +pub use crate::unicodeobject::*; +pub use crate::warnings::*; +pub use crate::weakrefobject::*; mod pyport; diff --git a/python27-sys/src/listobject.rs b/python27-sys/src/listobject.rs index b1606f60..c486b835 100644 --- a/python27-sys/src/listobject.rs +++ b/python27-sys/src/listobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/longobject.rs b/python27-sys/src/longobject.rs index c92db801..99622b0d 100644 --- a/python27-sys/src/longobject.rs +++ b/python27-sys/src/longobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_void, size_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; //enum PyLongObject { /* representation hidden */ } @@ -36,7 +37,7 @@ extern "C" { ) -> *mut PyObject; #[cfg(py_sys_config = "Py_USING_UNICODE")] pub fn PyLong_FromUnicode( - u: *mut ::unicodeobject::Py_UNICODE, + u: *mut crate::unicodeobject::Py_UNICODE, length: Py_ssize_t, base: c_int, ) -> *mut PyObject; diff --git a/python27-sys/src/marshal.rs b/python27-sys/src/marshal.rs index c96b81a7..dc81892a 100644 --- a/python27-sys/src/marshal.rs +++ b/python27-sys/src/marshal.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_long, FILE}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; // 1 -> 2 in df88846ebca9186514e86bc2067242233ade4608 (Python 2.5) pub const Py_MARSHAL_VERSION: c_int = 2; diff --git a/python27-sys/src/memoryobject.rs b/python27-sys/src/memoryobject.rs index 455fd317..4b8fb11c 100644 --- a/python27-sys/src/memoryobject.rs +++ b/python27-sys/src/memoryobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/methodobject.rs b/python27-sys/src/methodobject.rs index 7143ed13..5fbe4f14 100644 --- a/python27-sys/src/methodobject.rs +++ b/python27-sys/src/methodobject.rs @@ -1,7 +1,7 @@ use core::ptr; use libc::{c_char, c_int}; -//use pyport::Py_ssize_t; -use object::{PyObject, PyTypeObject, Py_TYPE}; + +use crate::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/modsupport.rs b/python27-sys/src/modsupport.rs index 349ce8db..9c0a54c0 100644 --- a/python27-sys/src/modsupport.rs +++ b/python27-sys/src/modsupport.rs @@ -1,8 +1,9 @@ use core::ptr; use libc::{c_char, c_int, c_long}; -use methodobject::PyMethodDef; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::methodobject::PyMethodDef; +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/moduleobject.rs b/python27-sys/src/moduleobject.rs index 4f6e18a6..95a2b0b3 100644 --- a/python27-sys/src/moduleobject.rs +++ b/python27-sys/src/moduleobject.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/object.rs b/python27-sys/src/object.rs index d98917fb..9d137e3f 100644 --- a/python27-sys/src/object.rs +++ b/python27-sys/src/object.rs @@ -1,7 +1,8 @@ use core::ptr; use libc::{c_char, c_double, c_int, c_long, c_uint, c_void, FILE}; -use methodobject::PyMethodDef; -use pyport::Py_ssize_t; + +use crate::methodobject::PyMethodDef; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] @@ -402,8 +403,8 @@ pub struct PyTypeObject { pub tp_iter: Option, pub tp_iternext: Option, pub tp_methods: *mut PyMethodDef, - pub tp_members: *mut ::structmember::PyMemberDef, - pub tp_getset: *mut ::descrobject::PyGetSetDef, + pub tp_members: *mut crate::structmember::PyMemberDef, + pub tp_getset: *mut crate::descrobject::PyGetSetDef, pub tp_base: *mut PyTypeObject, pub tp_dict: *mut PyObject, pub tp_descr_get: Option, @@ -474,8 +475,8 @@ pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject { tp_iter: None, tp_iternext: None, tp_methods: 0 as *mut PyMethodDef, - tp_members: 0 as *mut ::structmember::PyMemberDef, - tp_getset: 0 as *mut ::descrobject::PyGetSetDef, + tp_members: 0 as *mut crate::structmember::PyMemberDef, + tp_getset: 0 as *mut crate::descrobject::PyGetSetDef, tp_base: 0 as *mut PyTypeObject, tp_dict: 0 as *mut PyObject, tp_descr_get: None, @@ -527,8 +528,8 @@ pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject { tp_iter: None, tp_iternext: None, tp_methods: 0 as *mut PyMethodDef, - tp_members: 0 as *mut ::structmember::PyMemberDef, - tp_getset: 0 as *mut ::descrobject::PyGetSetDef, + tp_members: 0 as *mut crate::structmember::PyMemberDef, + tp_getset: 0 as *mut crate::descrobject::PyGetSetDef, tp_base: 0 as *mut PyTypeObject, tp_dict: 0 as *mut PyObject, tp_descr_get: None, @@ -578,9 +579,9 @@ impl Clone for PyHeapTypeObject { #[inline] pub unsafe fn PyHeapType_GET_MEMBERS( etype: *mut PyHeapTypeObject, -) -> *mut ::structmember::PyMemberDef { +) -> *mut crate::structmember::PyMemberDef { let basicsize = (*Py_TYPE(etype as *mut PyObject)).tp_basicsize; - (etype as *mut u8).offset(basicsize as isize) as *mut ::structmember::PyMemberDef + (etype as *mut u8).offset(basicsize as isize) as *mut crate::structmember::PyMemberDef } #[cfg_attr(windows, link(name = "pythonXY"))] @@ -871,7 +872,7 @@ pub const PyTrash_UNWIND_LEVEL: c_int = 50; #[inline(always)] pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { - let tstate = ::pystate::PyThreadState_GET(); + let tstate = crate::pystate::PyThreadState_GET(); if tstate.is_null() || (*tstate).trash_delete_nesting < PyTrash_UNWIND_LEVEL { if !tstate.is_null() { (*tstate).trash_delete_nesting += 1; diff --git a/python27-sys/src/objectabstract.rs b/python27-sys/src/objectabstract.rs index 425c2071..e1cffc57 100644 --- a/python27-sys/src/objectabstract.rs +++ b/python27-sys/src/objectabstract.rs @@ -1,7 +1,8 @@ use core::ptr; use libc::{c_char, c_int, c_void}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[inline] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { @@ -232,28 +233,28 @@ pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { #[inline] pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { - if ::listobject::PyList_Check(o) != 0 { - ::listobject::PyList_GET_SIZE(o) + if crate::listobject::PyList_Check(o) != 0 { + crate::listobject::PyList_GET_SIZE(o) } else { - ::tupleobject::PyTuple_GET_SIZE(o) + crate::tupleobject::PyTuple_GET_SIZE(o) } } #[inline] pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { - if ::listobject::PyList_Check(o) != 0 { - ::listobject::PyList_GET_ITEM(o, i) + if crate::listobject::PyList_Check(o) != 0 { + crate::listobject::PyList_GET_ITEM(o, i) } else { - ::tupleobject::PyTuple_GET_ITEM(o, i) + crate::tupleobject::PyTuple_GET_ITEM(o, i) } } #[inline] pub unsafe fn PySequence_Fast_ITEMS(o: *mut PyObject) -> *mut *mut PyObject { - if ::listobject::PyList_Check(o) != 0 { - (*(o as *mut ::listobject::PyListObject)).ob_item + if crate::listobject::PyList_Check(o) != 0 { + (*(o as *mut crate::listobject::PyListObject)).ob_item } else { - (*(o as *mut ::tupleobject::PyTupleObject)) + (*(o as *mut crate::tupleobject::PyTupleObject)) .ob_item .as_mut_ptr() } diff --git a/python27-sys/src/objimpl.rs b/python27-sys/src/objimpl.rs index 5ab91a00..1f08b428 100644 --- a/python27-sys/src/objimpl.rs +++ b/python27-sys/src/objimpl.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_void, size_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/pyarena.rs b/python27-sys/src/pyarena.rs index 10bad476..6eef43e1 100644 --- a/python27-sys/src/pyarena.rs +++ b/python27-sys/src/pyarena.rs @@ -1,5 +1,6 @@ use libc::{c_int, c_void, size_t}; -use object::PyObject; + +use crate::object::PyObject; #[allow(missing_copy_implementations)] pub enum PyArena {} diff --git a/python27-sys/src/pycapsule.rs b/python27-sys/src/pycapsule.rs index f35def72..a7da04e6 100644 --- a/python27-sys/src/pycapsule.rs +++ b/python27-sys/src/pycapsule.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_void}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/pyerrors.rs b/python27-sys/src/pyerrors.rs index f6e3601f..ceb91e8c 100644 --- a/python27-sys/src/pyerrors.rs +++ b/python27-sys/src/pyerrors.rs @@ -1,10 +1,11 @@ -use classobject::*; use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; -use stringobject::PyString_AS_STRING; + +use crate::classobject::*; +use crate::object::*; +use crate::pyport::Py_ssize_t; +use crate::stringobject::PyString_AS_STRING; #[cfg(py_sys_config = "Py_USING_UNICODE")] -use unicodeobject::Py_UNICODE; +use crate::unicodeobject::Py_UNICODE; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/pyport.rs b/python27-sys/src/pyport.rs index d9d70d6e..51228cb8 100644 --- a/python27-sys/src/pyport.rs +++ b/python27-sys/src/pyport.rs @@ -1,6 +1,6 @@ -pub type Py_uintptr_t = ::libc::uintptr_t; -pub type Py_intptr_t = ::libc::intptr_t; -pub type Py_ssize_t = ::libc::ssize_t; +pub type Py_uintptr_t = libc::uintptr_t; +pub type Py_intptr_t = libc::intptr_t; +pub type Py_ssize_t = libc::ssize_t; pub const PY_SSIZE_T_MIN: Py_ssize_t = ::core::isize::MIN as Py_ssize_t; pub const PY_SSIZE_T_MAX: Py_ssize_t = ::core::isize::MAX as Py_ssize_t; diff --git a/python27-sys/src/pystate.rs b/python27-sys/src/pystate.rs index d5947cb2..c95f28b3 100644 --- a/python27-sys/src/pystate.rs +++ b/python27-sys/src/pystate.rs @@ -1,6 +1,7 @@ -use frameobject::PyFrameObject; use libc::{c_int, c_long}; -use object::PyObject; + +use crate::frameobject::PyFrameObject; +use crate::object::PyObject; pub enum PyInterpreterState {} diff --git a/python27-sys/src/pythonrun.rs b/python27-sys/src/pythonrun.rs index 8e8c7c60..44b0fe13 100644 --- a/python27-sys/src/pythonrun.rs +++ b/python27-sys/src/pythonrun.rs @@ -1,8 +1,9 @@ -use code::*; use libc::{c_char, c_int, FILE}; -use object::*; -use pyarena::PyArena; -use pystate::PyThreadState; + +use crate::code::*; +use crate::object::*; +use crate::pyarena::PyArena; +use crate::pystate::PyThreadState; pub const PyCF_MASK: c_int = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT diff --git a/python27-sys/src/rangeobject.rs b/python27-sys/src/rangeobject.rs index 589b97c0..190fc73a 100644 --- a/python27-sys/src/rangeobject.rs +++ b/python27-sys/src/rangeobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/setobject.rs b/python27-sys/src/setobject.rs index c373f67f..14f9122d 100644 --- a/python27-sys/src/setobject.rs +++ b/python27-sys/src/setobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; //enum PySetObject { /* representation hidden */ } diff --git a/python27-sys/src/sliceobject.rs b/python27-sys/src/sliceobject.rs index 7d450db7..a804ac5d 100644 --- a/python27-sys/src/sliceobject.rs +++ b/python27-sys/src/sliceobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/stringobject.rs b/python27-sys/src/stringobject.rs index f97166f0..13edd909 100644 --- a/python27-sys/src/stringobject.rs +++ b/python27-sys/src/stringobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_long}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[allow(missing_copy_implementations)] diff --git a/python27-sys/src/structmember.rs b/python27-sys/src/structmember.rs index 8ad26662..db282c18 100644 --- a/python27-sys/src/structmember.rs +++ b/python27-sys/src/structmember.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/sysmodule.rs b/python27-sys/src/sysmodule.rs index da3005e8..1c5c8a03 100644 --- a/python27-sys/src/sysmodule.rs +++ b/python27-sys/src/sysmodule.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int}; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/traceback.rs b/python27-sys/src/traceback.rs index 992bec5d..55d440b2 100644 --- a/python27-sys/src/traceback.rs +++ b/python27-sys/src/traceback.rs @@ -1,7 +1,8 @@ -use frameobject::PyFrameObject; use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::frameobject::PyFrameObject; +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/tupleobject.rs b/python27-sys/src/tupleobject.rs index e4816d3f..985e8b8c 100644 --- a/python27-sys/src/tupleobject.rs +++ b/python27-sys/src/tupleobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python27-sys/src/unicodeobject.rs b/python27-sys/src/unicodeobject.rs index e7fd5330..377c630e 100644 --- a/python27-sys/src/unicodeobject.rs +++ b/python27-sys/src/unicodeobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_double, c_int, c_long, wchar_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] pub const Py_UNICODE_SIZE: Py_ssize_t = 4; diff --git a/python27-sys/src/warnings.rs b/python27-sys/src/warnings.rs index 421d8c55..761e7aa4 100644 --- a/python27-sys/src/warnings.rs +++ b/python27-sys/src/warnings.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python27-sys/src/weakrefobject.rs b/python27-sys/src/weakrefobject.rs index 7a905b52..a3c0272c 100644 --- a/python27-sys/src/weakrefobject.rs +++ b/python27-sys/src/weakrefobject.rs @@ -1,6 +1,7 @@ use libc::{c_int, c_long}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] From 458f555c951e1ba48d686cc9d5aa55dfc2ed0031 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 20:31:07 -0800 Subject: [PATCH 07/10] python3-sys: edition 2018 --- python3-sys/Cargo.toml | 1 + python3-sys/src/bltinmodule.rs | 2 +- python3-sys/src/boolobject.rs | 5 +- python3-sys/src/bytearrayobject.rs | 5 +- python3-sys/src/bytesobject.rs | 5 +- python3-sys/src/ceval.rs | 13 +- python3-sys/src/code.rs | 9 +- python3-sys/src/codecs.rs | 3 +- python3-sys/src/compile.rs | 9 +- python3-sys/src/complexobject.rs | 3 +- python3-sys/src/descrobject.rs | 7 +- python3-sys/src/dictobject.rs | 5 +- python3-sys/src/enumobject.rs | 2 +- python3-sys/src/eval.rs | 3 +- python3-sys/src/fileobject.rs | 3 +- python3-sys/src/floatobject.rs | 3 +- python3-sys/src/frameobject.rs | 7 +- python3-sys/src/import.rs | 3 +- python3-sys/src/iterobject.rs | 3 +- python3-sys/src/lib.rs | 106 ++++++------ python3-sys/src/listobject.rs | 5 +- python3-sys/src/longobject.rs | 5 +- python3-sys/src/marshal.rs | 5 +- python3-sys/src/memoryobject.rs | 5 +- python3-sys/src/methodobject.rs | 9 +- python3-sys/src/modsupport.rs | 9 +- python3-sys/src/moduleobject.rs | 7 +- python3-sys/src/object.rs | 264 +++++++++++++++-------------- python3-sys/src/objectabstract.rs | 8 +- python3-sys/src/objimpl.rs | 5 +- python3-sys/src/osmodule.rs | 2 +- python3-sys/src/pycapsule.rs | 3 +- python3-sys/src/pyerrors.rs | 5 +- python3-sys/src/pyhash.rs | 3 +- python3-sys/src/pyport.rs | 12 +- python3-sys/src/pystate.rs | 5 +- python3-sys/src/pystrtod.rs | 3 +- python3-sys/src/pythonrun.rs | 7 +- python3-sys/src/rangeobject.rs | 3 +- python3-sys/src/setobject.rs | 5 +- python3-sys/src/sliceobject.rs | 5 +- python3-sys/src/structmember.rs | 5 +- python3-sys/src/structseq.rs | 5 +- python3-sys/src/sysmodule.rs | 3 +- python3-sys/src/traceback.rs | 5 +- python3-sys/src/tupleobject.rs | 5 +- python3-sys/src/unicodeobject.rs | 5 +- python3-sys/src/warnings.rs | 5 +- python3-sys/src/weakrefobject.rs | 3 +- 49 files changed, 328 insertions(+), 280 deletions(-) diff --git a/python3-sys/Cargo.toml b/python3-sys/Cargo.toml index f15c704d..50ad4730 100644 --- a/python3-sys/Cargo.toml +++ b/python3-sys/Cargo.toml @@ -20,6 +20,7 @@ exclude = [ "/.travis.yml", ] workspace = ".." +edition = "2018" [dependencies] libc = "0.2" diff --git a/python3-sys/src/bltinmodule.rs b/python3-sys/src/bltinmodule.rs index d329a15f..cd5be043 100644 --- a/python3-sys/src/bltinmodule.rs +++ b/python3-sys/src/bltinmodule.rs @@ -1,4 +1,4 @@ -use object::PyTypeObject; +use crate::object::PyTypeObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/boolobject.rs b/python3-sys/src/boolobject.rs index 0e4ce064..167da49a 100644 --- a/python3-sys/src/boolobject.rs +++ b/python3-sys/src/boolobject.rs @@ -1,6 +1,7 @@ use libc::{c_int, c_long}; -use longobject::PyLongObject; -use object::*; + +use crate::longobject::PyLongObject; +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/bytearrayobject.rs b/python3-sys/src/bytearrayobject.rs index fb51303c..54df7ee0 100644 --- a/python3-sys/src/bytearrayobject.rs +++ b/python3-sys/src/bytearrayobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/bytesobject.rs b/python3-sys/src/bytesobject.rs index 283a73b5..84d474e0 100644 --- a/python3-sys/src/bytesobject.rs +++ b/python3-sys/src/bytesobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/ceval.rs b/python3-sys/src/ceval.rs index 7fe66af1..2f32d6b8 100644 --- a/python3-sys/src/ceval.rs +++ b/python3-sys/src/ceval.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_void}; -use object::PyObject; -use pystate::PyThreadState; + +use crate::object::PyObject; +use crate::pystate::PyThreadState; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { @@ -13,7 +14,7 @@ extern "C" { #[inline] pub unsafe fn PyEval_CallObject(callable: *mut PyObject, arg: *mut PyObject) -> *mut PyObject { - PyEval_CallObjectWithKeywords(callable, arg, ::core::ptr::null_mut()) + PyEval_CallObjectWithKeywords(callable, arg, core::ptr::null_mut()) } #[cfg_attr(windows, link(name = "pythonXY"))] @@ -32,7 +33,7 @@ extern "C" { pub fn PyEval_GetBuiltins() -> *mut PyObject; pub fn PyEval_GetGlobals() -> *mut PyObject; pub fn PyEval_GetLocals() -> *mut PyObject; - pub fn PyEval_GetFrame() -> *mut ::PyFrameObject; + pub fn PyEval_GetFrame() -> *mut crate::PyFrameObject; pub fn Py_AddPendingCall( func: Option c_int>, arg: *mut c_void, @@ -53,8 +54,8 @@ extern "C" { pub fn PyEval_GetFuncDesc(arg1: *mut PyObject) -> *const c_char; #[cfg(not(Py_3_7))] pub fn PyEval_GetCallStats(arg1: *mut PyObject) -> *mut PyObject; - pub fn PyEval_EvalFrame(arg1: *mut ::PyFrameObject) -> *mut PyObject; - pub fn PyEval_EvalFrameEx(f: *mut ::PyFrameObject, exc: c_int) -> *mut PyObject; + pub fn PyEval_EvalFrame(arg1: *mut crate::PyFrameObject) -> *mut PyObject; + pub fn PyEval_EvalFrameEx(f: *mut crate::PyFrameObject, exc: c_int) -> *mut PyObject; pub fn PyEval_SaveThread() -> *mut PyThreadState; pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> (); } diff --git a/python3-sys/src/code.rs b/python3-sys/src/code.rs index f726bec5..d9708d2c 100644 --- a/python3-sys/src/code.rs +++ b/python3-sys/src/code.rs @@ -1,7 +1,8 @@ #[allow(unused_imports)] use libc::{c_char, c_int, c_uchar, c_void}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg(Py_3_8)] pub enum _PyOpcache {} @@ -56,7 +57,7 @@ impl Clone for PyCodeObject { impl Default for PyCodeObject { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } @@ -163,5 +164,5 @@ pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { #[inline] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { - ::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) + crate::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } diff --git a/python3-sys/src/codecs.rs b/python3-sys/src/codecs.rs index d4dac6aa..cac6a536 100644 --- a/python3-sys/src/codecs.rs +++ b/python3-sys/src/codecs.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int}; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/compile.rs b/python3-sys/src/compile.rs index 3ea6f56e..a91fae4c 100644 --- a/python3-sys/src/compile.rs +++ b/python3-sys/src/compile.rs @@ -1,8 +1,9 @@ -use code::*; use libc::{c_char, c_int}; -use object::PyObject; -use pyarena::*; -use pythonrun::*; + +use crate::code::*; +use crate::object::PyObject; +use crate::pyarena::*; +use crate::pythonrun::*; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python3-sys/src/complexobject.rs b/python3-sys/src/complexobject.rs index 30945377..f9a2c89a 100644 --- a/python3-sys/src/complexobject.rs +++ b/python3-sys/src/complexobject.rs @@ -1,5 +1,6 @@ use libc::{c_double, c_int}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/descrobject.rs b/python3-sys/src/descrobject.rs index 77e48213..5fc9f1b3 100644 --- a/python3-sys/src/descrobject.rs +++ b/python3-sys/src/descrobject.rs @@ -1,7 +1,8 @@ use libc::{c_char, c_int, c_void}; -use methodobject::PyMethodDef; -use object::{PyObject, PyTypeObject}; -use structmember::PyMemberDef; + +use crate::methodobject::PyMethodDef; +use crate::object::{PyObject, PyTypeObject}; +use crate::structmember::PyMemberDef; pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; diff --git a/python3-sys/src/dictobject.rs b/python3-sys/src/dictobject.rs index 7b7e237c..eef37119 100644 --- a/python3-sys/src/dictobject.rs +++ b/python3-sys/src/dictobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/enumobject.rs b/python3-sys/src/enumobject.rs index fa7df51a..e3f187d1 100644 --- a/python3-sys/src/enumobject.rs +++ b/python3-sys/src/enumobject.rs @@ -1,4 +1,4 @@ -use object::PyTypeObject; +use crate::object::PyTypeObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/eval.rs b/python3-sys/src/eval.rs index 6104f24b..45f7a341 100644 --- a/python3-sys/src/eval.rs +++ b/python3-sys/src/eval.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/fileobject.rs b/python3-sys/src/fileobject.rs index 9ab14ece..2ed57ca6 100644 --- a/python3-sys/src/fileobject.rs +++ b/python3-sys/src/fileobject.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int}; -use object::PyObject; + +use crate::object::PyObject; pub const PY_STDIOTEXTMODE: &'static str = "b"; diff --git a/python3-sys/src/floatobject.rs b/python3-sys/src/floatobject.rs index ca7d7a43..b63e0bca 100644 --- a/python3-sys/src/floatobject.rs +++ b/python3-sys/src/floatobject.rs @@ -1,5 +1,6 @@ use libc::{c_double, c_int}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/frameobject.rs b/python3-sys/src/frameobject.rs index caf27ea7..39abfaf3 100644 --- a/python3-sys/src/frameobject.rs +++ b/python3-sys/src/frameobject.rs @@ -1,7 +1,8 @@ -use code::{PyCodeObject, CO_MAXBLOCKS}; use libc::{c_char, c_int}; -use object::*; -use pystate::PyThreadState; + +use crate::code::{PyCodeObject, CO_MAXBLOCKS}; +use crate::object::*; +use crate::pystate::PyThreadState; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python3-sys/src/import.rs b/python3-sys/src/import.rs index 41bef77f..cdbf61b8 100644 --- a/python3-sys/src/import.rs +++ b/python3-sys/src/import.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_long, c_uchar}; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/iterobject.rs b/python3-sys/src/iterobject.rs index 977b1aae..32c55773 100644 --- a/python3-sys/src/iterobject.rs +++ b/python3-sys/src/iterobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/lib.rs b/python3-sys/src/lib.rs index 63ccba34..68e39e9b 100644 --- a/python3-sys/src/lib.rs +++ b/python3-sys/src/lib.rs @@ -9,63 +9,61 @@ // new: // Based on the headers of Python 3.3.0, 3.4.0 and 3.5.0. -extern crate libc; - -pub use bltinmodule::*; -pub use boolobject::*; -pub use bytearrayobject::*; -pub use bytesobject::*; -pub use ceval::*; -pub use code::*; -pub use codecs::*; -pub use compile::*; -pub use complexobject::*; -pub use descrobject::*; -pub use dictobject::*; -pub use enumobject::*; -pub use eval::*; -pub use fileobject::*; +pub use crate::bltinmodule::*; +pub use crate::boolobject::*; +pub use crate::bytearrayobject::*; +pub use crate::bytesobject::*; +pub use crate::ceval::*; +pub use crate::code::*; +pub use crate::codecs::*; +pub use crate::compile::*; +pub use crate::complexobject::*; +pub use crate::descrobject::*; +pub use crate::dictobject::*; +pub use crate::enumobject::*; +pub use crate::eval::*; +pub use crate::fileobject::*; #[cfg(Py_3_5)] -pub use fileutils::*; -pub use floatobject::*; -pub use frameobject::PyFrameObject; -pub use import::*; -pub use intrcheck::*; -pub use iterobject::*; -pub use listobject::*; -pub use longobject::*; -pub use marshal::*; -pub use memoryobject::*; -pub use methodobject::*; -pub use modsupport::*; -pub use moduleobject::*; -pub use object::*; -pub use objectabstract::*; -pub use objimpl::*; +pub use crate::fileutils::*; +pub use crate::floatobject::*; +pub use crate::frameobject::PyFrameObject; +pub use crate::import::*; +pub use crate::intrcheck::*; +pub use crate::iterobject::*; +pub use crate::listobject::*; +pub use crate::longobject::*; +pub use crate::marshal::*; +pub use crate::memoryobject::*; +pub use crate::methodobject::*; +pub use crate::modsupport::*; +pub use crate::moduleobject::*; +pub use crate::object::*; +pub use crate::objectabstract::*; +pub use crate::objimpl::*; #[cfg(Py_3_6)] -pub use osmodule::*; -pub use pyarena::*; -pub use pycapsule::*; -pub use pydebug::*; -pub use pyerrors::*; +pub use crate::osmodule::*; +pub use crate::pyarena::*; +pub use crate::pycapsule::*; +pub use crate::pydebug::*; +pub use crate::pyerrors::*; #[cfg(Py_3_4)] -pub use pyhash::*; -pub use pymem::*; -pub use pyport::*; -pub use pystate::*; -pub use pystrtod::*; -pub use pythonrun::*; -pub use rangeobject::*; -pub use setobject::*; -pub use sliceobject::*; -pub use structseq::*; -pub use sysmodule::*; -pub use traceback::*; -pub use tupleobject::*; -pub use typeslots::*; -pub use unicodeobject::*; -pub use warnings::*; -pub use weakrefobject::*; +pub use crate::pyhash::*; +pub use crate::pymem::*; +pub use crate::pyport::*; +pub use crate::pystate::*; +pub use crate::pystrtod::*; +pub use crate::pythonrun::*; +pub use crate::rangeobject::*; +pub use crate::setobject::*; +pub use crate::sliceobject::*; +pub use crate::structseq::*; +pub use crate::sysmodule::*; +pub use crate::traceback::*; +pub use crate::tupleobject::*; +pub use crate::typeslots::*; +pub use crate::unicodeobject::*; +pub use crate::warnings::*; +pub use crate::weakrefobject::*; mod pyport; diff --git a/python3-sys/src/listobject.rs b/python3-sys/src/listobject.rs index b38c9fa3..d591a271 100644 --- a/python3-sys/src/listobject.rs +++ b/python3-sys/src/listobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/longobject.rs b/python3-sys/src/longobject.rs index 32151e6c..d419eae8 100644 --- a/python3-sys/src/longobject.rs +++ b/python3-sys/src/longobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_void, size_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; pub enum PyLongObject {} diff --git a/python3-sys/src/marshal.rs b/python3-sys/src/marshal.rs index 29e0dda7..089f107d 100644 --- a/python3-sys/src/marshal.rs +++ b/python3-sys/src/marshal.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_long, FILE}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; // 1 -> 2 in df88846ebca9186514e86bc2067242233ade4608 (Python 2.5) // 2 -> 3 in d7009c69136a3809282804f460902ab42e9972f6 (Python 3.4) diff --git a/python3-sys/src/memoryobject.rs b/python3-sys/src/memoryobject.rs index bdd3160f..27d60d05 100644 --- a/python3-sys/src/memoryobject.rs +++ b/python3-sys/src/memoryobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/methodobject.rs b/python3-sys/src/methodobject.rs index 5261dff7..f46ae9f2 100644 --- a/python3-sys/src/methodobject.rs +++ b/python3-sys/src/methodobject.rs @@ -1,6 +1,7 @@ use core::{mem, ptr}; use libc::{c_char, c_int}; -use object::{PyObject, PyTypeObject, Py_TYPE}; + +use crate::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { @@ -19,7 +20,7 @@ pub type PyCFunction = pub type _PyCFunctionFast = unsafe extern "C" fn( slf: *mut PyObject, args: *mut *mut PyObject, - nargs: ::pyport::Py_ssize_t, + nargs: crate::pyport::Py_ssize_t, kwnames: *mut PyObject, ) -> *mut PyObject; @@ -27,7 +28,7 @@ pub type _PyCFunctionFast = unsafe extern "C" fn( pub type _PyCFunctionFast = unsafe extern "C" fn( slf: *mut PyObject, args: *const *mut PyObject, - nargs: ::pyport::Py_ssize_t, + nargs: crate::pyport::Py_ssize_t, ) -> *mut PyObject; pub type PyCFunctionWithKeywords = unsafe extern "C" fn( @@ -40,7 +41,7 @@ pub type PyCFunctionWithKeywords = unsafe extern "C" fn( pub type _PyCFunctionFastWithKeywords = unsafe extern "C" fn( slf: *mut PyObject, args: *const *mut PyObject, - nargs: ::pyport::Py_ssize_t, + nargs: crate::pyport::Py_ssize_t, kwnames: *mut PyObject, ) -> *mut PyObject; diff --git a/python3-sys/src/modsupport.rs b/python3-sys/src/modsupport.rs index 906500e1..602279b8 100644 --- a/python3-sys/src/modsupport.rs +++ b/python3-sys/src/modsupport.rs @@ -1,9 +1,10 @@ use libc::{c_char, c_int, c_long}; + #[cfg(Py_3_5)] -use methodobject::PyMethodDef; -use moduleobject::PyModuleDef; -use object::PyObject; -use pyport::Py_ssize_t; +use crate::methodobject::PyMethodDef; +use crate::moduleobject::PyModuleDef; +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/moduleobject.rs b/python3-sys/src/moduleobject.rs index 6353c554..af112782 100644 --- a/python3-sys/src/moduleobject.rs +++ b/python3-sys/src/moduleobject.rs @@ -1,7 +1,8 @@ use libc::{c_char, c_int, c_void}; -use methodobject::PyMethodDef; -use object::*; -use pyport::Py_ssize_t; + +use crate::methodobject::PyMethodDef; +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/object.rs b/python3-sys/src/object.rs index 11b11951..09df770b 100644 --- a/python3-sys/src/object.rs +++ b/python3-sys/src/object.rs @@ -1,6 +1,7 @@ use core::ptr; use libc::{c_char, c_int, c_uint, c_ulong, c_void}; -use pyport::{Py_hash_t, Py_ssize_t}; + +use crate::pyport::{Py_hash_t, Py_ssize_t}; #[repr(C)] #[derive(Copy, Clone)] @@ -77,13 +78,14 @@ pub type objobjargproc = #[cfg(not(Py_LIMITED_API))] mod bufferinfo { use libc::{c_char, c_int, c_void}; - use pyport::Py_ssize_t; + + use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy)] pub struct Py_buffer { pub buf: *mut c_void, - pub obj: *mut ::object::PyObject, + pub obj: *mut crate::object::PyObject, pub len: Py_ssize_t, pub itemsize: Py_ssize_t, pub readonly: c_int, @@ -103,14 +105,17 @@ mod bufferinfo { impl Default for Py_buffer { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } - pub type getbufferproc = - extern "C" fn(arg1: *mut ::object::PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int; + pub type getbufferproc = extern "C" fn( + arg1: *mut crate::object::PyObject, + arg2: *mut Py_buffer, + arg3: c_int, + ) -> c_int; pub type releasebufferproc = - extern "C" fn(arg1: *mut ::object::PyObject, arg2: *mut Py_buffer) -> (); + extern "C" fn(arg1: *mut crate::object::PyObject, arg2: *mut Py_buffer) -> (); /// Maximum number of dimensions pub const PyBUF_MAX_NDIM: c_int = 64; @@ -155,7 +160,7 @@ pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void); pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject); #[cfg(not(Py_LIMITED_API))] pub type printfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut ::libc::FILE, arg3: c_int) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut libc::FILE, arg3: c_int) -> c_int; pub type getattrfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char) -> *mut PyObject; pub type getattrofunc = @@ -189,11 +194,11 @@ pub type allocfunc = #[cfg(Py_3_8)] pub type vectorcallfunc = unsafe extern "C" fn( - callable: *mut ::object::PyObject, - args: *const *mut ::object::PyObject, - nargsf: ::libc::size_t, - kwnames: *mut ::object::PyObject, -) -> *mut ::object::PyObject; + callable: *mut crate::object::PyObject, + args: *const *mut crate::object::PyObject, + nargsf: libc::size_t, + kwnames: *mut crate::object::PyObject, +) -> *mut crate::object::PyObject; #[cfg(Py_LIMITED_API)] pub enum PyTypeObject {} @@ -201,49 +206,50 @@ pub enum PyTypeObject {} #[cfg(not(Py_LIMITED_API))] mod typeobject { use libc::{c_char, c_uint, c_ulong, c_void}; - use pyport::Py_ssize_t; + + use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy)] pub struct PyNumberMethods { - pub nb_add: Option<::object::binaryfunc>, - pub nb_subtract: Option<::object::binaryfunc>, - pub nb_multiply: Option<::object::binaryfunc>, - pub nb_remainder: Option<::object::binaryfunc>, - pub nb_divmod: Option<::object::binaryfunc>, - pub nb_power: Option<::object::ternaryfunc>, - pub nb_negative: Option<::object::unaryfunc>, - pub nb_positive: Option<::object::unaryfunc>, - pub nb_absolute: Option<::object::unaryfunc>, - pub nb_bool: Option<::object::inquiry>, - pub nb_invert: Option<::object::unaryfunc>, - pub nb_lshift: Option<::object::binaryfunc>, - pub nb_rshift: Option<::object::binaryfunc>, - pub nb_and: Option<::object::binaryfunc>, - pub nb_xor: Option<::object::binaryfunc>, - pub nb_or: Option<::object::binaryfunc>, - pub nb_int: Option<::object::unaryfunc>, + pub nb_add: Option, + pub nb_subtract: Option, + pub nb_multiply: Option, + pub nb_remainder: Option, + pub nb_divmod: Option, + pub nb_power: Option, + pub nb_negative: Option, + pub nb_positive: Option, + pub nb_absolute: Option, + pub nb_bool: Option, + pub nb_invert: Option, + pub nb_lshift: Option, + pub nb_rshift: Option, + pub nb_and: Option, + pub nb_xor: Option, + pub nb_or: Option, + pub nb_int: Option, pub nb_reserved: *mut c_void, - pub nb_float: Option<::object::unaryfunc>, - pub nb_inplace_add: Option<::object::binaryfunc>, - pub nb_inplace_subtract: Option<::object::binaryfunc>, - pub nb_inplace_multiply: Option<::object::binaryfunc>, - pub nb_inplace_remainder: Option<::object::binaryfunc>, - pub nb_inplace_power: Option<::object::ternaryfunc>, - pub nb_inplace_lshift: Option<::object::binaryfunc>, - pub nb_inplace_rshift: Option<::object::binaryfunc>, - pub nb_inplace_and: Option<::object::binaryfunc>, - pub nb_inplace_xor: Option<::object::binaryfunc>, - pub nb_inplace_or: Option<::object::binaryfunc>, - pub nb_floor_divide: Option<::object::binaryfunc>, - pub nb_true_divide: Option<::object::binaryfunc>, - pub nb_inplace_floor_divide: Option<::object::binaryfunc>, - pub nb_inplace_true_divide: Option<::object::binaryfunc>, - pub nb_index: Option<::object::unaryfunc>, + pub nb_float: Option, + pub nb_inplace_add: Option, + pub nb_inplace_subtract: Option, + pub nb_inplace_multiply: Option, + pub nb_inplace_remainder: Option, + pub nb_inplace_power: Option, + pub nb_inplace_lshift: Option, + pub nb_inplace_rshift: Option, + pub nb_inplace_and: Option, + pub nb_inplace_xor: Option, + pub nb_inplace_or: Option, + pub nb_floor_divide: Option, + pub nb_true_divide: Option, + pub nb_inplace_floor_divide: Option, + pub nb_inplace_true_divide: Option, + pub nb_index: Option, #[cfg(Py_3_5)] - pub nb_matrix_multiply: Option<::object::binaryfunc>, + pub nb_matrix_multiply: Option, #[cfg(Py_3_5)] - pub nb_inplace_matrix_multiply: Option<::object::binaryfunc>, + pub nb_inplace_matrix_multiply: Option, } impl Clone for PyNumberMethods { #[inline] @@ -254,7 +260,7 @@ mod typeobject { impl Default for PyNumberMethods { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } macro_rules! as_expr { @@ -319,16 +325,16 @@ mod typeobject { #[repr(C)] #[derive(Copy)] pub struct PySequenceMethods { - pub sq_length: Option<::object::lenfunc>, - pub sq_concat: Option<::object::binaryfunc>, - pub sq_repeat: Option<::object::ssizeargfunc>, - pub sq_item: Option<::object::ssizeargfunc>, + pub sq_length: Option, + pub sq_concat: Option, + pub sq_repeat: Option, + pub sq_item: Option, pub was_sq_slice: *mut c_void, - pub sq_ass_item: Option<::object::ssizeobjargproc>, + pub sq_ass_item: Option, pub was_sq_ass_slice: *mut c_void, - pub sq_contains: Option<::object::objobjproc>, - pub sq_inplace_concat: Option<::object::binaryfunc>, - pub sq_inplace_repeat: Option<::object::ssizeargfunc>, + pub sq_contains: Option, + pub sq_inplace_concat: Option, + pub sq_inplace_repeat: Option, } impl Clone for PySequenceMethods { #[inline] @@ -339,7 +345,7 @@ mod typeobject { impl Default for PySequenceMethods { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { @@ -357,9 +363,9 @@ mod typeobject { #[repr(C)] #[derive(Copy)] pub struct PyMappingMethods { - pub mp_length: Option<::object::lenfunc>, - pub mp_subscript: Option<::object::binaryfunc>, - pub mp_ass_subscript: Option<::object::objobjargproc>, + pub mp_length: Option, + pub mp_subscript: Option, + pub mp_ass_subscript: Option, } impl Clone for PyMappingMethods { #[inline] @@ -370,7 +376,7 @@ mod typeobject { impl Default for PyMappingMethods { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { @@ -382,9 +388,9 @@ mod typeobject { #[derive(Copy)] #[cfg(Py_3_5)] pub struct PyAsyncMethods { - pub am_await: Option<::object::unaryfunc>, - pub am_aiter: Option<::object::unaryfunc>, - pub am_anext: Option<::object::unaryfunc>, + pub am_await: Option, + pub am_aiter: Option, + pub am_anext: Option, } #[cfg(Py_3_5)] impl Clone for PyAsyncMethods { @@ -397,7 +403,7 @@ mod typeobject { impl Default for PyAsyncMethods { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } #[cfg(Py_3_5)] @@ -409,8 +415,8 @@ mod typeobject { #[repr(C)] #[derive(Copy)] pub struct PyBufferProcs { - pub bf_getbuffer: Option<::object::getbufferproc>, - pub bf_releasebuffer: Option<::object::releasebufferproc>, + pub bf_getbuffer: Option, + pub bf_releasebuffer: Option, } impl Clone for PyBufferProcs { #[inline] @@ -421,72 +427,72 @@ mod typeobject { impl Default for PyBufferProcs { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } #[repr(C)] #[derive(Copy)] pub struct PyTypeObject { - pub ob_base: ::object::PyVarObject, + pub ob_base: crate::object::PyVarObject, pub tp_name: *const c_char, pub tp_basicsize: Py_ssize_t, pub tp_itemsize: Py_ssize_t, - pub tp_dealloc: Option<::object::destructor>, + pub tp_dealloc: Option, #[cfg(not(Py_3_8))] - pub tp_print: Option<::object::printfunc>, + pub tp_print: Option, #[cfg(Py_3_8)] pub tp_vectorcall_offset: Py_ssize_t, - pub tp_getattr: Option<::object::getattrfunc>, - pub tp_setattr: Option<::object::setattrfunc>, + pub tp_getattr: Option, + pub tp_setattr: Option, #[cfg(Py_3_5)] pub tp_as_async: *mut PyAsyncMethods, #[cfg(not(Py_3_5))] pub tp_reserved: *mut c_void, - pub tp_repr: Option<::object::reprfunc>, + pub tp_repr: Option, pub tp_as_number: *mut PyNumberMethods, pub tp_as_sequence: *mut PySequenceMethods, pub tp_as_mapping: *mut PyMappingMethods, - pub tp_hash: Option<::object::hashfunc>, - pub tp_call: Option<::object::ternaryfunc>, - pub tp_str: Option<::object::reprfunc>, - pub tp_getattro: Option<::object::getattrofunc>, - pub tp_setattro: Option<::object::setattrofunc>, + pub tp_hash: Option, + pub tp_call: Option, + pub tp_str: Option, + pub tp_getattro: Option, + pub tp_setattro: Option, pub tp_as_buffer: *mut PyBufferProcs, pub tp_flags: c_ulong, pub tp_doc: *const c_char, - pub tp_traverse: Option<::object::traverseproc>, - pub tp_clear: Option<::object::inquiry>, - pub tp_richcompare: Option<::object::richcmpfunc>, + pub tp_traverse: Option, + pub tp_clear: Option, + pub tp_richcompare: Option, pub tp_weaklistoffset: Py_ssize_t, - pub tp_iter: Option<::object::getiterfunc>, - pub tp_iternext: Option<::object::iternextfunc>, - pub tp_methods: *mut ::methodobject::PyMethodDef, - pub tp_members: *mut ::structmember::PyMemberDef, - pub tp_getset: *mut ::descrobject::PyGetSetDef, + pub tp_iter: Option, + pub tp_iternext: Option, + pub tp_methods: *mut crate::methodobject::PyMethodDef, + pub tp_members: *mut crate::structmember::PyMemberDef, + pub tp_getset: *mut crate::descrobject::PyGetSetDef, pub tp_base: *mut PyTypeObject, - pub tp_dict: *mut ::object::PyObject, - pub tp_descr_get: Option<::object::descrgetfunc>, - pub tp_descr_set: Option<::object::descrsetfunc>, + pub tp_dict: *mut crate::object::PyObject, + pub tp_descr_get: Option, + pub tp_descr_set: Option, pub tp_dictoffset: Py_ssize_t, - pub tp_init: Option<::object::initproc>, - pub tp_alloc: Option<::object::allocfunc>, - pub tp_new: Option<::object::newfunc>, - pub tp_free: Option<::object::freefunc>, - pub tp_is_gc: Option<::object::inquiry>, - pub tp_bases: *mut ::object::PyObject, - pub tp_mro: *mut ::object::PyObject, - pub tp_cache: *mut ::object::PyObject, - pub tp_subclasses: *mut ::object::PyObject, - pub tp_weaklist: *mut ::object::PyObject, - pub tp_del: Option<::object::destructor>, + pub tp_init: Option, + pub tp_alloc: Option, + pub tp_new: Option, + pub tp_free: Option, + pub tp_is_gc: Option, + pub tp_bases: *mut crate::object::PyObject, + pub tp_mro: *mut crate::object::PyObject, + pub tp_cache: *mut crate::object::PyObject, + pub tp_subclasses: *mut crate::object::PyObject, + pub tp_weaklist: *mut crate::object::PyObject, + pub tp_del: Option, pub tp_version_tag: c_uint, #[cfg(Py_3_4)] - pub tp_finalize: Option<::object::destructor>, + pub tp_finalize: Option, #[cfg(Py_3_8)] - pub tp_vectorcall: Option<::object::vectorcallfunc>, + pub tp_vectorcall: Option, #[cfg(Py_3_8)] - pub tp_print: Option<::object::printfunc>, + pub tp_print: Option, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_allocs: Py_ssize_t, #[cfg(py_sys_config = "COUNT_ALLOCS")] @@ -509,8 +515,8 @@ mod typeobject { ($($tail:tt)*) => { as_expr! { PyTypeObject { - ob_base: ::object::PyVarObject { - ob_base: ::object::PyObject_HEAD_INIT, + ob_base: crate::object::PyVarObject { + ob_base: crate::object::PyObject_HEAD_INIT, ob_size: 0 }, tp_name: 0 as *const c_char, @@ -530,7 +536,7 @@ mod typeobject { tp_getattro: None, tp_setattro: None, tp_as_buffer: 0 as *mut PyBufferProcs, - tp_flags: ::object::Py_TPFLAGS_DEFAULT, + tp_flags: crate::object::Py_TPFLAGS_DEFAULT, tp_doc: 0 as *const c_char, tp_traverse: None, tp_clear: None, @@ -538,11 +544,11 @@ mod typeobject { tp_weaklistoffset: 0, tp_iter: None, tp_iternext: None, - tp_methods: 0 as *mut ::methodobject::PyMethodDef, - tp_members: 0 as *mut ::structmember::PyMemberDef, - tp_getset: 0 as *mut ::descrobject::PyGetSetDef, + tp_methods: 0 as *mut crate::methodobject::PyMethodDef, + tp_members: 0 as *mut crate::structmember::PyMemberDef, + tp_getset: 0 as *mut crate::descrobject::PyGetSetDef, tp_base: 0 as *mut PyTypeObject, - tp_dict: 0 as *mut ::object::PyObject, + tp_dict: 0 as *mut crate::object::PyObject, tp_descr_get: None, tp_descr_set: None, tp_dictoffset: 0, @@ -551,11 +557,11 @@ mod typeobject { tp_new: None, tp_free: None, tp_is_gc: None, - tp_bases: 0 as *mut ::object::PyObject, - tp_mro: 0 as *mut ::object::PyObject, - tp_cache: 0 as *mut ::object::PyObject, - tp_subclasses: 0 as *mut ::object::PyObject, - tp_weaklist: 0 as *mut ::object::PyObject, + tp_bases: 0 as *mut crate::object::PyObject, + tp_mro: 0 as *mut crate::object::PyObject, + tp_cache: 0 as *mut crate::object::PyObject, + tp_subclasses: 0 as *mut crate::object::PyObject, + tp_weaklist: 0 as *mut crate::object::PyObject, tp_del: None, tp_version_tag: 0, $($tail)* @@ -627,9 +633,9 @@ mod typeobject { pub as_mapping: PyMappingMethods, pub as_sequence: PySequenceMethods, pub as_buffer: PyBufferProcs, - pub ht_name: *mut ::object::PyObject, - pub ht_slots: *mut ::object::PyObject, - pub ht_qualname: *mut ::object::PyObject, + pub ht_name: *mut crate::object::PyObject, + pub ht_slots: *mut crate::object::PyObject, + pub ht_qualname: *mut crate::object::PyObject, pub ht_cached_keys: *mut c_void, } impl Clone for PyHeapTypeObject { @@ -641,17 +647,17 @@ mod typeobject { impl Default for PyHeapTypeObject { #[inline] fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } #[inline] pub unsafe fn PyHeapType_GET_MEMBERS( etype: *mut PyHeapTypeObject, - ) -> *mut ::structmember::PyMemberDef { - (etype as *mut c_char) - .offset((*::object::Py_TYPE(etype as *mut ::object::PyObject)).tp_basicsize as isize) - as *mut ::structmember::PyMemberDef + ) -> *mut crate::structmember::PyMemberDef { + (etype as *mut c_char).offset( + (*crate::object::Py_TYPE(etype as *mut crate::object::PyObject)).tp_basicsize as isize, + ) as *mut crate::structmember::PyMemberDef } } #[cfg(not(Py_LIMITED_API))] @@ -670,7 +676,7 @@ impl Clone for PyType_Slot { } impl Default for PyType_Slot { fn default() -> PyType_Slot { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } @@ -690,7 +696,7 @@ impl Clone for PyType_Spec { } impl Default for PyType_Spec { fn default() -> PyType_Spec { - unsafe { ::core::mem::zeroed() } + unsafe { core::mem::zeroed() } } } @@ -750,7 +756,7 @@ extern "C" { pub fn PyType_Modified(t: *mut PyTypeObject); #[cfg(not(Py_LIMITED_API))] - pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int; + pub fn PyObject_Print(o: *mut PyObject, fp: *mut libc::FILE, flags: c_int) -> c_int; pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_ASCII(arg1: *mut PyObject) -> *mut PyObject; diff --git a/python3-sys/src/objectabstract.rs b/python3-sys/src/objectabstract.rs index 6629ee72..3419aa60 100644 --- a/python3-sys/src/objectabstract.rs +++ b/python3-sys/src/objectabstract.rs @@ -1,7 +1,8 @@ use core::ptr; use libc::{c_char, c_int, c_void}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[inline] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { @@ -135,7 +136,8 @@ extern "C" { pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { (match (*(*o).ob_type).tp_iternext { Some(tp_iternext) => { - tp_iternext as *const c_void != ::object::_PyObject_NextNotImplemented as *const c_void + tp_iternext as *const c_void + != crate::object::_PyObject_NextNotImplemented as *const c_void } None => false, }) as c_int diff --git a/python3-sys/src/objimpl.rs b/python3-sys/src/objimpl.rs index 7306b270..beb4a0fd 100644 --- a/python3-sys/src/objimpl.rs +++ b/python3-sys/src/objimpl.rs @@ -1,6 +1,7 @@ use libc::{c_int, c_void, size_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/osmodule.rs b/python3-sys/src/osmodule.rs index 399196fe..97079b58 100644 --- a/python3-sys/src/osmodule.rs +++ b/python3-sys/src/osmodule.rs @@ -1,5 +1,5 @@ // This header is new in Python 3.6 -use object::PyObject; +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/pycapsule.rs b/python3-sys/src/pycapsule.rs index f35def72..a7da04e6 100644 --- a/python3-sys/src/pycapsule.rs +++ b/python3-sys/src/pycapsule.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_void}; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/pyerrors.rs b/python3-sys/src/pyerrors.rs index 1369eae7..481f07b5 100644 --- a/python3-sys/src/pyerrors.rs +++ b/python3-sys/src/pyerrors.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/pyhash.rs b/python3-sys/src/pyhash.rs index 7f4d7f85..cf2c6339 100644 --- a/python3-sys/src/pyhash.rs +++ b/python3-sys/src/pyhash.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, c_void}; -use pyport::{Py_hash_t, Py_ssize_t}; + +use crate::pyport::{Py_hash_t, Py_ssize_t}; #[repr(C)] #[derive(Copy)] diff --git a/python3-sys/src/pyport.rs b/python3-sys/src/pyport.rs index b3d1b485..0613c5f3 100644 --- a/python3-sys/src/pyport.rs +++ b/python3-sys/src/pyport.rs @@ -1,9 +1,9 @@ -pub type Py_uintptr_t = ::libc::uintptr_t; -pub type Py_intptr_t = ::libc::intptr_t; -pub type Py_ssize_t = ::libc::ssize_t; +pub type Py_uintptr_t = libc::uintptr_t; +pub type Py_intptr_t = libc::intptr_t; +pub type Py_ssize_t = libc::ssize_t; pub type Py_hash_t = Py_ssize_t; -pub type Py_uhash_t = ::libc::size_t; +pub type Py_uhash_t = libc::size_t; -pub const PY_SSIZE_T_MIN: Py_ssize_t = ::core::isize::MIN as Py_ssize_t; -pub const PY_SSIZE_T_MAX: Py_ssize_t = ::core::isize::MAX as Py_ssize_t; +pub const PY_SSIZE_T_MIN: Py_ssize_t = core::isize::MIN as Py_ssize_t; +pub const PY_SSIZE_T_MAX: Py_ssize_t = core::isize::MAX as Py_ssize_t; diff --git a/python3-sys/src/pystate.rs b/python3-sys/src/pystate.rs index 59285eef..f416b92c 100644 --- a/python3-sys/src/pystate.rs +++ b/python3-sys/src/pystate.rs @@ -1,6 +1,7 @@ use libc; -use moduleobject::PyModuleDef; -use object::PyObject; + +use crate::moduleobject::PyModuleDef; +use crate::object::PyObject; #[cfg(Py_3_6)] pub const MAX_CO_EXTRA_USERS: libc::c_int = 255; diff --git a/python3-sys/src/pystrtod.rs b/python3-sys/src/pystrtod.rs index c351b17f..c84e1815 100644 --- a/python3-sys/src/pystrtod.rs +++ b/python3-sys/src/pystrtod.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_double, c_int}; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/pythonrun.rs b/python3-sys/src/pythonrun.rs index 00fa25ba..bbaf5fcb 100644 --- a/python3-sys/src/pythonrun.rs +++ b/python3-sys/src/pythonrun.rs @@ -1,9 +1,10 @@ use core::ptr; use libc::{c_char, c_int, wchar_t, FILE}; -use object::*; + +use crate::object::*; #[cfg(not(Py_LIMITED_API))] -use pyarena::PyArena; -use pystate::PyThreadState; +use crate::pyarena::PyArena; +use crate::pystate::PyThreadState; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/rangeobject.rs b/python3-sys/src/rangeobject.rs index 208a5ff5..224171a8 100644 --- a/python3-sys/src/rangeobject.rs +++ b/python3-sys/src/rangeobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/setobject.rs b/python3-sys/src/setobject.rs index b6f95f4e..3aa57e18 100644 --- a/python3-sys/src/setobject.rs +++ b/python3-sys/src/setobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/sliceobject.rs b/python3-sys/src/sliceobject.rs index 4756fe70..7969dbc6 100644 --- a/python3-sys/src/sliceobject.rs +++ b/python3-sys/src/sliceobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/structmember.rs b/python3-sys/src/structmember.rs index 00a98cb4..a1508e61 100644 --- a/python3-sys/src/structmember.rs +++ b/python3-sys/src/structmember.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] diff --git a/python3-sys/src/structseq.rs b/python3-sys/src/structseq.rs index 5b85e962..a8aa3750 100644 --- a/python3-sys/src/structseq.rs +++ b/python3-sys/src/structseq.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::{PyObject, PyTypeObject}; -use pyport::Py_ssize_t; + +use crate::object::{PyObject, PyTypeObject}; +use crate::pyport::Py_ssize_t; #[repr(C)] #[derive(Copy)] diff --git a/python3-sys/src/sysmodule.rs b/python3-sys/src/sysmodule.rs index 4e563738..fdfc8cce 100644 --- a/python3-sys/src/sysmodule.rs +++ b/python3-sys/src/sysmodule.rs @@ -1,5 +1,6 @@ use libc::{c_char, c_int, wchar_t}; -use object::PyObject; + +use crate::object::PyObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/traceback.rs b/python3-sys/src/traceback.rs index eed26484..d5c8a81d 100644 --- a/python3-sys/src/traceback.rs +++ b/python3-sys/src/traceback.rs @@ -1,9 +1,10 @@ use libc::c_int; -use object::*; + +use crate::object::*; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - pub fn PyTraceBack_Here(arg1: *mut ::PyFrameObject) -> c_int; + pub fn PyTraceBack_Here(arg1: *mut crate::PyFrameObject) -> c_int; pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; pub static mut PyTraceBack_Type: PyTypeObject; diff --git a/python3-sys/src/tupleobject.rs b/python3-sys/src/tupleobject.rs index bd4291f3..0d958396 100644 --- a/python3-sys/src/tupleobject.rs +++ b/python3-sys/src/tupleobject.rs @@ -1,6 +1,7 @@ use libc::c_int; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[repr(C)] #[cfg(not(Py_LIMITED_API))] diff --git a/python3-sys/src/unicodeobject.rs b/python3-sys/src/unicodeobject.rs index 5bc0f8c6..2fa85468 100644 --- a/python3-sys/src/unicodeobject.rs +++ b/python3-sys/src/unicodeobject.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int, c_void, wchar_t}; -use object::*; -use pyport::Py_ssize_t; + +use crate::object::*; +use crate::pyport::Py_ssize_t; #[cfg(not(Py_LIMITED_API))] #[deprecated(since = "0.2.1", note = "Deprecated since Python 3.3 / PEP 393")] diff --git a/python3-sys/src/warnings.rs b/python3-sys/src/warnings.rs index 73790705..846216e5 100644 --- a/python3-sys/src/warnings.rs +++ b/python3-sys/src/warnings.rs @@ -1,6 +1,7 @@ use libc::{c_char, c_int}; -use object::PyObject; -use pyport::Py_ssize_t; + +use crate::object::PyObject; +use crate::pyport::Py_ssize_t; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { diff --git a/python3-sys/src/weakrefobject.rs b/python3-sys/src/weakrefobject.rs index 8307025b..c7628ad4 100644 --- a/python3-sys/src/weakrefobject.rs +++ b/python3-sys/src/weakrefobject.rs @@ -1,5 +1,6 @@ use libc::c_int; -use object::*; + +use crate::object::*; pub enum PyWeakReference {} From d1d93c210087f0e954dc8b14280ee04d0a4a26ac Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 21:11:40 -0800 Subject: [PATCH 08/10] cpython: edition 2018 --- Cargo.toml | 1 + src/argparse.rs | 17 +++++++++-------- src/buffer.rs | 24 +++++++++++------------ src/conversion.rs | 9 ++++----- src/err.rs | 24 +++++++++++------------ src/function.rs | 15 ++++++++------- src/lib.rs | 35 +++++++++++++++++----------------- src/objectprotocol.rs | 35 +++++++++++++++++++--------------- src/objects/boolobject.rs | 14 +++++++------- src/objects/capsule.rs | 9 +++++---- src/objects/dict.rs | 17 +++++++++-------- src/objects/exc.rs | 13 +++++++------ src/objects/iterator.rs | 16 ++++++++-------- src/objects/list.rs | 14 +++++++------- src/objects/mod.rs | 26 ++++++++++++------------- src/objects/module.rs | 16 ++++++++-------- src/objects/num.rs | 18 ++++++++--------- src/objects/object.rs | 15 ++++++++------- src/objects/oldstyle.rs | 8 ++++---- src/objects/sequence.rs | 26 ++++++++++++------------- src/objects/set.rs | 17 +++++++++-------- src/objects/string.rs | 28 ++++++++++++++------------- src/objects/tests.rs | 3 ++- src/objects/tuple.rs | 15 ++++++++------- src/objects/typeobject.rs | 11 ++++++----- src/py_class/gc.rs | 9 +++++---- src/py_class/members.rs | 11 ++++++----- src/py_class/mod.rs | 9 +++++---- src/py_class/py_class_impl.py | 6 +++--- src/py_class/py_class_impl2.rs | 8 ++++---- src/py_class/py_class_impl3.rs | 8 ++++---- src/py_class/slots.rs | 21 ++++++++++---------- src/python.rs | 33 +++++++++++++++++--------------- src/pythonrun.rs | 7 ++++--- 34 files changed, 281 insertions(+), 257 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2fb7a2a5..ef3f723a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ exclude = [ "/extensions/**" ] build = "build.rs" +edition = "2018" [badges] travis-ci = { repository = "dgrunwald/rust-cpython" } diff --git a/src/argparse.rs b/src/argparse.rs index ad3ea575..5bf853c6 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -19,13 +19,14 @@ //! This module contains logic for parsing a python argument list. //! See also the macros `py_argparse!`, `py_fn!` and `py_method!`. -use conversion::{RefFromPyObject, ToPyObject}; -use err::{self, PyResult}; -use ffi; -use objects::{exc, PyDict, PyObject, PyString, PyTuple}; -use python::{Python, PythonObject}; use std::ptr; +use crate::conversion::{RefFromPyObject, ToPyObject}; +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::objects::{exc, PyDict, PyObject, PyString, PyTuple}; +use crate::python::{Python, PythonObject}; + /// Description of a python parameter; used for `parse_args()`. pub struct ParamDescription<'a> { /// The name of the parameter. @@ -479,9 +480,9 @@ where #[cfg(test)] mod test { - use conversion::ToPyObject; - use objects::PyTuple; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::objects::PyTuple; + use crate::python::{Python, PythonObject}; #[test] pub fn test_parse() { diff --git a/src/buffer.rs b/src/buffer.rs index 4ebe4360..4c0662c2 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -16,15 +16,16 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use err::{self, PyResult}; -use exc; -use ffi; use libc; -use objects::PyObject; -use python::{PyDrop, Python}; use std::ffi::CStr; use std::{cell, mem, slice}; +use crate::err::{self, PyResult}; +use crate::exc; +use crate::ffi; +use crate::objects::PyObject; +use crate::python::{PyDrop, Python}; + /// Allows access to the underlying buffer used by a python object such as `bytes`, `bytearray` or `array.array`. pub struct PyBuffer(Box); // use Box<> because Python expects that the Py_buffer struct has a stable memory address @@ -194,7 +195,7 @@ impl PyBuffer { unsafe { ffi::PyBuffer_GetPointer( &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, - indices.as_ptr() as *mut usize as *mut ::Py_ssize_t, + indices.as_ptr() as *mut usize as *mut crate::Py_ssize_t, ) } } @@ -663,17 +664,16 @@ impl_element!(f64, Float); #[cfg(test)] mod test { use super::PyBuffer; - use conversion::ToPyObject; - use objectprotocol::ObjectProtocol; - use objects::{PyIterator, PyList, PySequence, PyTuple}; - use python::{PyDrop, Python, PythonObject}; - use std; + use crate::conversion::ToPyObject; + use crate::objectprotocol::ObjectProtocol; + use crate::objects::{PyIterator, PyList, PySequence, PyTuple}; + use crate::python::{PyDrop, Python, PythonObject}; #[test] fn test_compatible_size() { // for the cast in PyBuffer::shape() assert_eq!( - std::mem::size_of::<::Py_ssize_t>(), + std::mem::size_of::(), std::mem::size_of::() ); } diff --git a/src/conversion.rs b/src/conversion.rs index 36a77d46..3ca9539a 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -16,11 +16,10 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use err::PyResult; -use ffi; -use objects::PyObject; -use python::{PyClone, PyDrop, Python, PythonObject, PythonObjectWithCheckedDowncast}; -use std; +use crate::err::PyResult; +use crate::ffi; +use crate::objects::PyObject; +use crate::python::{PyClone, PyDrop, Python, PythonObject, PythonObjectWithCheckedDowncast}; /// Conversion trait that allows various objects to be converted into Python objects. /// diff --git a/src/err.rs b/src/err.rs index e31c73e9..6e3d777a 100644 --- a/src/err.rs +++ b/src/err.rs @@ -16,20 +16,20 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use ffi; use libc; use libc::c_char; +use std::ffi::CString; +use std::ptr; + +use crate::conversion::ToPyObject; +use crate::ffi; #[cfg(feature = "python27-sys")] -use objects::oldstyle::PyClass; -use objects::{exc, PyObject, PyType}; -use python::{ +use crate::objects::oldstyle::PyClass; +use crate::objects::{exc, PyObject, PyType}; +use crate::python::{ PyClone, PyDrop, Python, PythonObject, PythonObjectDowncastError, PythonObjectWithTypeObject, ToPythonPointer, }; -use std; -use std::ffi::CString; -use std::ptr; /** Defines a new exception type. @@ -497,7 +497,7 @@ pub unsafe fn from_owned_ptr_or_panic(py: Python, p: *mut ffi::PyObject) -> PyOb pub unsafe fn result_cast_from_owned_ptr(py: Python, p: *mut ffi::PyObject) -> PyResult where - T: ::python::PythonObjectWithCheckedDowncast, + T: crate::python::PythonObjectWithCheckedDowncast, { if p.is_null() { Err(PyErr::fetch(py)) @@ -508,7 +508,7 @@ where pub unsafe fn cast_from_owned_ptr_or_panic(py: Python, p: *mut ffi::PyObject) -> T where - T: ::python::PythonObjectWithCheckedDowncast, + T: crate::python::PythonObjectWithCheckedDowncast, { if p.is_null() { panic_after_error(py); @@ -547,8 +547,8 @@ macro_rules! _cpython__err__stringify { #[cfg(test)] mod tests { - use objects::exc; - use {PyErr, Python}; + use crate::objects::exc; + use crate::{PyErr, Python}; #[test] fn set_typeerror() { diff --git a/src/function.rs b/src/function.rs index e709179d..a3b753b0 100644 --- a/src/function.rs +++ b/src/function.rs @@ -16,16 +16,17 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyResult}; -use ffi; use libc; -use objects::{exc, PyDict, PyObject, PyString, PyTuple}; -use python::{PyDrop, Python, PythonObject}; use std::ffi::{CStr, CString}; use std::panic; use std::{any, io, marker, mem, ptr}; +use crate::conversion::ToPyObject; +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::objects::{exc, PyDict, PyObject, PyString, PyTuple}; +use crate::python::{PyDrop, Python, PythonObject}; + #[macro_export(local_inner_macros)] #[doc(hidden)] macro_rules! py_method_def { @@ -51,7 +52,7 @@ macro_rules! py_method_def { if !$doc.is_empty() { METHOD_DEF.ml_doc = _cpython__concat!($doc, "\0").as_ptr() as *const _; } - METHOD_DEF.ml_meth = Some(::std::mem::transmute::< + METHOD_DEF.ml_meth = Some(std::mem::transmute::< $crate::_detail::ffi::PyCFunctionWithKeywords, $crate::_detail::ffi::PyCFunction, >($wrap)); @@ -169,7 +170,7 @@ pub unsafe fn py_fn_impl(py: Python, method_def: *mut ffi::PyMethodDef) -> PyObj pub trait CallbackConverter { type R; - fn convert(S, Python) -> Self::R; + fn convert(val: S, py: Python) -> Self::R; fn error_value() -> Self::R; } diff --git a/src/lib.rs b/src/lib.rs index 4aa4da27..c647f7cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,26 +86,29 @@ //! } //! ``` -extern crate libc; +use std::{mem, ptr}; #[cfg(feature = "python27-sys")] -extern crate python27_sys as ffi; +pub(crate) use python27_sys as ffi; #[cfg(feature = "python3-sys")] -extern crate python3_sys as ffi; +pub(crate) use python3_sys as ffi; -pub use conversion::{FromPyObject, RefFromPyObject, ToPyObject}; -pub use err::{PyErr, PyResult}; pub use ffi::Py_ssize_t; -pub use objectprotocol::ObjectProtocol; -pub use objects::*; -pub use py_class::CompareOp; -pub use python::{ + +pub use crate::conversion::{FromPyObject, RefFromPyObject, ToPyObject}; +pub use crate::err::{PyErr, PyResult}; +pub use crate::objectprotocol::ObjectProtocol; +pub use crate::objects::*; +pub use crate::py_class::CompareOp; +pub use crate::python::{ PyClone, PyDrop, Python, PythonObject, PythonObjectDowncastError, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject, }; -pub use pythonrun::{prepare_freethreaded_python, GILGuard, GILProtected}; -pub use sharedref::{PyLeakedRef, PyLeakedRefMut, PySharedRef, PySharedRefCell, UnsafePyLeaked}; +pub use crate::pythonrun::{prepare_freethreaded_python, GILGuard, GILProtected}; +pub use crate::sharedref::{ + PyLeakedRef, PyLeakedRefMut, PySharedRef, PySharedRefCell, UnsafePyLeaked, +}; #[cfg(feature = "python27-sys")] #[allow(non_camel_case_types)] @@ -115,14 +118,12 @@ pub type Py_hash_t = libc::c_long; #[allow(non_camel_case_types)] pub type Py_hash_t = ffi::Py_hash_t; -use std::{mem, ptr}; - /// Constructs a `&'static CStr` literal. macro_rules! cstr( ($s: tt) => ( // TODO: verify that $s is a string literal without nuls unsafe { - ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) + std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) } ); ); @@ -219,13 +220,13 @@ mod sharedref; #[doc(hidden)] pub mod _detail { pub mod ffi { - pub use ffi::*; + pub use crate::ffi::*; } pub mod libc { pub use libc::{c_char, c_int, c_void}; } - pub use err::{from_owned_ptr_or_panic, result_from_owned_ptr}; - pub use function::{ + pub use crate::err::{from_owned_ptr_or_panic, result_from_owned_ptr}; + pub use crate::function::{ handle_callback, py_fn_impl, AbortOnDrop, PyObjectCallbackConverter, PythonObjectCallbackConverter, }; diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index ebd82090..230b8287 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -16,15 +16,16 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyErr, PyResult}; -use ffi; use libc; -use objects::{PyDict, PyObject, PyString, PyTuple}; -use python::{Python, PythonObject, ToPythonPointer}; use std::cmp::Ordering; use std::fmt; +use crate::conversion::ToPyObject; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::objects::{PyDict, PyObject, PyString, PyTuple}; +use crate::python::{Python, PythonObject, ToPythonPointer}; + /// Trait that contains methods pub trait ObjectProtocol: PythonObject { /// Determines whether this object has the given attribute. @@ -138,7 +139,7 @@ pub trait ObjectProtocol: PythonObject { } else if result < 0 { return Err(PyErr::fetch(py)); } - return Err(PyErr::new::<::exc::TypeError, _>( + return Err(PyErr::new::( py, "ObjectProtocol::compare(): All comparisons returned false", )); @@ -156,7 +157,12 @@ pub trait ObjectProtocol: PythonObject { /// * CompareOp::Le: `self <= other` /// * CompareOp::Gt: `self > other` /// * CompareOp::Ge: `self >= other` - fn rich_compare(&self, py: Python, other: O, compare_op: ::CompareOp) -> PyResult + fn rich_compare( + &self, + py: Python, + other: O, + compare_op: crate::CompareOp, + ) -> PyResult where O: ToPyObject, { @@ -186,7 +192,7 @@ pub trait ObjectProtocol: PythonObject { /// This is equivalent to the Python expression 'unistr(self)'. #[inline] #[cfg(feature = "python27-sys")] - fn unistr(&self, py: Python) -> PyResult<::objects::PyUnicode> { + fn unistr(&self, py: Python) -> PyResult { unsafe { err::result_cast_from_owned_ptr(py, ffi::PyObject_Unicode(self.as_ptr())) } } @@ -250,7 +256,7 @@ pub trait ObjectProtocol: PythonObject { /// Retrieves the hash code of the object. /// This is equivalent to the Python expression: 'hash(self)' #[inline] - fn hash(&self, py: Python) -> PyResult<::Py_hash_t> { + fn hash(&self, py: Python) -> PyResult { let v = unsafe { ffi::PyObject_Hash(self.as_ptr()) }; if v == -1 { Err(PyErr::fetch(py)) @@ -325,9 +331,9 @@ pub trait ObjectProtocol: PythonObject { /// This is typically a new iterator but if the argument /// is an iterator, this returns itself. #[inline] - fn iter<'p>(&self, py: Python<'p>) -> PyResult<::objects::PyIterator<'p>> { + fn iter<'p>(&self, py: Python<'p>) -> PyResult> { let obj = unsafe { err::result_from_owned_ptr(py, ffi::PyObject_GetIter(self.as_ptr())) }?; - Ok(::objects::PyIterator::from_object(py, obj)?) + Ok(crate::objects::PyIterator::from_object(py, obj)?) } } @@ -356,10 +362,9 @@ impl fmt::Display for PyObject { #[cfg(test)] mod test { use super::ObjectProtocol; - use conversion::ToPyObject; - use objects::{PyList, PyTuple}; - use python::{Python, PythonObject}; - use std; + use crate::conversion::ToPyObject; + use crate::objects::{PyList, PyTuple}; + use crate::python::{Python, PythonObject}; #[test] fn test_debug_string() { diff --git a/src/objects/boolobject.rs b/src/objects/boolobject.rs index 6d11b4c5..efb43822 100644 --- a/src/objects/boolobject.rs +++ b/src/objects/boolobject.rs @@ -1,8 +1,8 @@ use super::PyObject; -use conversion::ToPyObject; -use err::PyResult; -use ffi; -use python::Python; +use crate::conversion::ToPyObject; +use crate::err::PyResult; +use crate::ffi; +use crate::python::Python; /// Represents a Python `bool`. pub struct PyBool(PyObject); @@ -23,7 +23,7 @@ impl PyBool { /// Gets whether this boolean is `true`. #[inline] pub fn is_true(&self) -> bool { - self.0.as_ptr() == unsafe { ::ffi::Py_True() } + self.0.as_ptr() == unsafe { crate::ffi::Py_True() } } } @@ -63,8 +63,8 @@ extract!(obj to bool; #[cfg(test)] mod test { - use conversion::ToPyObject; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::python::{Python, PythonObject}; #[test] fn test_true() { diff --git a/src/objects/capsule.rs b/src/objects/capsule.rs index 1c12a0e5..359ed9e2 100644 --- a/src/objects/capsule.rs +++ b/src/objects/capsule.rs @@ -1,13 +1,14 @@ //! Work wih Python capsules //! -use super::object::PyObject; -use err::{self, PyErr, PyResult}; -use ffi::{PyCapsule_GetPointer, PyCapsule_Import, PyCapsule_New}; use libc::c_void; -use python::{Python, ToPythonPointer}; use std::ffi::{CStr, CString, NulError}; use std::mem; +use super::object::PyObject; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi::{PyCapsule_GetPointer, PyCapsule_Import, PyCapsule_New}; +use crate::python::{Python, ToPythonPointer}; + /// Capsules are the preferred way to export/import C APIs between extension modules, /// see [Providing a C API for an Extension Module](https://docs.python.org/3/extending/extending.html#using-capsules). /// diff --git a/src/objects/dict.rs b/src/objects/dict.rs index a3e20a51..2994aa14 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -16,13 +16,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyErr, PyResult}; -use ffi; -use objects::{PyList, PyObject}; -use python::{Python, PythonObject}; use std::{cmp, collections, hash, mem}; +use crate::conversion::ToPyObject; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::objects::{PyList, PyObject}; +use crate::python::{Python, PythonObject}; + /// Represents a Python `dict`. pub struct PyDict(PyObject); @@ -172,9 +173,9 @@ where #[cfg(test)] mod test { - use conversion::ToPyObject; - use objects::{PyDict, PyTuple}; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::objects::{PyDict, PyTuple}; + use crate::python::{Python, PythonObject}; use std::collections::HashMap; #[test] diff --git a/src/objects/exc.rs b/src/objects/exc.rs index 237f533e..74ec94a3 100644 --- a/src/objects/exc.rs +++ b/src/objects/exc.rs @@ -18,17 +18,18 @@ //! This module contains the python exception types. +use libc::c_char; +use std::ffi::CStr; +use std::{mem, ops}; + use super::object::PyObject; use super::typeobject::PyType; -use err::{self, PyResult}; -use ffi; -use libc::c_char; -use python::{ +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::python::{ Python, PythonObject, PythonObjectDowncastError, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject, }; -use std::ffi::CStr; -use std::{self, mem, ops}; macro_rules! exc_type( ($name:ident, $exc_name:ident) => ( diff --git a/src/objects/iterator.rs b/src/objects/iterator.rs index 5d408389..4cf88b19 100644 --- a/src/objects/iterator.rs +++ b/src/objects/iterator.rs @@ -16,11 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{PyErr, PyResult}; -use ffi; -use objects::PyObject; -use python::{Python, PythonObject, PythonObjectDowncastError, ToPythonPointer}; +use crate::conversion::ToPyObject; +use crate::err::{PyErr, PyResult}; +use crate::ffi; +use crate::objects::PyObject; +use crate::python::{Python, PythonObject, PythonObjectDowncastError, ToPythonPointer}; /// A python iterator object. /// @@ -86,9 +86,9 @@ impl<'p> Iterator for PyIterator<'p> { #[cfg(test)] mod tests { - use conversion::ToPyObject; - use objectprotocol::ObjectProtocol; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::objectprotocol::ObjectProtocol; + use crate::python::{Python, PythonObject}; #[test] fn vec_iter() { diff --git a/src/objects/list.rs b/src/objects/list.rs index 0577ea33..348fdb90 100644 --- a/src/objects/list.rs +++ b/src/objects/list.rs @@ -17,10 +17,10 @@ // DEALINGS IN THE SOFTWARE. use super::object::PyObject; -use conversion::{FromPyObject, ToPyObject}; -use err::{self, PyErr, PyResult}; -use ffi::{self, Py_ssize_t}; -use python::{PyClone, PyDrop, Python, PythonObject, ToPythonPointer}; +use crate::conversion::{FromPyObject, ToPyObject}; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi::{self, Py_ssize_t}; +use crate::python::{PyClone, PyDrop, Python, PythonObject, ToPythonPointer}; /// Represents a Python `list`. pub struct PyList(PyObject); @@ -181,9 +181,9 @@ where #[cfg(test)] mod test { - use conversion::ToPyObject; - use objects::PyList; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::objects::PyList; + use crate::python::{Python, PythonObject}; #[test] fn test_len() { diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 738d9297..a69b9218 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -68,21 +68,21 @@ macro_rules! pyobject_newtype( /// Undefined behavior if the input object does not have the expected type. #[inline] unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a $crate::PyObject) -> &'a Self { - ::std::mem::transmute(obj) + std::mem::transmute(obj) } } ); ($name: ident, $checkfunction: ident) => ( pyobject_newtype!($name); - impl ::python::PythonObjectWithCheckedDowncast for $name { + impl crate::python::PythonObjectWithCheckedDowncast for $name { #[inline] - fn downcast_from<'p>(py: ::python::Python<'p>, obj: ::objects::object::PyObject) -> Result<$name, ::python::PythonObjectDowncastError<'p>> { + fn downcast_from<'p>(py: crate::python::Python<'p>, obj: crate::objects::object::PyObject) -> Result<$name, crate::python::PythonObjectDowncastError<'p>> { unsafe { - if ::ffi::$checkfunction(obj.as_ptr()) != 0 { + if crate::ffi::$checkfunction(obj.as_ptr()) != 0 { Ok($name(obj)) } else { - Err(::python::PythonObjectDowncastError::new( + Err(crate::python::PythonObjectDowncastError::new( py, _cpython__objects__stringify!($name), obj.get_type(py) @@ -92,12 +92,12 @@ macro_rules! pyobject_newtype( } #[inline] - fn downcast_borrow_from<'a, 'p>(py: ::python::Python<'p>, obj: &'a ::objects::object::PyObject) -> Result<&'a $name, ::python::PythonObjectDowncastError<'p>> { + fn downcast_borrow_from<'a, 'p>(py: crate::python::Python<'p>, obj: &'a crate::objects::object::PyObject) -> Result<&'a $name, crate::python::PythonObjectDowncastError<'p>> { unsafe { - if ::ffi::$checkfunction(obj.as_ptr()) != 0 { - Ok(::std::mem::transmute(obj)) + if crate::ffi::$checkfunction(obj.as_ptr()) != 0 { + Ok(std::mem::transmute(obj)) } else { - Err(::python::PythonObjectDowncastError::new( + Err(crate::python::PythonObjectDowncastError::new( py, _cpython__objects__stringify!($name), obj.get_type(py) @@ -110,10 +110,10 @@ macro_rules! pyobject_newtype( ($name: ident, $checkfunction: ident, $typeobject: ident) => ( pyobject_newtype!($name, $checkfunction); - impl ::python::PythonObjectWithTypeObject for $name { + impl crate::python::PythonObjectWithTypeObject for $name { #[inline] - fn type_object(py: ::python::Python) -> ::objects::typeobject::PyType { - unsafe { ::objects::typeobject::PyType::from_type_ptr(py, &mut ::ffi::$typeobject) } + fn type_object(py: crate::python::Python) -> crate::objects::typeobject::PyType { + unsafe { crate::objects::typeobject::PyType::from_type_ptr(py, &mut crate::ffi::$typeobject) } } } ); @@ -121,7 +121,7 @@ macro_rules! pyobject_newtype( macro_rules! extract( ($obj:ident to $t:ty; $(#[$meta:meta])* $py:ident => $body: block) => { - impl <'s> ::conversion::FromPyObject<'s> + impl <'s> crate::conversion::FromPyObject<'s> for $t { $(#[$meta])* diff --git a/src/objects/module.rs b/src/objects/module.rs index d4811d0b..1e2a9cb3 100644 --- a/src/objects/module.rs +++ b/src/objects/module.rs @@ -16,17 +16,17 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyErr, PyResult}; -use ffi; use libc::c_char; -use objectprotocol::ObjectProtocol; -use objects::{exc, PyDict, PyObject, PyTuple}; -use py_class::PythonObjectFromPyClassMacro; -use python::{PyDrop, Python, PythonObject}; -use std; use std::ffi::{CStr, CString}; +use crate::conversion::ToPyObject; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::objectprotocol::ObjectProtocol; +use crate::objects::{exc, PyDict, PyObject, PyTuple}; +use crate::py_class::PythonObjectFromPyClassMacro; +use crate::python::{PyDrop, Python, PythonObject}; + /// Represents a Python module object. pub struct PyModule(PyObject); diff --git a/src/objects/num.rs b/src/objects/num.rs index 31b27f7e..f81f2995 100644 --- a/src/objects/num.rs +++ b/src/objects/num.rs @@ -16,16 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate num_traits; +use libc::{c_double, c_long}; +use num_traits::cast::cast; -use self::num_traits::cast::cast; use super::exc; use super::object::PyObject; -use conversion::{FromPyObject, ToPyObject}; -use err::{self, PyErr, PyResult}; -use ffi; -use libc::{c_double, c_long}; -use python::{PyClone, Python, PythonObject}; +use crate::conversion::{FromPyObject, ToPyObject}; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::python::{PyClone, Python, PythonObject}; /// Represents a Python `int` object. /// @@ -338,9 +337,8 @@ extract!( #[cfg(test)] mod test { - use conversion::ToPyObject; - use python::{Python, PythonObject}; - use std; + use crate::conversion::ToPyObject; + use crate::python::{Python, PythonObject}; macro_rules! num_to_py_object_and_back ( ($func_name:ident, $t1:ty, $t2:ty) => ( diff --git a/src/objects/object.rs b/src/objects/object.rs index cfab99e3..d27d53ff 100644 --- a/src/objects/object.rs +++ b/src/objects/object.rs @@ -16,14 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use err::PyResult; -use ffi; -use objects::PyType; -use python::{ +use std::{mem, ptr}; + +use crate::err::PyResult; +use crate::ffi; +use crate::objects::PyType; +use crate::python::{ Python, PythonObject, PythonObjectDowncastError, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject, }; -use std::{mem, ptr}; /// Represents a reference to a Python object. /// @@ -254,9 +255,9 @@ impl PyObject { #[inline] pub fn extract<'a, T>(&'a self, py: Python) -> PyResult where - T: ::conversion::FromPyObject<'a>, + T: crate::conversion::FromPyObject<'a>, { - ::conversion::FromPyObject::extract(py, self) + crate::conversion::FromPyObject::extract(py, self) } } diff --git a/src/objects/oldstyle.rs b/src/objects/oldstyle.rs index c8317297..33cf4083 100644 --- a/src/objects/oldstyle.rs +++ b/src/objects/oldstyle.rs @@ -21,10 +21,10 @@ use super::dict::PyDict; use super::object::PyObject; use super::tuple::PyTuple; -use conversion::ToPyObject; -use err::{self, PyResult}; -use ffi; -use python::{Python, PythonObject, ToPythonPointer}; +use crate::conversion::ToPyObject; +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::python::{Python, PythonObject, ToPythonPointer}; /// Represents an old-style Python class. /// diff --git a/src/objects/sequence.rs b/src/objects/sequence.rs index d9a589be..8c446287 100644 --- a/src/objects/sequence.rs +++ b/src/objects/sequence.rs @@ -16,16 +16,17 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use buffer; -use conversion::{FromPyObject, ToPyObject}; -use err; -use err::{result_cast_from_owned_ptr, result_from_owned_ptr, PyErr, PyResult}; -use ffi; -use ffi::Py_ssize_t; -use objects::{PyIterator, PyList, PyObject, PyTuple}; -use python::{PyClone, PyDrop, Python, PythonObject, ToPythonPointer}; use std::mem; +use crate::buffer; +use crate::conversion::{FromPyObject, ToPyObject}; +use crate::err; +use crate::err::{result_cast_from_owned_ptr, result_from_owned_ptr, PyErr, PyResult}; +use crate::ffi; +use crate::ffi::Py_ssize_t; +use crate::objects::{PyIterator, PyList, PyObject, PyTuple}; +use crate::python::{PyClone, PyDrop, Python, PythonObject, ToPythonPointer}; + /// Represents a reference to a python object supporting the sequence protocol. pub struct PySequence(PyObject); @@ -225,7 +226,7 @@ impl PySequence { #[inline] pub fn iter<'p>(&self, py: Python<'p>) -> PyResult> { - use objectprotocol::ObjectProtocol; + use crate::objectprotocol::ObjectProtocol; self.as_object().iter(py) } } @@ -310,10 +311,9 @@ where #[cfg(test)] mod test { - use conversion::ToPyObject; - use objects::{PyIterator, PyList, PySequence, PyTuple}; - use python::{Python, PythonObject}; - use std; + use crate::conversion::ToPyObject; + use crate::objects::{PyIterator, PyList, PySequence, PyTuple}; + use crate::python::{Python, PythonObject}; #[test] fn test_numbers_are_not_sequences() { diff --git a/src/objects/set.rs b/src/objects/set.rs index ad3c6b54..6f8d17ad 100644 --- a/src/objects/set.rs +++ b/src/objects/set.rs @@ -16,13 +16,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyErr, PyResult}; -use ffi; -use objects::PyObject; -use python::{Python, PythonObject}; use std::{cmp, collections, hash, mem, ptr}; +use crate::conversion::ToPyObject; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::objects::PyObject; +use crate::python::{Python, PythonObject}; + /// Represents a Python `set`. pub struct PySet(PyObject); @@ -145,9 +146,9 @@ where #[cfg(test)] mod test { - use conversion::ToPyObject; - use objects::PySet; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::objects::PySet; + use crate::python::{Python, PythonObject}; use std::collections::{BTreeSet, HashSet}; #[test] diff --git a/src/objects/string.rs b/src/objects/string.rs index 06c54f53..ea5b918f 100644 --- a/src/objects/string.rs +++ b/src/objects/string.rs @@ -16,16 +16,16 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use super::{exc, PyObject}; -use conversion::{FromPyObject, RefFromPyObject, ToPyObject}; -use err::{self, PyErr, PyResult}; -use ffi; use libc::c_char; -use python::{PyClone, Python, PythonObject, PythonObjectDowncastError, ToPythonPointer}; -use std; use std::borrow::Cow; use std::{char, mem, str}; +use super::{exc, PyObject}; +use crate::conversion::{FromPyObject, RefFromPyObject, ToPyObject}; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::python::{PyClone, Python, PythonObject, PythonObjectDowncastError, ToPythonPointer}; + /// Represents a Python string. /// Corresponds to `basestring` in Python 2, and `str` in Python 3. pub struct PyString(PyObject); @@ -55,7 +55,7 @@ pyobject_newtype!(PyUnicode, PyUnicode_Check, PyUnicode_Type); pub use PyString as PyUnicode; #[cfg(feature = "python27-sys")] -impl ::python::PythonObjectWithCheckedDowncast for PyString { +impl crate::python::PythonObjectWithCheckedDowncast for PyString { #[inline] fn downcast_from<'p>( py: Python<'p>, @@ -79,9 +79,9 @@ impl ::python::PythonObjectWithCheckedDowncast for PyString { ) -> Result<&'a PyString, PythonObjectDowncastError<'p>> { unsafe { if is_base_string(obj) { - Ok(::std::mem::transmute(obj)) + Ok(std::mem::transmute(obj)) } else { - Err(::python::PythonObjectDowncastError::new( + Err(crate::python::PythonObjectDowncastError::new( py, "PyString", obj.get_type(py), @@ -103,10 +103,12 @@ fn is_base_string(obj: &PyObject) -> bool { } #[cfg(feature = "python27-sys")] -impl ::python::PythonObjectWithTypeObject for PyString { +impl crate::python::PythonObjectWithTypeObject for PyString { #[inline] fn type_object(py: Python) -> super::PyType { - unsafe { ::objects::typeobject::PyType::from_type_ptr(py, &mut ::ffi::PyBaseString_Type) } + unsafe { + crate::objects::typeobject::PyType::from_type_ptr(py, &mut ffi::PyBaseString_Type) + } } } @@ -531,8 +533,8 @@ impl RefFromPyObject for [u8] { #[cfg(test)] mod test { - use conversion::{RefFromPyObject, ToPyObject}; - use python::{Python, PythonObject}; + use crate::conversion::{RefFromPyObject, ToPyObject}; + use crate::python::{Python, PythonObject}; #[test] fn test_non_bmp() { diff --git a/src/objects/tests.rs b/src/objects/tests.rs index 2d18d8f9..309148a8 100644 --- a/src/objects/tests.rs +++ b/src/objects/tests.rs @@ -17,7 +17,8 @@ // DEALINGS IN THE SOFTWARE. use std::collections::{BTreeMap, HashMap}; -use {PyDict, PyInt, Python, ToPyObject}; + +use crate::{PyDict, PyInt, Python, ToPyObject}; // TODO: move these tests into the dict module #[test] diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index faa3eacd..f9b47ea3 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -16,13 +16,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use std::slice; + use super::exc; use super::object::PyObject; -use conversion::{FromPyObject, ToPyObject}; -use err::{self, PyErr, PyResult}; -use ffi::{self, Py_ssize_t}; -use python::{PyDrop, Python, PythonObject, ToPythonPointer}; -use std::slice; +use crate::conversion::{FromPyObject, ToPyObject}; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi::{self, Py_ssize_t}; +use crate::python::{PyDrop, Python, PythonObject, ToPythonPointer}; /// Represents a Python tuple object. pub struct PyTuple(PyObject); @@ -235,8 +236,8 @@ extract!(obj to NoArgs; #[cfg(test)] mod test { - use conversion::ToPyObject; - use python::{Python, PythonObject}; + use crate::conversion::ToPyObject; + use crate::python::{Python, PythonObject}; #[test] fn test_len() { diff --git a/src/objects/typeobject.rs b/src/objects/typeobject.rs index 564d7cb9..56452981 100644 --- a/src/objects/typeobject.rs +++ b/src/objects/typeobject.rs @@ -16,14 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{result_from_owned_ptr, PyResult}; -use ffi; -use objects::{PyDict, PyObject, PyTuple}; -use python::{Python, PythonObject, ToPythonPointer}; use std::borrow::Cow; use std::ffi::CStr; +use crate::conversion::ToPyObject; +use crate::err::{result_from_owned_ptr, PyResult}; +use crate::ffi; +use crate::objects::{PyDict, PyObject, PyTuple}; +use crate::python::{Python, PythonObject, ToPythonPointer}; + /// Represents a reference to a Python type object. pub struct PyType(PyObject); diff --git a/src/py_class/gc.rs b/src/py_class/gc.rs index def14fbd..aae1c74b 100644 --- a/src/py_class/gc.rs +++ b/src/py_class/gc.rs @@ -16,13 +16,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use ffi; -use function::AbortOnDrop; use libc; -use objects::PyObject; -use python::{PyDrop, Python, PythonObject, ToPythonPointer}; use std::mem; +use crate::ffi; +use crate::function::AbortOnDrop; +use crate::objects::PyObject; +use crate::python::{PyDrop, Python, PythonObject, ToPythonPointer}; + // TODO: what's the semantics of the traverse return code? // If it's just a normal python exception, we might want to use PyErr instead. pub struct TraverseError(libc::c_int); diff --git a/src/py_class/members.rs b/src/py_class/members.rs index 0167785c..4ee06042 100644 --- a/src/py_class/members.rs +++ b/src/py_class/members.rs @@ -16,13 +16,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{self, PyResult}; -use ffi; -use objects::PyObject; -use python::{Python, PythonObject}; use std::marker; +use crate::conversion::ToPyObject; +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::objects::PyObject; +use crate::python::{Python, PythonObject}; + /// Represents something that can be added as a member to a Python class/type. /// /// T: type of rust class used for instances of the Python class/type. diff --git a/src/py_class/mod.rs b/src/py_class/mod.rs index 82b1b359..42a9d838 100644 --- a/src/py_class/mod.rs +++ b/src/py_class/mod.rs @@ -34,13 +34,14 @@ mod py_class_impl3; #[doc(hidden)] pub mod slots; -use err::{self, PyResult}; -use ffi; use libc; -use objects::{PyModule, PyObject, PyType}; -use python::{self, Python, PythonObject}; use std::{cell, mem, ptr}; +use crate::err::{self, PyResult}; +use crate::ffi; +use crate::objects::{PyModule, PyObject, PyType}; +use crate::python::{self, Python, PythonObject}; + // TODO: consider moving CompareOp to a different module, so that it isn't exported via two paths #[derive(Debug)] pub enum CompareOp { diff --git a/src/py_class/py_class_impl.py b/src/py_class/py_class_impl.py index c817d5b1..9eb57e0e 100644 --- a/src/py_class/py_class_impl.py +++ b/src/py_class/py_class_impl.py @@ -78,7 +78,7 @@ /// Undefined behavior if the input object does not have the expected type. #[inline] unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a $crate::PyObject) -> &'a Self { - ::std::mem::transmute(obj) + std::mem::transmute(obj) } } @@ -99,7 +99,7 @@ #[inline] fn downcast_borrow_from<'a, 'p>(py: $crate::Python<'p>, obj: &'a $crate::PyObject) -> Result<&'a $class, $crate::PythonObjectDowncastError<'p>> { if py.get_type::<$class>().is_instance(py, obj) { - unsafe { Ok(::std::mem::transmute(obj)) } + unsafe { Ok(std::mem::transmute(obj)) } } else { Err($crate::PythonObjectDowncastError::new( py, @@ -629,7 +629,7 @@ def operator(special_name, slot, elif res_type == 'PyObject': res_conv = '$crate::_detail::PyObjectCallbackConverter' else: - res_conv = '$crate::_detail::PythonObjectCallbackConverter::<$crate::%s>(::std::marker::PhantomData)' % res_type + res_conv = '$crate::_detail::PythonObjectCallbackConverter::<$crate::%s>(std::marker::PhantomData)' % res_type arg_pattern = '' param_list = [] for arg in args: diff --git a/src/py_class/py_class_impl2.rs b/src/py_class/py_class_impl2.rs index 68e6c643..8c8549fd 100644 --- a/src/py_class/py_class_impl2.rs +++ b/src/py_class/py_class_impl2.rs @@ -70,7 +70,7 @@ macro_rules! py_class_impl { /// Undefined behavior if the input object does not have the expected type. #[inline] unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a $crate::PyObject) -> &'a Self { - ::std::mem::transmute(obj) + std::mem::transmute(obj) } } @@ -91,7 +91,7 @@ macro_rules! py_class_impl { #[inline] fn downcast_borrow_from<'a, 'p>(py: $crate::Python<'p>, obj: &'a $crate::PyObject) -> Result<&'a $class, $crate::PythonObjectDowncastError<'p>> { if py.get_type::<$class>().is_instance(py, obj) { - unsafe { Ok(::std::mem::transmute(obj)) } + unsafe { Ok(std::mem::transmute(obj)) } } else { Err($crate::PythonObjectDowncastError::new( py, @@ -1512,7 +1512,7 @@ macro_rules! py_class_impl { /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(::std::marker::PhantomData)), + tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } @@ -1685,7 +1685,7 @@ macro_rules! py_class_impl { /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(::std::marker::PhantomData)), + tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } diff --git a/src/py_class/py_class_impl3.rs b/src/py_class/py_class_impl3.rs index 12820dc8..ae275fde 100644 --- a/src/py_class/py_class_impl3.rs +++ b/src/py_class/py_class_impl3.rs @@ -70,7 +70,7 @@ macro_rules! py_class_impl { /// Undefined behavior if the input object does not have the expected type. #[inline] unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a $crate::PyObject) -> &'a Self { - ::std::mem::transmute(obj) + std::mem::transmute(obj) } } @@ -91,7 +91,7 @@ macro_rules! py_class_impl { #[inline] fn downcast_borrow_from<'a, 'p>(py: $crate::Python<'p>, obj: &'a $crate::PyObject) -> Result<&'a $class, $crate::PythonObjectDowncastError<'p>> { if py.get_type::<$class>().is_instance(py, obj) { - unsafe { Ok(::std::mem::transmute(obj)) } + unsafe { Ok(std::mem::transmute(obj)) } } else { Err($crate::PythonObjectDowncastError::new( py, @@ -1512,7 +1512,7 @@ macro_rules! py_class_impl { /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(::std::marker::PhantomData)), + tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } @@ -1685,7 +1685,7 @@ macro_rules! py_class_impl { /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(::std::marker::PhantomData)), + tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } diff --git a/src/py_class/slots.rs b/src/py_class/slots.rs index db10e8b9..bc50b56f 100644 --- a/src/py_class/slots.rs +++ b/src/py_class/slots.rs @@ -16,18 +16,19 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use conversion::ToPyObject; -use err::{PyErr, PyResult}; -use exc; -use ffi; -use function::CallbackConverter; use libc::{c_char, c_int}; -use objects::PyObject; -use py_class::CompareOp; -use python::{Python, PythonObject}; use std::ffi::CString; use std::{isize, mem, ptr}; -use Py_hash_t; + +use crate::conversion::ToPyObject; +use crate::err::{PyErr, PyResult}; +use crate::exc; +use crate::ffi; +use crate::function::CallbackConverter; +use crate::objects::PyObject; +use crate::py_class::CompareOp; +use crate::python::{Python, PythonObject}; +use crate::Py_hash_t; #[macro_export(local_inner_macros)] #[doc(hidden)] @@ -117,7 +118,7 @@ pub unsafe extern "C" fn tp_dealloc_callback(obj: *mut ffi::PyObject) where T: super::BaseObject, { - let guard = ::function::AbortOnDrop("Cannot unwind out of tp_dealloc"); + let guard = crate::function::AbortOnDrop("Cannot unwind out of tp_dealloc"); let py = Python::assume_gil_acquired(); let r = T::dealloc(py, obj); mem::forget(guard); diff --git a/src/python.rs b/src/python.rs index a51d8184..263f1557 100644 --- a/src/python.rs +++ b/src/python.rs @@ -16,15 +16,15 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use err::{self, PyErr, PyResult}; -use ffi; use libc::c_int; -use objects::{PyBool, PyDict, PyModule, PyObject, PyType}; -use pythonrun::GILGuard; -use std; use std::ffi::CString; use std::marker::PhantomData; +use crate::err::{self, PyErr, PyResult}; +use crate::ffi; +use crate::objects::{PyBool, PyDict, PyModule, PyObject, PyType}; +use crate::pythonrun::GILGuard; + /// Marker type that indicates that the GIL is currently held. /// /// The 'Python' struct is a zero-size marker struct that is required for most Python operations. @@ -39,7 +39,7 @@ use std::marker::PhantomData; pub struct Python<'p>(PhantomData<&'p GILGuard>); /// Trait implemented by all Python object types. -pub trait PythonObject: ::conversion::ToPyObject + Send + Sized + 'static { +pub trait PythonObject: crate::conversion::ToPyObject + Send + Sized + 'static { /// Casts the Python object to PyObject. fn as_object(&self) -> &PyObject; @@ -48,11 +48,11 @@ pub trait PythonObject: ::conversion::ToPyObject + Send + Sized + 'static { /// Unchecked downcast from PyObject to Self. /// Undefined behavior if the input object does not have the expected type. - unsafe fn unchecked_downcast_from(PyObject) -> Self; + unsafe fn unchecked_downcast_from(obj: PyObject) -> Self; /// Unchecked downcast from PyObject to Self. /// Undefined behavior if the input object does not have the expected type. - unsafe fn unchecked_downcast_borrow_from(&PyObject) -> &Self; + unsafe fn unchecked_downcast_borrow_from(obj: &PyObject) -> &Self; } // Marker type that indicates an error while downcasting @@ -80,23 +80,26 @@ impl<'p> PythonObjectDowncastError<'p> { /// Trait implemented by Python object types that allow a checked downcast. pub trait PythonObjectWithCheckedDowncast: PythonObject { /// Cast from PyObject to a concrete Python object type. - fn downcast_from<'p>(Python<'p>, PyObject) -> Result>; + fn downcast_from<'p>( + py: Python<'p>, + obj: PyObject, + ) -> Result>; /// Cast from PyObject to a concrete Python object type. fn downcast_borrow_from<'a, 'p>( - Python<'p>, - &'a PyObject, + py: Python<'p>, + obj: &'a PyObject, ) -> Result<&'a Self, PythonObjectDowncastError<'p>>; } /// Trait implemented by Python object types that have a corresponding type object. pub trait PythonObjectWithTypeObject: PythonObjectWithCheckedDowncast { /// Retrieves the type object for this Python object type. - fn type_object(Python) -> PyType; + fn type_object(py: Python) -> PyType; } pub trait PyClone: Sized { - fn clone_ref(&self, Python) -> Self; + fn clone_ref(&self, py: Python) -> Self; } impl PyClone for T @@ -124,7 +127,7 @@ where } pub trait PyDrop: Sized { - fn release_ref(self, Python); + fn release_ref(self, py: Python); } impl PyDrop for T @@ -369,7 +372,7 @@ impl<'p> std::fmt::Debug for PythonObjectDowncastError<'p> { #[cfg(test)] mod test { - use {PyDict, Python}; + use crate::{PyDict, Python}; #[test] fn test_eval() { diff --git a/src/pythonrun.rs b/src/pythonrun.rs index d632d5dd..6bb84190 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -16,10 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use ffi; -use python::Python; use std::{marker, rc, sync}; +use crate::ffi; +use crate::python::Python; + static START: sync::Once = sync::Once::new(); /// Prepares the use of Python in a free-threaded context. @@ -113,7 +114,7 @@ impl GILGuard { /// See [prepare_freethreaded_python()](fn.prepare_freethreaded_python.html) for details. pub fn acquire() -> GILGuard { if !cfg!(feature = "no-auto-initialize") { - ::pythonrun::prepare_freethreaded_python(); + crate::pythonrun::prepare_freethreaded_python(); } let gstate = unsafe { ffi::PyGILState_Ensure() }; // acquire GIL GILGuard { From 45fdacca12ace4ac7e580fd253c10643d6de3682 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Mon, 27 Jan 2020 22:28:29 -0800 Subject: [PATCH 09/10] use edition 2018 style macro export and import --- README.md | 6 +- examples/hello.rs | 2 - extensions/hello/Cargo.toml | 1 + extensions/hello/src/hello.rs | 5 +- extensions/tests/Makefile | 5 +- extensions/tests/btree.rs | 4 +- extensions/tests/custom_class.rs | 4 +- extensions/tests/hello.rs | 4 +- python27-sys/README.md | 6 - python27-sys/build.rs | 2 - python27-sys/examples/version.rs | 3 - python3-sys/README.md | 6 - python3-sys/build.rs | 2 - python3-sys/examples/version.rs | 3 - src/argparse.rs | 58 ++-- src/err.rs | 39 +-- src/function.rs | 44 +-- src/lib.rs | 5 +- src/objects/capsule.rs | 28 +- src/objects/mod.rs | 18 +- src/py_class/members.rs | 41 +-- src/py_class/py_class.rs | 15 +- src/py_class/py_class_impl.py | 108 +++---- src/py_class/py_class_impl2.rs | 526 +++++++++++++++---------------- src/py_class/py_class_impl3.rs | 526 +++++++++++++++---------------- src/py_class/slots.rs | 55 ++-- tests/test_class.rs | 2 - tests/test_function.rs | 5 +- tests/test_sharedref.rs | 5 +- 29 files changed, 651 insertions(+), 877 deletions(-) diff --git a/README.md b/README.md index 7bdd4aec..e9a768af 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ cpython = "0.4" #### Example program displaying the value of `sys.version`: ```rust -extern crate cpython; - use cpython::{Python, PyDict, PyResult}; fn main() { @@ -78,9 +76,7 @@ features = ["extension-module"] **`src/lib.rs`** ```rust -#[macro_use] extern crate cpython; - -use cpython::{PyResult, Python}; +use cpython::{PyResult, Python, py_module_initializer, py_fn}; // add bindings to the generated python module // N.B: names: "rust2py" must be the name of the `.so` or `.pyd` file diff --git a/examples/hello.rs b/examples/hello.rs index 408f9de9..80ec33cb 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,5 +1,3 @@ -extern crate cpython; - use cpython::{PyDict, PyResult, Python}; fn main() { diff --git a/extensions/hello/Cargo.toml b/extensions/hello/Cargo.toml index 7c93eb94..b822d448 100644 --- a/extensions/hello/Cargo.toml +++ b/extensions/hello/Cargo.toml @@ -2,6 +2,7 @@ name = "hello" version = "0.4.0" authors = ["Daniel Grunwald "] +edition = "2018" [lib] ## Python extension modules should be compiled as 'cdylib' diff --git a/extensions/hello/src/hello.rs b/extensions/hello/src/hello.rs index b39b34b2..d5771d9b 100644 --- a/extensions/hello/src/hello.rs +++ b/extensions/hello/src/hello.rs @@ -1,7 +1,4 @@ -#[macro_use] -extern crate cpython; - -use cpython::{PyDict, PyObject, PyResult, PyTuple, Python}; +use cpython::{py_fn, py_module_initializer, PyDict, PyObject, PyResult, PyTuple, Python}; // Our module is named 'hello', and can be imported using `import hello`. // This requires that the output binary file is named `hello.so` (or Windows: `hello.pyd`). diff --git a/extensions/tests/Makefile b/extensions/tests/Makefile index 2e73cebd..9880e343 100644 --- a/extensions/tests/Makefile +++ b/extensions/tests/Makefile @@ -21,7 +21,6 @@ all: clean: $(RM) *.so $(RM) *.out - $(RM) *_expanded.rs $(RM) -r stamps stamps: @@ -33,10 +32,10 @@ stamps/rust-cpython-$(PY): $(call rwildcard,../../src,*.rs) Makefile | stamps touch "$@" %.so: %.rs stamps/rust-cpython-$(PY) - rustc $< -g -L $(TARGETDIR) -L $(TARGETDIR)/deps -o $@ + rustc $< --edition 2018 -g -L $(TARGETDIR) -L $(TARGETDIR)/deps --extern cpython=$(TARGETDIR)/libcpython.rlib -o $@ %_expanded.rs: %.rs stamps/rust-cpython-$(PY) - rustc $< -g -L $(TARGETDIR) -L $(TARGETDIR)/deps -Z unstable-options --pretty=expanded -o $@ + rustc $< --edition 2018 -g -L $(TARGETDIR) -L $(TARGETDIR)/deps -Z unstable-options --pretty=expanded --extern cpython=$(TARGETDIR)/libcpython.rlib -o $@ hello.out: hello.so python$(PY) -c "import hello; hello.run(hello.val())" 2>&1 | tee $@ diff --git a/extensions/tests/btree.rs b/extensions/tests/btree.rs index 1a5044f8..6cfe8b40 100644 --- a/extensions/tests/btree.rs +++ b/extensions/tests/btree.rs @@ -1,8 +1,6 @@ #![crate_type = "dylib"] -#[macro_use] extern crate cpython; - -use cpython::{PyObject, PyResult}; +use cpython::{PyObject, PyResult, py_module_initializer, py_class}; use std::{cell, cmp, collections}; py_module_initializer!(btree, initbtree, PyInit_btree, |py, m| { diff --git a/extensions/tests/custom_class.rs b/extensions/tests/custom_class.rs index 6f9dde98..f1d64b50 100644 --- a/extensions/tests/custom_class.rs +++ b/extensions/tests/custom_class.rs @@ -1,8 +1,6 @@ #![crate_type = "dylib"] -#[macro_use] extern crate cpython; - -use cpython::{PyObject, PyResult}; +use cpython::{PyObject, PyResult, py_module_initializer, py_class}; py_module_initializer!(custom_class, initcustom_class, PyInit_custom_class, |py, m| { m.add(py, "__doc__", "Module documentation string")?; diff --git a/extensions/tests/hello.rs b/extensions/tests/hello.rs index b2ce8cbe..87597884 100644 --- a/extensions/tests/hello.rs +++ b/extensions/tests/hello.rs @@ -1,8 +1,6 @@ #![crate_type = "dylib"] -#[macro_use] extern crate cpython; - -use cpython::{PyObject, PyResult, Python, PyTuple, PyDict}; +use cpython::{PyObject, PyResult, Python, PyTuple, PyDict, py_module_initializer, py_fn}; py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { m.add(py, "__doc__", "Module documentation string")?; diff --git a/python27-sys/README.md b/python27-sys/README.md index 47a26fc7..9566c17e 100644 --- a/python27-sys/README.md +++ b/python27-sys/README.md @@ -19,11 +19,5 @@ For a safe high-level API, see [rust-cpython](https://github.com/dgrunwald/rust- version = "*" ``` -In Rust, import the crate like this: - -```rust -extern crate python27_sys as py; -``` - Documentation for the python API is available on [https://docs.python.org/2/c-api/]. diff --git a/python27-sys/build.rs b/python27-sys/build.rs index c2e8261a..6def1c48 100644 --- a/python27-sys/build.rs +++ b/python27-sys/build.rs @@ -1,8 +1,6 @@ // THIS FILE IS GENERATED FROM python3-sys/build.rs // DO NOT MODIFY -extern crate regex; - use regex::Regex; use std::collections::HashMap; use std::env; diff --git a/python27-sys/examples/version.rs b/python27-sys/examples/version.rs index 797f4666..4af51dcb 100644 --- a/python27-sys/examples/version.rs +++ b/python27-sys/examples/version.rs @@ -1,6 +1,3 @@ -extern crate libc; -extern crate python27_sys; - unsafe fn get_str<'a>(s: *const libc::c_char) -> &'a str { let bytes = std::ffi::CStr::from_ptr(s).to_bytes(); std::str::from_utf8(bytes).unwrap() diff --git a/python3-sys/README.md b/python3-sys/README.md index 2b0f4a72..44819506 100644 --- a/python3-sys/README.md +++ b/python3-sys/README.md @@ -20,11 +20,5 @@ For a safe high-level API, see [rust-cpython](https://github.com/dgrunwald/rust- version = "*" ``` -In Rust, import the crate like this: - -```rust -extern crate python3_sys as py; -``` - Documentation for the python API is available on [https://docs.python.org/3/c-api/]. diff --git a/python3-sys/build.rs b/python3-sys/build.rs index b233c5c5..1f51152f 100644 --- a/python3-sys/build.rs +++ b/python3-sys/build.rs @@ -1,5 +1,3 @@ -extern crate regex; - use regex::Regex; use std::collections::HashMap; use std::env; diff --git a/python3-sys/examples/version.rs b/python3-sys/examples/version.rs index b60cf976..979c9fd0 100644 --- a/python3-sys/examples/version.rs +++ b/python3-sys/examples/version.rs @@ -1,6 +1,3 @@ -extern crate libc; -extern crate python3_sys; - unsafe fn get_str<'a>(s: *const libc::c_char) -> &'a str { let bytes = std::ffi::CStr::from_ptr(s).to_bytes(); std::str::from_utf8(bytes).unwrap() diff --git a/src/argparse.rs b/src/argparse.rs index 5bf853c6..2c3cd570 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -167,14 +167,14 @@ pub fn parse_args( /// so `return` statements might behave unexpectedly in this case. (this only affects direct use /// of `py_argparse!`; `py_fn!` is unaffected as the body there is always in a separate function /// from the generated argument-parsing code). -#[macro_export(local_inner_macros)] +#[macro_export] macro_rules! py_argparse { ($py:expr, $fname:expr, $args:expr, $kwargs:expr, $plist:tt $body:block) => { - py_argparse_parse_plist! { py_argparse_impl { $py, $fname, $args, $kwargs, $body, } $plist } + $crate::py_argparse_parse_plist! { py_argparse_impl { $py, $fname, $args, $kwargs, $body, } $plist } }; } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_argparse_parse_plist { // Parses a parameter-list into a format more suitable for consumption by Rust macros. @@ -184,30 +184,30 @@ macro_rules! py_argparse_parse_plist { // Special-case entry-point for empty parameter list: { $callback:ident { $($initial_arg:tt)* } ( ) } => { - $callback! { $($initial_arg)* [] } + $crate::$callback! { $($initial_arg)* [] } }; // Regular entry point for non-empty parameter list: { $callback:ident $initial_args:tt ( $( $p:tt )+ ) } => { // add trailing comma to plist so that the parsing step can assume every // parameter ends with a comma. - py_argparse_parse_plist_impl! { $callback $initial_args [] ( $($p)*, ) } + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [] ( $($p)*, ) } }; } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_argparse_parse_plist_impl { // TT muncher macro that does the main work for py_argparse_parse_plist!. // Base case: all parameters handled { $callback:ident { $($initial_arg:tt)* } $output:tt ( ) } => { - $callback! { $($initial_arg)* $output } + $crate::$callback! { $($initial_arg)* $output } }; // Kwargs parameter with reference extraction { $callback:ident $initial_args:tt [ $($output:tt)* ] ( ** $name:ident : &$t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$t = [ {**} {} {$t} ] } ] ($($tail)*) @@ -217,7 +217,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( ** $name:ident : $t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:$t = [ {**} {} {} ] } ] ($($tail)*) @@ -227,7 +227,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( ** $name:ident , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:Option<&$crate::PyDict> = [ {**} {} {} ] } ] ($($tail)*) @@ -237,7 +237,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( * $name:ident : &$t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$t = [ {*} {} {$t} ] } ] ($($tail)*) @@ -247,7 +247,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( * $name:ident : $t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:$t = [ {*} {} {} ] } ] ($($tail)*) @@ -257,7 +257,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( * $name:ident , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$crate::PyTuple = [ {*} {} {} ] } ] ($($tail)*) @@ -267,7 +267,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( $name:ident : &$t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$t = [ {} {} {$t} ] } ] ($($tail)*) @@ -277,7 +277,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( $name:ident : $t:ty , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:$t = [ {} {} {} ] } ] ($($tail)*) @@ -287,7 +287,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( $name:ident , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$crate::PyObject = [ {} {} {} ] } ] ($($tail)*) @@ -297,7 +297,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( $name:ident : &$t:ty = $default:expr, $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:&$t = [ {} {$default} {$t} ] } ] ($($tail)*) @@ -307,7 +307,7 @@ macro_rules! py_argparse_parse_plist_impl { { $callback:ident $initial_args:tt [ $($output:tt)* ] ( $name:ident : $t:ty = $default:expr , $($tail:tt)* ) } => { - py_argparse_parse_plist_impl! { + $crate::py_argparse_parse_plist_impl! { $callback $initial_args [ $($output)* { $name:$t = [ {} {$default} {} ] } ] ($($tail)*) @@ -317,7 +317,7 @@ macro_rules! py_argparse_parse_plist_impl { // The main py_argparse!() macro, except that it expects the parameter-list // in the output format of py_argparse_parse_plist!(). -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_argparse_impl { // special case: function signature is (*args, **kwargs), @@ -341,11 +341,11 @@ macro_rules! py_argparse_impl { ) => {{ const PARAMS: &'static [$crate::argparse::ParamDescription<'static>] = &[ $( - py_argparse_param_description! { $pname : $ptype = $detail } + $crate::py_argparse_param_description! { $pname : $ptype = $detail } ),* ]; let py: $crate::Python = $py; - let mut output = [$( py_replace_expr!($pname None) ),*]; + let mut output = [$( $crate::py_replace_expr!($pname None) ),*]; match $crate::argparse::parse_args(py, $fname, PARAMS, $args, $kwargs, &mut output) { Ok(()) => { // Experimental slice pattern syntax would be really nice here (#23121) @@ -355,7 +355,7 @@ macro_rules! py_argparse_impl { // We'll have to generate a bunch of nested `match` statements // (at least until we can use ? + catch, assuming that will be hygienic wrt. macros), // so use a recursive helper macro for that: - py_argparse_extract!( py, _iter, $body, + $crate::py_argparse_extract!( py, _iter, $body, [ $( { $pname : $ptype = $detail } )* ]) }, Err(e) => Err(e) @@ -364,14 +364,14 @@ macro_rules! py_argparse_impl { } // Like py_argparse_impl!(), but accepts `*mut ffi::PyObject` for $args and $kwargs. -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_argparse_raw { ($py:ident, $fname:expr, $args:expr, $kwargs:expr, $plist:tt $body:block) => {{ let args: $crate::PyTuple = $crate::PyObject::from_borrowed_ptr($py, $args).unchecked_cast_into(); let kwargs: Option<$crate::PyDict> = $crate::argparse::get_kwargs($py, $kwargs); - let ret = py_argparse_impl!($py, $fname, &args, kwargs.as_ref(), $body, $plist); + let ret = $crate::py_argparse_impl!($py, $fname, &args, kwargs.as_ref(), $body, $plist); $crate::PyDrop::release_ref(args, $py); $crate::PyDrop::release_ref(kwargs, $py); ret @@ -407,7 +407,7 @@ macro_rules! py_argparse_param_description { ); } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_argparse_extract { // base case @@ -419,7 +419,7 @@ macro_rules! py_argparse_extract { // First unwrap() asserts the iterated sequence is long enough (which should be guaranteed); // second unwrap() asserts the parameter was not missing (which fn parse_args already checked for). match <$ptype as $crate::FromPyObject>::extract($py, $iter.next().unwrap().as_ref().unwrap()) { - Ok($pname) => py_argparse_extract!($py, $iter, $body, [$($tail)*]), + Ok($pname) => $crate::py_argparse_extract!($py, $iter, $body, [$($tail)*]), Err(e) => Err(e) } }; @@ -431,7 +431,7 @@ macro_rules! py_argparse_extract { // second unwrap() asserts the parameter was not missing (which fn parse_args already checked for). match <$rtype as $crate::RefFromPyObject>::with_extracted($py, $iter.next().unwrap().as_ref().unwrap(), - |$pname: $ptype| py_argparse_extract!($py, $iter, $body, [$($tail)*]) + |$pname: $ptype| $crate::py_argparse_extract!($py, $iter, $body, [$($tail)*]) ) { Ok(v) => v, Err(e) => Err(e) @@ -442,7 +442,7 @@ macro_rules! py_argparse_extract { [ { $pname:ident : $ptype:ty = [ {} {$default:expr} {} ] } $($tail:tt)* ] ) => { match $iter.next().unwrap().as_ref().map(|obj| obj.extract::<_>($py)).unwrap_or(Ok($default)) { - Ok($pname) => py_argparse_extract!($py, $iter, $body, [$($tail)*]), + Ok($pname) => $crate::py_argparse_extract!($py, $iter, $body, [$($tail)*]), Err(e) => Err(e) } }; @@ -453,7 +453,7 @@ macro_rules! py_argparse_extract { //unwrap() asserts the iterated sequence is long enough (which should be guaranteed); $crate::argparse::with_extracted_or_default($py, $iter.next().unwrap().as_ref(), - |$pname: $ptype| py_argparse_extract!($py, $iter, $body, [$($tail)*]), + |$pname: $ptype| $crate::py_argparse_extract!($py, $iter, $body, [$($tail)*]), $default) }; } diff --git a/src/err.rs b/src/err.rs index 6e3d777a..194896e8 100644 --- a/src/err.rs +++ b/src/err.rs @@ -42,10 +42,7 @@ Defines a new exception type. # Example ``` -#[macro_use] -extern crate cpython; - -use cpython::{Python, PyDict}; +use cpython::{Python, PyDict, py_exception}; py_exception!(mymodule, CustomError); @@ -61,12 +58,12 @@ fn main() { } ``` */ -#[macro_export(local_inner_macros)] +#[macro_export] macro_rules! py_exception { ($module: ident, $name: ident, $base: ty) => { pub struct $name($crate::PyObject); - pyobject_newtype!($name); + $crate::pyobject_newtype!($name); impl $name { pub fn new<'p, T: $crate::ToPyObject>( @@ -90,7 +87,7 @@ macro_rules! py_exception { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__err__stringify!($name), + stringify!($name), <$name as $crate::PythonObjectWithTypeObject>::type_object(py), )) } @@ -108,7 +105,7 @@ macro_rules! py_exception { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__err__stringify!($name), + stringify!($name), <$name as $crate::PythonObjectWithTypeObject>::type_object(py), )) } @@ -125,11 +122,7 @@ macro_rules! py_exception { if type_object.is_null() { type_object = $crate::PyErr::new_type( py, - _cpython__err__concat!( - _cpython__err__stringify!($module), - ".", - _cpython__err__stringify!($name) - ), + concat!(stringify!($module), ".", stringify!($name)), Some($crate::PythonObject::into_object(py.get_type::<$base>())), None, ) @@ -142,7 +135,7 @@ macro_rules! py_exception { } }; ($module: ident, $name: ident) => { - py_exception!($module, $name, $crate::exc::Exception); + $crate::py_exception!($module, $name, $crate::exc::Exception); }; } @@ -527,24 +520,6 @@ pub fn error_on_minusone(py: Python, result: libc::c_int) -> PyResult<()> { } } -// 2018 macros support -// -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__err__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__err__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - #[cfg(test)] mod tests { use crate::objects::exc; diff --git a/src/function.rs b/src/function.rs index a3b753b0..44612efd 100644 --- a/src/function.rs +++ b/src/function.rs @@ -27,11 +27,11 @@ use crate::ffi; use crate::objects::{exc, PyDict, PyObject, PyString, PyTuple}; use crate::python::{PyDrop, Python, PythonObject}; -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_method_def { ($name: expr, $flags: expr, $wrap: expr) => {{ - py_method_def!($name, $flags, $wrap, "") + $crate::py_method_def!($name, $flags, $wrap, "") }}; ($name: expr, $flags: expr, $wrap: expr, $doc: expr) => {{ @@ -45,12 +45,12 @@ macro_rules! py_method_def { | $flags, ml_doc: 0 as *const $crate::_detail::libc::c_char, }; - METHOD_DEF.ml_name = _cpython__concat!($name, "\0").as_ptr() as *const _; + METHOD_DEF.ml_name = concat!($name, "\0").as_ptr() as *const _; if $name.starts_with("r#") { METHOD_DEF.ml_name = METHOD_DEF.ml_name.add(2); } if !$doc.is_empty() { - METHOD_DEF.ml_doc = _cpython__concat!($doc, "\0").as_ptr() as *const _; + METHOD_DEF.ml_doc = concat!($doc, "\0").as_ptr() as *const _; } METHOD_DEF.ml_meth = Some(std::mem::transmute::< $crate::_detail::ffi::PyCFunctionWithKeywords, @@ -101,8 +101,7 @@ macro_rules! py_method_def { /// /// # Example /// ``` -/// #[macro_use] extern crate cpython; -/// use cpython::{Python, PyResult, PyErr, PyDict}; +/// use cpython::{Python, PyResult, PyErr, PyDict, py_fn}; /// use cpython::{exc}; /// /// fn multiply(py: Python, lhs: i32, rhs: i32) -> PyResult { @@ -120,17 +119,17 @@ macro_rules! py_method_def { /// py.run("print(multiply(6, 7))", None, Some(&dict)).unwrap(); /// } /// ``` -#[macro_export(local_inner_macros)] +#[macro_export] macro_rules! py_fn { ($py:expr, $f:ident $plist:tt ) => { - py_argparse_parse_plist! { py_fn_impl { $py, $f } $plist } + $crate::py_argparse_parse_plist! { py_fn_impl { $py, $f } $plist } }; ($py:ident, $f:ident $plist:tt -> $ret:ty { $($body:tt)* } ) => { - py_argparse_parse_plist! { py_fn_impl { $py, $f, $ret, { $($body)* } } $plist } + $crate::py_argparse_parse_plist! { py_fn_impl { $py, $f, $ret, { $($body)* } } $plist } }; } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_fn_impl { // Form 1: reference existing function @@ -142,9 +141,9 @@ macro_rules! py_fn_impl { -> *mut $crate::_detail::ffi::PyObject { $crate::_detail::handle_callback( - _cpython__function__stringify!($f), $crate::_detail::PyObjectCallbackConverter, + stringify!($f), $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(_cpython__function__stringify!($f)), args, kwargs, + $crate::py_argparse_raw!(py, Some(stringify!($f)), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { $f(py $(, $pname )* ) @@ -153,13 +152,13 @@ macro_rules! py_fn_impl { } unsafe { $crate::_detail::py_fn_impl($py, - py_method_def!(_cpython__function__stringify!($f), 0, wrap)) + $crate::py_method_def!(stringify!($f), 0, wrap)) } }}; // Form 2: inline function definition { $py:ident, $f:ident, $ret:ty, $body:block [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ] } => {{ fn $f($py: $crate::Python $( , $pname : $ptype )* ) -> $ret $body - py_fn_impl!($py, $f [ $( { $pname : $ptype = $detail } )* ]) + $crate::py_fn_impl!($py, $f [ $( { $pname : $ptype = $detail } )* ]) }} } @@ -256,21 +255,4 @@ impl<'a> Drop for AbortOnDrop<'a> { } } -// Rust 2018 support -#[macro_export] -#[doc(hidden)] -macro_rules! _cpython__function__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - // Tests for this file are in tests/test_function.rs diff --git a/src/lib.rs b/src/lib.rs index c647f7cd..fb77036c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,8 +64,6 @@ //! //! # Example //! ``` -//! extern crate cpython; -//! //! use cpython::{Python, PyDict, PyResult}; //! //! fn main() { @@ -246,8 +244,7 @@ pub mod _detail { /// /// # Example /// ``` -/// #[macro_use] extern crate cpython; -/// use cpython::{Python, PyResult, PyObject}; +/// use cpython::{Python, PyResult, PyObject, py_module_initializer, py_fn}; /// /// py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { /// m.add(py, "__doc__", "Module documentation string")?; diff --git a/src/objects/capsule.rs b/src/objects/capsule.rs index 359ed9e2..90e61101 100644 --- a/src/objects/capsule.rs +++ b/src/objects/capsule.rs @@ -32,9 +32,6 @@ use crate::python::{Python, ToPythonPointer}; /// Note: this example is a lower-level version of the [`py_capsule!`] example. Only the /// capsule retrieval actually differs. /// ``` -/// #[macro_use] extern crate cpython; -/// extern crate libc; -/// /// use cpython::{Python, PyCapsule}; /// use libc::{c_void, c_char, c_int}; /// use std::ffi::{CStr, CString}; @@ -134,9 +131,6 @@ use crate::python::{Python, ToPythonPointer}; /// /// /// ``` -/// extern crate cpython; -/// extern crate libc; -/// /// use libc::{c_void, c_int}; /// use cpython::{PyCapsule, Python}; /// use std::ffi::{CStr, CString}; @@ -169,10 +163,8 @@ use crate::python::{Python, ToPythonPointer}; /// Note that in that case, the capsule `name` must be full dotted name of the capsule object, /// as we're doing here. /// ``` -/// # #[macro_use] extern crate cpython; -/// # extern crate libc; /// # use libc::c_int; -/// # use cpython::PyCapsule; +/// # use cpython::{PyCapsule, py_module_initializer}; /// # #[repr(C)] /// # struct CapsData { /// # value: c_int, @@ -237,10 +229,7 @@ pyobject_newtype!(PyCapsule, PyCapsule_CheckExact, PyCapsule_Type); /// In this case, as with all capsules from the Python standard library, the capsule data /// is an array (`static struct`) with constants and function pointers. /// ``` -/// #[macro_use] extern crate cpython; -/// extern crate libc; -/// -/// use cpython::{Python, PyCapsule}; +/// use cpython::{Python, PyCapsule, py_capsule}; /// use libc::{c_char, c_int}; /// use std::ffi::{c_void, CStr, CString}; /// use std::mem; @@ -325,10 +314,7 @@ pyobject_newtype!(PyCapsule, PyCapsule_CheckExact, PyCapsule_Type); /// In this example, we lend a Python object and receive a new one of which we take ownership. /// /// ``` -/// #[macro_use] extern crate cpython; -/// extern crate libc; -/// -/// use cpython::{PyCapsule, PyObject, PyResult, Python}; +/// use cpython::{PyCapsule, PyObject, PyResult, Python, py_capsule}; /// use libc::c_void; /// /// // In the struct, we still have to use c_void for C-level Python objects. @@ -429,9 +415,7 @@ macro_rules! py_capsule { /// /// /// ``` -/// #[macro_use] extern crate cpython; -/// extern crate libc; -/// use cpython::{PyCapsule, Python, FromPyObject}; +/// use cpython::{PyCapsule, Python, FromPyObject, py_capsule_fn}; /// use libc::{c_int, c_void}; /// /// extern "C" fn inc(a: c_int) -> c_int { @@ -475,8 +459,7 @@ macro_rules! py_capsule { /// In this example, we lend a Python object and receive a new one of which we take ownership. /// /// ``` -/// #[macro_use] extern crate cpython; -/// use cpython::{PyCapsule, PyObject, PyResult, Python}; +/// use cpython::{PyCapsule, PyObject, PyResult, Python, py_capsule_fn}; /// /// py_capsule_fn!(from some.mod import capsfn as capsmod /// signature (raw: *mut RawPyObject) -> *mut RawPyObject); @@ -583,7 +566,6 @@ impl PyCapsule { /// can be obtained simply by a simple cast: /// /// ``` - /// extern crate libc; /// use libc::c_void; /// /// extern "C" fn inc(a: i32) -> i32 { diff --git a/src/objects/mod.rs b/src/objects/mod.rs index a69b9218..98fa040f 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -40,11 +40,11 @@ pub use self::sequence::PySequence; pub use self::set::PySet; pub use self::tuple::{NoArgs, PyTuple}; -#[macro_export(local_inner_macros)] +#[macro_export] macro_rules! pyobject_newtype( ($name: ident) => ( - py_impl_to_py_object_for_python_object!($name); - py_impl_from_py_object_for_python_object!($name); + $crate::py_impl_to_py_object_for_python_object!($name); + $crate::py_impl_from_py_object_for_python_object!($name); impl $crate::PythonObject for $name { #[inline] @@ -84,7 +84,7 @@ macro_rules! pyobject_newtype( } else { Err(crate::python::PythonObjectDowncastError::new( py, - _cpython__objects__stringify!($name), + stringify!($name), obj.get_type(py) )) } @@ -99,7 +99,7 @@ macro_rules! pyobject_newtype( } else { Err(crate::python::PythonObjectDowncastError::new( py, - _cpython__objects__stringify!($name), + stringify!($name), obj.get_type(py) )) } @@ -132,14 +132,6 @@ macro_rules! extract( } ); -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__objects__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - mod boolobject; mod capsule; mod dict; diff --git a/src/py_class/members.rs b/src/py_class/members.rs index 4ee06042..2b224c72 100644 --- a/src/py_class/members.rs +++ b/src/py_class/members.rs @@ -78,11 +78,11 @@ macro_rules! py_class_init_members { }}; } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_instance_method { ($py:ident, $class:ident :: $f:ident [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ - py_class_instance_method!($py, $class::$f, { "" } [ $( { $pname : $ptype = $detail } )* ]) + $crate::py_class_instance_method!($py, $class::$f, { "" } [ $( { $pname : $ptype = $detail } )* ]) }}; ($py:ident, $class:ident :: $f:ident, { $doc:expr } [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ @@ -92,11 +92,11 @@ macro_rules! py_class_instance_method { kwargs: *mut $crate::_detail::ffi::PyObject) -> *mut $crate::_detail::ffi::PyObject { - const LOCATION: &'static str = _cpython__py_class__members__concat!(_cpython__py_class__members__stringify!($class), ".", _cpython__py_class__members__stringify!($f), "()"); + const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()"); $crate::_detail::handle_callback( LOCATION, $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(LOCATION), args, kwargs, + $crate::py_argparse_raw!(py, Some(LOCATION), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { let slf = $crate::PyObject::from_borrowed_ptr(py, slf).unchecked_cast_into::<$class>(); @@ -107,7 +107,7 @@ macro_rules! py_class_instance_method { }) } unsafe { - let method_def = py_method_def!(_cpython__py_class__members__stringify!($f), 0, wrap_instance_method, $doc); + let method_def = $crate::py_method_def!(stringify!($f), 0, wrap_instance_method, $doc); $crate::py_class::members::create_instance_method_descriptor::<$class>(method_def) } }} @@ -146,11 +146,11 @@ macro_rules! py_class_class_method { kwargs: *mut $crate::_detail::ffi::PyObject) -> *mut $crate::_detail::ffi::PyObject { - const LOCATION: &'static str = _cpython__py_class__members__concat!(_cpython__py_class__members__stringify!($class), ".", _cpython__py_class__members__stringify!($f), "()"); + const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()"); $crate::_detail::handle_callback( LOCATION, $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(LOCATION), args, kwargs, + $crate::py_argparse_raw!(py, Some(LOCATION), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { let cls = $crate::PyObject::from_borrowed_ptr(py, cls).unchecked_cast_into::<$crate::PyType>(); @@ -161,7 +161,7 @@ macro_rules! py_class_class_method { }) } unsafe { - let method_def = py_method_def!(_cpython__py_class__members__stringify!($f), + let method_def = $crate::py_method_def!(stringify!($f), $crate::_detail::ffi::METH_CLASS, wrap_class_method, $doc); @@ -193,7 +193,7 @@ where #[doc(hidden)] macro_rules! py_class_static_method { ($py:ident, $class:ident :: $f:ident [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ - py_class_static_method!($py, $class::$f, { "" } [ $( { $pname : $ptype = $detail } )* ]) + $crate::py_class_static_method!($py, $class::$f, { "" } [ $( { $pname : $ptype = $detail } )* ]) }}; ($py:ident, $class:ident :: $f:ident, { $doc:expr } [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ @@ -203,11 +203,11 @@ macro_rules! py_class_static_method { kwargs: *mut $crate::_detail::ffi::PyObject) -> *mut $crate::_detail::ffi::PyObject { - const LOCATION: &'static str = _cpython__py_class__members__concat!(_cpython__py_class__members__stringify!($class), ".", _cpython__py_class__members__stringify!($f), "()"); + const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()"); $crate::_detail::handle_callback( LOCATION, $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(LOCATION), args, kwargs, + $crate::py_argparse_raw!(py, Some(LOCATION), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { $class::$f(py $(, $pname )* ) @@ -215,7 +215,7 @@ macro_rules! py_class_static_method { }) } unsafe { - let method_def = py_method_def!(_cpython__py_class__members__stringify!($f), + let method_def = $crate::py_method_def!(stringify!($f), $crate::_detail::ffi::METH_STATIC, wrap_static_method, $doc); @@ -223,20 +223,3 @@ macro_rules! py_class_static_method { } }} } - -// Rust 2018 support -#[macro_export] -#[doc(hidden)] -macro_rules! _cpython__py_class__members__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - -#[macro_export] -#[doc(hidden)] -macro_rules! _cpython__py_class__members__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} diff --git a/src/py_class/py_class.rs b/src/py_class/py_class.rs index 7bf7747b..a2d0b427 100644 --- a/src/py_class/py_class.rs +++ b/src/py_class/py_class.rs @@ -33,8 +33,7 @@ in all function bodies. # Example ``` -#[macro_use] extern crate cpython; -use cpython::{Python, PyResult, PyDict}; +use cpython::{Python, PyResult, PyDict, py_class}; py_class!(class MyType |py| { data number: i32; @@ -198,9 +197,8 @@ as every cycle must contain at least one mutable reference. Example: ``` -#[macro_use] extern crate cpython; use std::{mem, cell}; -use cpython::{PyObject, PyDrop}; +use cpython::{PyObject, PyDrop, py_class}; py_class!(class ClassWithGCSupport |py| { data obj: cell::RefCell>; @@ -251,9 +249,8 @@ Iterators can be defined using the Python special methods `__iter__` and `__next Example: ``` -#[macro_use] extern crate cpython; use std::cell::RefCell; -use cpython::{PyObject, PyClone, PyResult}; +use cpython::{PyObject, PyClone, PyResult, py_class}; py_class!(class MyIterator |py| { data iter: RefCell + Send>>; @@ -425,7 +422,7 @@ py_class!(class MyIterator |py| { #[macro_export] macro_rules! py_class { (class $class:ident |$py: ident| { $( $body:tt )* }) => ( - py_class_impl! { + $crate::py_class_impl! { { $( $body )* } $class $py /* info: */ { @@ -454,7 +451,7 @@ macro_rules! py_class { } ); (pub class $class:ident |$py: ident| { $( $body:tt )* }) => ( - py_class_impl! { + $crate::py_class_impl! { { $( $body )* } $class $py /* info: */ { @@ -489,7 +486,7 @@ macro_rules! py_class { macro_rules! py_class_impl_item { { $class:ident, $py:ident, $name:ident( $( $selfarg:tt )* ) $res_type:ty; $body:block [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ] - } => { py_coerce_item! { + } => { $crate::py_coerce_item! { impl $class { pub fn $name($( $selfarg )* $py: $crate::Python $( , $pname: $ptype )* ) -> $res_type $body diff --git a/src/py_class/py_class_impl.py b/src/py_class/py_class_impl.py index 9eb57e0e..b6c3c90c 100644 --- a/src/py_class/py_class_impl.py +++ b/src/py_class/py_class_impl.py @@ -30,7 +30,7 @@ ''' macro_start = ''' -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_impl { // TT muncher macro. Results are accumulated in $info $slots $impls and $members. @@ -49,12 +49,12 @@ } $slots:tt { $( $imp:item )* } $members:tt } => { - py_coerce_item! { + $crate::py_coerce_item! { $($class_visibility)* struct $class { _unsafe_inner: $crate::PyObject } } - py_impl_to_py_object_for_python_object!($class); - py_impl_from_py_object_for_python_object!($class); + $crate::py_impl_to_py_object_for_python_object!($class); + $crate::py_impl_from_py_object_for_python_object!($class); impl $crate::PythonObject for $class { #[inline] @@ -90,7 +90,7 @@ } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } @@ -103,14 +103,14 @@ } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } } } - py_coerce_item! { + $crate::py_coerce_item! { impl $crate::py_class::BaseObject for $class { type InitType = ( $( $init_ty, )* ); @@ -137,7 +137,7 @@ } } $($imp)* - py_coerce_item! { + $crate::py_coerce_item! { impl $class { fn create_instance(py: $crate::Python $( , $data_name : $init_ty )* ) -> $crate::PyResult<$class> { let obj = unsafe { @@ -149,7 +149,7 @@ // hide statics in create_instance to avoid name conflicts static mut TYPE_OBJECT : $crate::_detail::ffi::PyTypeObject - = py_class_type_object_static_init!($class, $gc, $slots); + = $crate::py_class_type_object_static_init!($class, $gc, $slots); static mut INIT_ACTIVE: bool = false; // trait implementations that need direct access to TYPE_OBJECT @@ -161,7 +161,7 @@ } else { // automatically initialize the class on-demand <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, None) - .expect(_cpython__py_class__py_class_impl__concat!("An error occurred while initializing class ", _cpython__py_class__py_class_impl__stringify!($class))) + .expect(concat!("An error occurred while initializing class ", stringify!($class))) } } } @@ -173,9 +173,9 @@ if $crate::py_class::is_ready(py, &TYPE_OBJECT) { return Ok($crate::PyType::from_type_ptr(py, &mut TYPE_OBJECT)); } - _cpython__py_class__py_class_impl__assert!(!INIT_ACTIVE, - _cpython__py_class__py_class_impl__concat!("Reentrancy detected: already initializing class ", - _cpython__py_class__py_class_impl__stringify!($class))); + assert!(!INIT_ACTIVE, + concat!("Reentrancy detected: already initializing class ", + stringify!($class))); INIT_ACTIVE = true; let res = init(py, module_name); INIT_ACTIVE = false; @@ -185,13 +185,13 @@ fn add_to_module(py: $crate::Python, module: &$crate::PyModule) -> $crate::PyResult<()> { let ty = <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, module.name(py).ok())?; - module.add(py, _cpython__py_class__py_class_impl__stringify!($class), ty) + module.add(py, stringify!($class), ty) } } fn init($py: $crate::Python, module_name: Option<&str>) -> $crate::PyResult<$crate::PyType> { - py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); - py_class_init_members!($class, $py, TYPE_OBJECT, $members); + $crate::py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); + $crate::py_class_init_members!($class, $py, TYPE_OBJECT, $members); unsafe { if $crate::_detail::ffi::PyType_Ready(&mut TYPE_OBJECT) == 0 { Ok($crate::PyType::from_type_ptr($py, &mut TYPE_OBJECT)) @@ -293,7 +293,7 @@ def generate_case(pattern, old_info=None, new_info=None, new_impl=None, new_slot write('\n{ $( $member_name:ident = $member_expr:expr; )* }') else: write('$members:tt') - write('\n} => { py_class_impl! {\n') + write('\n} => { $crate::py_class_impl! {\n') write('{ $($tail)* }\n') write('$class $py') write(new_info or '$info') @@ -415,22 +415,22 @@ def generate_class_method(special_name=None, decoration='', def impl(with_params, with_docs): if with_docs: doc_prefix = '$(#[doc=$doc:expr])*' - value_suffix = ', { _cpython__py_class__py_class_impl__concat!($($doc, "\\n"),*) }' + value_suffix = ', { concat!($($doc, "\\n"),*) }' else: doc_prefix = value_suffix = '' if with_params: param_pattern = ', $($p:tt)+' - impl = '''py_argparse_parse_plist_impl!{ + impl = '''$crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, %s($cls: &$crate::PyType,) $res_type; { $($body)* } } [] ($($p)+,) }''' % name_use - value = 'py_argparse_parse_plist_impl!{%s {%s} [] ($($p)+,)}' \ + value = '$crate::py_argparse_parse_plist_impl!{%s {%s} [] ($($p)+,)}' \ % (value_macro, value_args + value_suffix) else: param_pattern = '' - impl = 'py_class_impl_item! { $class, $py,%s($cls: &$crate::PyType,) $res_type; { $($body)* } [] }' \ + impl = '$crate::py_class_impl_item! { $class, $py,%s($cls: &$crate::PyType,) $res_type; { $($body)* } [] }' \ % name_use - value = '%s!{%s []}' % (value_macro, value_args + value_suffix) + value = '$crate::%s!{%s []}' % (value_macro, value_args + value_suffix) pattern = '%s def %s ($cls:ident%s) -> $res_type:ty { $( $body:tt )* }' \ % (doc_prefix + decoration, name_pattern, param_pattern) slots = [] @@ -473,7 +473,7 @@ def traverse_and_clear(): } ''', new_impl=''' - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __traverse__(&$slf, $py: $crate::Python, @@ -484,9 +484,9 @@ def traverse_and_clear(): } ''') generate_case('def __clear__ (&$slf:ident) $body:block', - new_slots=[('tp_clear', 'py_class_tp_clear!($class)')], + new_slots=[('tp_clear', '$crate::py_class_tp_clear!($class)')], new_impl=''' - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __clear__(&$slf, $py: $crate::Python) $body } @@ -500,22 +500,22 @@ def generate_instance_method(special_name=None, decoration='', def impl(with_params, with_docs): if with_docs: doc_prefix = '$(#[doc=$doc:expr])*' - value_suffix = ', { _cpython__py_class__py_class_impl__concat!($($doc, "\\n"),*) }' + value_suffix = ', { concat!($($doc, "\\n"),*) }' else: doc_prefix = value_suffix = '' if with_params: param_pattern = ', $($p:tt)+' - impl = '''py_argparse_parse_plist_impl!{ + impl = '''$crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, %s(&$slf,) $res_type; { $($body)* } } [] ($($p)+,) }''' % name_use - value = 'py_argparse_parse_plist_impl!{%s {%s} [] ($($p)+,)}' \ + value = '$crate::py_argparse_parse_plist_impl!{%s {%s} [] ($($p)+,)}' \ % (value_macro, value_args + value_suffix) else: param_pattern = '' - impl = 'py_class_impl_item! { $class, $py, %s(&$slf,) $res_type; { $($body)* } [] }' \ + impl = '$crate::py_class_impl_item! { $class, $py, %s(&$slf,) $res_type; { $($body)* } [] }' \ % name_use - value = '%s!{%s []}' % (value_macro, value_args + value_suffix) + value = '$crate::%s!{%s []}' % (value_macro, value_args + value_suffix) pattern = '%s def %s (&$slf:ident%s) -> $res_type:ty { $( $body:tt )* }' \ % (doc_prefix + decoration, name_pattern, param_pattern) slots = [] @@ -535,15 +535,15 @@ def static_method(): generate_case( '$(#[doc=$doc:expr])* @staticmethod def $name:ident ($($p:tt)*) -> $res_type:ty { $( $body:tt )* }', new_impl=''' - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_impl_item { $class, $py, $name() $res_type; { $($body)* } } ($($p)*) } ''', new_members=[('$name', ''' - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_static_method {$py, $class::$name, { - _cpython__py_class__py_class_impl__concat!($($doc, "\\n"),*) + concat!($($doc, "\\n"),*) } } ($($p)*) } @@ -555,30 +555,6 @@ def static_data(): macro_end = ''' } - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__assert { - ($($inner:tt)*) => { - assert! { $($inner)* } - } -} ''' def special_method(decorated_function): @@ -592,7 +568,7 @@ def wrap2(special_name): def error(special_name, msg): print(''' { { def %s $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "%s" } + $crate::py_error! { "%s" } };''' % (special_name, msg)) @special_method @@ -636,24 +612,24 @@ def operator(special_name, slot, arg_pattern += ', ${0}:ident : ${0}_type:ty'.format(arg.name) param_list.append('{{ ${0} : ${0}_type = {{}} }}'.format(arg.name)) if slot == 'sq_contains': - new_slots = [(slot, 'py_class_contains_slot!($class::%s, $%s_type)' % (special_name, args[0].name))] + new_slots = [(slot, '$crate::py_class_contains_slot!($class::%s, $%s_type)' % (special_name, args[0].name))] elif slot == 'tp_richcompare': - new_slots = [(slot, 'py_class_richcompare_slot!($class::%s, $%s_type, %s, %s)' + new_slots = [(slot, '$crate::py_class_richcompare_slot!($class::%s, $%s_type, %s, %s)' % (special_name, args[0].name, res_ffi_type, res_conv))] elif len(args) == 0: - new_slots = [(slot, 'py_class_unary_slot!($class::%s, %s, %s)' + new_slots = [(slot, '$crate::py_class_unary_slot!($class::%s, %s, %s)' % (special_name, res_ffi_type, res_conv))] elif len(args) == 1: - new_slots = [(slot, 'py_class_binary_slot!($class::%s, $%s_type, %s, %s)' + new_slots = [(slot, '$crate::py_class_binary_slot!($class::%s, $%s_type, %s, %s)' % (special_name, args[0].name, res_ffi_type, res_conv))] elif len(args) == 2: - new_slots = [(slot, 'py_class_ternary_slot!($class::%s, $%s_type, $%s_type, %s, %s)' + new_slots = [(slot, '$crate::py_class_ternary_slot!($class::%s, $%s_type, $%s_type, %s, %s)' % (special_name, args[0].name, args[1].name, res_ffi_type, res_conv))] else: raise ValueError('Unsupported argument count') generate_case( pattern='def %s(&$slf:ident%s) -> $res_type:ty { $($body:tt)* }' % (special_name, arg_pattern), - new_impl='py_class_impl_item! { $class, $py, %s(&$slf,) $res_type; { $($body)* } [%s] }' + new_impl='$crate::py_class_impl_item! { $class, $py, %s(&$slf,) $res_type; { $($body)* } [%s] }' % (special_name, ' '.join(param_list)), new_slots=new_slots + list(additional_slots) ) @@ -674,9 +650,9 @@ def binary_numeric_operator(special_name, slot): generate_case( pattern='def %s($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* }' % special_name, - new_impl='py_class_impl_item! { $class, $py, %s() $res_type; { $($body)* } ' % special_name + new_impl='$crate::py_class_impl_item! { $class, $py, %s() $res_type; { $($body)* } ' % special_name +'[ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] }', - new_slots=[(slot, 'py_class_binary_numeric_slot!($class::%s)' % special_name)] + new_slots=[(slot, '$crate::py_class_binary_numeric_slot!($class::%s)' % special_name)] ) error('Invalid signature for binary numeric operator %s' % special_name)(special_name) diff --git a/src/py_class/py_class_impl2.rs b/src/py_class/py_class_impl2.rs index 8c8549fd..1f9f3e55 100644 --- a/src/py_class/py_class_impl2.rs +++ b/src/py_class/py_class_impl2.rs @@ -23,7 +23,7 @@ // DO NOT MODIFY !! // !!!!!!!!!!!!!!!!!!!!!!!!!!! -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_impl { // TT muncher macro. Results are accumulated in $info $slots $impls and $members. @@ -41,12 +41,12 @@ macro_rules! py_class_impl { } $slots:tt { $( $imp:item )* } $members:tt } => { - py_coerce_item! { + $crate::py_coerce_item! { $($class_visibility)* struct $class { _unsafe_inner: $crate::PyObject } } - py_impl_to_py_object_for_python_object!($class); - py_impl_from_py_object_for_python_object!($class); + $crate::py_impl_to_py_object_for_python_object!($class); + $crate::py_impl_from_py_object_for_python_object!($class); impl $crate::PythonObject for $class { #[inline] @@ -82,7 +82,7 @@ macro_rules! py_class_impl { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } @@ -95,14 +95,14 @@ macro_rules! py_class_impl { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } } } - py_coerce_item! { + $crate::py_coerce_item! { impl $crate::py_class::BaseObject for $class { type InitType = ( $( $init_ty, )* ); @@ -129,7 +129,7 @@ macro_rules! py_class_impl { } } $($imp)* - py_coerce_item! { + $crate::py_coerce_item! { impl $class { fn create_instance(py: $crate::Python $( , $data_name : $init_ty )* ) -> $crate::PyResult<$class> { let obj = unsafe { @@ -141,7 +141,7 @@ macro_rules! py_class_impl { // hide statics in create_instance to avoid name conflicts static mut TYPE_OBJECT : $crate::_detail::ffi::PyTypeObject - = py_class_type_object_static_init!($class, $gc, $slots); + = $crate::py_class_type_object_static_init!($class, $gc, $slots); static mut INIT_ACTIVE: bool = false; // trait implementations that need direct access to TYPE_OBJECT @@ -153,7 +153,7 @@ macro_rules! py_class_impl { } else { // automatically initialize the class on-demand <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, None) - .expect(_cpython__py_class__py_class_impl__concat!("An error occurred while initializing class ", _cpython__py_class__py_class_impl__stringify!($class))) + .expect(concat!("An error occurred while initializing class ", stringify!($class))) } } } @@ -165,9 +165,9 @@ macro_rules! py_class_impl { if $crate::py_class::is_ready(py, &TYPE_OBJECT) { return Ok($crate::PyType::from_type_ptr(py, &mut TYPE_OBJECT)); } - _cpython__py_class__py_class_impl__assert!(!INIT_ACTIVE, - _cpython__py_class__py_class_impl__concat!("Reentrancy detected: already initializing class ", - _cpython__py_class__py_class_impl__stringify!($class))); + assert!(!INIT_ACTIVE, + concat!("Reentrancy detected: already initializing class ", + stringify!($class))); INIT_ACTIVE = true; let res = init(py, module_name); INIT_ACTIVE = false; @@ -177,13 +177,13 @@ macro_rules! py_class_impl { fn add_to_module(py: $crate::Python, module: &$crate::PyModule) -> $crate::PyResult<()> { let ty = <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, module.name(py).ok())?; - module.add(py, _cpython__py_class__py_class_impl__stringify!($class), ty) + module.add(py, stringify!($class), ty) } } fn init($py: $crate::Python, module_name: Option<&str>) -> $crate::PyResult<$crate::PyType> { - py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); - py_class_init_members!($class, $py, TYPE_OBJECT, $members); + $crate::py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); + $crate::py_class_init_members!($class, $py, TYPE_OBJECT, $members); unsafe { if $crate::_detail::ffi::PyType_Ready(&mut TYPE_OBJECT) == 0 { Ok($crate::PyType::from_type_ptr($py, &mut TYPE_OBJECT)) @@ -209,7 +209,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -257,7 +257,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -309,7 +309,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -325,7 +325,7 @@ macro_rules! py_class_impl { $slots /* impl: */ { $($imp)* - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __traverse__(&$slf, $py: $crate::Python, @@ -345,19 +345,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_clear: py_class_tp_clear!($class), + tp_clear: $crate::py_class_tp_clear!($class), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __clear__(&$slf, $py: $crate::Python) $body } @@ -374,26 +374,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_absolute: py_class_unary_slot!($class::__abs__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_absolute: $crate::py_class_unary_slot!($class::__abs__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __abs__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __abs__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __abs__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __abs__" } + $crate::py_error! { "Invalid signature for operator __abs__" } }; { { def __add__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -404,38 +404,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_add: py_class_binary_numeric_slot!($class::__add__), + nb_add: $crate::py_class_binary_numeric_slot!($class::__add__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __add__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __add__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __add__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __add__" } + $crate::py_error! { "Invalid signature for binary numeric operator __add__" } }; { { def __aenter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aenter__ is not supported by py_class! yet." } + $crate::py_error! { "__aenter__ is not supported by py_class! yet." } }; { { def __aexit__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aexit__ is not supported by py_class! yet." } + $crate::py_error! { "__aexit__ is not supported by py_class! yet." } }; { { def __aiter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aiter__ is not supported by py_class! yet." } + $crate::py_error! { "__aiter__ is not supported by py_class! yet." } }; { { def __and__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -446,30 +446,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_and: py_class_binary_numeric_slot!($class::__and__), + nb_and: $crate::py_class_binary_numeric_slot!($class::__and__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __and__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __and__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __and__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __and__" } + $crate::py_error! { "Invalid signature for binary numeric operator __and__" } }; { { def __await__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__await__ is not supported by py_class! yet." } + $crate::py_error! { "__await__ is not supported by py_class! yet." } }; { { def __bool__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -480,26 +480,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_nonzero: py_class_unary_slot!($class::__bool__, $crate::_detail::libc::c_int, $crate::py_class::slots::BoolConverter), + nb_nonzero: $crate::py_class_unary_slot!($class::__bool__, $crate::_detail::libc::c_int, $crate::py_class::slots::BoolConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __bool__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __bool__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __bool__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __bool__" } + $crate::py_error! { "Invalid signature for operator __bool__" } }; { { def __call__ (&$slf:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -509,19 +509,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_call: py_class_call_slot!{$class::__call__ []}, + tp_call: $crate::py_class_call_slot!{$class::__call__ []}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __call__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __call__(&$slf,) $res_type; { $($body)* } [] } } $members }}; @@ -533,19 +533,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_call: py_argparse_parse_plist_impl!{py_class_call_slot {$class::__call__} [] ($($p)+,)}, + tp_call: $crate::py_argparse_parse_plist_impl!{py_class_call_slot {$class::__call__} [] ($($p)+,)}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, __call__(&$slf,) $res_type; { $($body)* } } [] ($($p)+,) } @@ -554,15 +554,15 @@ macro_rules! py_class_impl { }}; { { def __cmp__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__cmp__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__cmp__ is not supported by py_class! use __richcmp__ instead." } }; { { def __coerce__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__coerce__ is not supported by py_class! yet." } + $crate::py_error! { "__coerce__ is not supported by py_class! yet." } }; { { def __complex__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__complex__ is not supported by py_class! yet." } + $crate::py_error! { "__complex__ is not supported by py_class! yet." } }; { { def __contains__(&$slf:ident, $item:ident : $item_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -573,38 +573,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number /* as_sequence */ [ $( $sq_slot_name : $sq_slot_value, )* - sq_contains: py_class_contains_slot!($class::__contains__, $item_type), + sq_contains: $crate::py_class_contains_slot!($class::__contains__, $item_type), ] $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __contains__(&$slf,) $res_type; { $($body)* } [{ $item : $item_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __contains__(&$slf,) $res_type; { $($body)* } [{ $item : $item_type = {} }] } } $members }}; { { def __contains__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __contains__" } + $crate::py_error! { "Invalid signature for operator __contains__" } }; { { def __del__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__del__ is not supported by py_class!; Use a data member with a Drop impl instead." } + $crate::py_error! { "__del__ is not supported by py_class!; Use a data member with a Drop impl instead." } }; { { def __delattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__delattr__ is not supported by py_class! yet." } + $crate::py_error! { "__delattr__ is not supported by py_class! yet." } }; { { def __delete__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__delete__ is not supported by py_class! yet." } + $crate::py_error! { "__delete__ is not supported by py_class! yet." } }; { { def __delitem__(&$slf:ident, $key:ident : $key_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -617,65 +617,65 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number $as_sequence $as_mapping /* setdelitem */ [ sdi_setitem: $sdi_setitem_slot_value, - sdi_delitem: { py_class_binary_slot!($class::__delitem__, $key_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, + sdi_delitem: { $crate::py_class_binary_slot!($class::__delitem__, $key_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, ] } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __delitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __delitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } } $members }}; { { def __delitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __delitem__" } + $crate::py_error! { "Invalid signature for operator __delitem__" } }; { { def __dir__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__dir__ is not supported by py_class! yet." } + $crate::py_error! { "__dir__ is not supported by py_class! yet." } }; { { def __div__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__div__ is not supported by py_class! yet." } + $crate::py_error! { "__div__ is not supported by py_class! yet." } }; { { def __divmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__divmod__ is not supported by py_class! yet." } + $crate::py_error! { "__divmod__ is not supported by py_class! yet." } }; { { def __eq__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__eq__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__eq__ is not supported by py_class! use __richcmp__ instead." } }; { { def __float__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__float__ is not supported by py_class! yet." } + $crate::py_error! { "__float__ is not supported by py_class! yet." } }; { { def __floordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__floordiv__ is not supported by py_class! yet." } + $crate::py_error! { "__floordiv__ is not supported by py_class! yet." } }; { { def __ge__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ge__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__ge__ is not supported by py_class! use __richcmp__ instead." } }; { { def __get__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__get__ is not supported by py_class! yet." } + $crate::py_error! { "__get__ is not supported by py_class! yet." } }; { { def __getattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__getattr__ is not supported by py_class! yet." } + $crate::py_error! { "__getattr__ is not supported by py_class! yet." } }; { { def __getattribute__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__getattribute__ is not supported by py_class! yet." } + $crate::py_error! { "__getattribute__ is not supported by py_class! yet." } }; { { def __getitem__(&$slf:ident, $key:ident : $key_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -687,7 +687,7 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { @@ -698,23 +698,23 @@ macro_rules! py_class_impl { ] /* as_mapping */ [ $( $mp_slot_name : $mp_slot_value, )* - mp_subscript: py_class_binary_slot!($class::__getitem__, $key_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + mp_subscript: $crate::py_class_binary_slot!($class::__getitem__, $key_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __getitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __getitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } } $members }}; { { def __getitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __getitem__" } + $crate::py_error! { "Invalid signature for operator __getitem__" } }; { { def __gt__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__gt__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__gt__ is not supported by py_class! use __richcmp__ instead." } }; { { def __hash__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -724,25 +724,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_hash: py_class_unary_slot!($class::__hash__, $crate::Py_hash_t, $crate::py_class::slots::HashConverter), + tp_hash: $crate::py_class_unary_slot!($class::__hash__, $crate::Py_hash_t, $crate::py_class::slots::HashConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __hash__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __hash__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __hash__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __hash__" } + $crate::py_error! { "Invalid signature for operator __hash__" } }; { { def __iadd__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -753,26 +753,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_add: py_class_binary_slot!($class::__iadd__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_add: $crate::py_class_binary_slot!($class::__iadd__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iadd__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __iadd__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __iadd__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iadd__" } + $crate::py_error! { "Invalid signature for operator __iadd__" } }; { { def __iand__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -783,30 +783,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_and: py_class_binary_slot!($class::__iand__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_and: $crate::py_class_binary_slot!($class::__iand__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iand__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __iand__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __iand__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iand__" } + $crate::py_error! { "Invalid signature for operator __iand__" } }; { { def __idiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__idiv__ is not supported by py_class! yet." } + $crate::py_error! { "__idiv__ is not supported by py_class! yet." } }; { { def __ifloordiv__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -817,26 +817,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_floor_divide: py_class_binary_slot!($class::__ifloordiv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_floor_divide: $crate::py_class_binary_slot!($class::__ifloordiv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ifloordiv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ifloordiv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ifloordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ifloordiv__" } + $crate::py_error! { "Invalid signature for operator __ifloordiv__" } }; { { def __ilshift__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -847,26 +847,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_lshift: py_class_binary_slot!($class::__ilshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_lshift: $crate::py_class_binary_slot!($class::__ilshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ilshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ilshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ilshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ilshift__" } + $crate::py_error! { "Invalid signature for operator __ilshift__" } }; { { def __imatmul__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -877,26 +877,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_matrix_multiply: py_class_binary_slot!($class::__imatmul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_matrix_multiply: $crate::py_class_binary_slot!($class::__imatmul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imatmul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imatmul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imatmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imatmul__" } + $crate::py_error! { "Invalid signature for operator __imatmul__" } }; { { def __imod__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -907,26 +907,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_remainder: py_class_binary_slot!($class::__imod__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_remainder: $crate::py_class_binary_slot!($class::__imod__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imod__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imod__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imod__" } + $crate::py_error! { "Invalid signature for operator __imod__" } }; { { def __imul__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -937,42 +937,42 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_multiply: py_class_binary_slot!($class::__imul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_multiply: $crate::py_class_binary_slot!($class::__imul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imul__" } + $crate::py_error! { "Invalid signature for operator __imul__" } }; { { def __index__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__index__ is not supported by py_class! yet." } + $crate::py_error! { "__index__ is not supported by py_class! yet." } }; { { def __init__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__init__ is not supported by py_class!; use __new__ instead." } + $crate::py_error! { "__init__ is not supported by py_class!; use __new__ instead." } }; { { def __instancecheck__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__instancecheck__ is not supported by py_class! yet." } + $crate::py_error! { "__instancecheck__ is not supported by py_class! yet." } }; { { def __int__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__int__ is not supported by py_class! yet." } + $crate::py_error! { "__int__ is not supported by py_class! yet." } }; { { def __invert__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -983,26 +983,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_invert: py_class_unary_slot!($class::__invert__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_invert: $crate::py_class_unary_slot!($class::__invert__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __invert__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __invert__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __invert__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __invert__" } + $crate::py_error! { "Invalid signature for operator __invert__" } }; { { def __ior__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1013,30 +1013,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_or: py_class_binary_slot!($class::__ior__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_or: $crate::py_class_binary_slot!($class::__ior__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ior__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ior__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ior__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ior__" } + $crate::py_error! { "Invalid signature for operator __ior__" } }; { { def __ipow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ipow__ is not supported by py_class! yet." } + $crate::py_error! { "__ipow__ is not supported by py_class! yet." } }; { { def __irshift__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1047,26 +1047,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_rshift: py_class_binary_slot!($class::__irshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_rshift: $crate::py_class_binary_slot!($class::__irshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __irshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __irshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __irshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __irshift__" } + $crate::py_error! { "Invalid signature for operator __irshift__" } }; { { def __isub__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1077,26 +1077,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_subtract: py_class_binary_slot!($class::__isub__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_subtract: $crate::py_class_binary_slot!($class::__isub__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __isub__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __isub__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __isub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __isub__" } + $crate::py_error! { "Invalid signature for operator __isub__" } }; { { def __iter__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1106,25 +1106,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_iter: py_class_unary_slot!($class::__iter__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + tp_iter: $crate::py_class_unary_slot!($class::__iter__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iter__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __iter__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __iter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iter__" } + $crate::py_error! { "Invalid signature for operator __iter__" } }; { { def __itruediv__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1135,26 +1135,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_true_divide: py_class_binary_slot!($class::__itruediv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_true_divide: $crate::py_class_binary_slot!($class::__itruediv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __itruediv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __itruediv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __itruediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __itruediv__" } + $crate::py_error! { "Invalid signature for operator __itruediv__" } }; { { def __ixor__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1165,30 +1165,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_xor: py_class_binary_slot!($class::__ixor__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_xor: $crate::py_class_binary_slot!($class::__ixor__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ixor__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ixor__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ixor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ixor__" } + $crate::py_error! { "Invalid signature for operator __ixor__" } }; { { def __le__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__le__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__le__ is not supported by py_class! use __richcmp__ instead." } }; { { def __len__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1200,14 +1200,14 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number /* as_sequence */ [ $( $sq_slot_name : $sq_slot_value, )* - sq_length: py_class_unary_slot!($class::__len__, $crate::_detail::ffi::Py_ssize_t, $crate::py_class::slots::LenResultConverter), + sq_length: $crate::py_class_unary_slot!($class::__len__, $crate::_detail::ffi::Py_ssize_t, $crate::py_class::slots::LenResultConverter), ] /* as_mapping */ [ $( $mp_slot_name : $mp_slot_value, )* @@ -1217,17 +1217,17 @@ macro_rules! py_class_impl { } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __len__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __len__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __len__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __len__" } + $crate::py_error! { "Invalid signature for operator __len__" } }; { { def __long__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__long__ is not supported by py_class! yet." } + $crate::py_error! { "__long__ is not supported by py_class! yet." } }; { { def __lshift__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1238,38 +1238,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_lshift: py_class_binary_numeric_slot!($class::__lshift__), + nb_lshift: $crate::py_class_binary_numeric_slot!($class::__lshift__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __lshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __lshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __lshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __lshift__" } + $crate::py_error! { "Invalid signature for binary numeric operator __lshift__" } }; { { def __lt__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__lt__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__lt__ is not supported by py_class! use __richcmp__ instead." } }; { { def __matmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__matmul__ is not supported by py_class! yet." } + $crate::py_error! { "__matmul__ is not supported by py_class! yet." } }; { { def __mod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__mod__ is not supported by py_class! yet." } + $crate::py_error! { "__mod__ is not supported by py_class! yet." } }; { { def __mul__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1280,30 +1280,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_multiply: py_class_binary_numeric_slot!($class::__mul__), + nb_multiply: $crate::py_class_binary_numeric_slot!($class::__mul__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __mul__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __mul__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __mul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __mul__" } + $crate::py_error! { "Invalid signature for binary numeric operator __mul__" } }; { { def __ne__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ne__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__ne__ is not supported by py_class! use __richcmp__ instead." } }; { { def __neg__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1314,26 +1314,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_negative: py_class_unary_slot!($class::__neg__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_negative: $crate::py_class_unary_slot!($class::__neg__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __neg__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __neg__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __neg__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __neg__" } + $crate::py_error! { "Invalid signature for operator __neg__" } }; { { def __new__ ($cls:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1343,19 +1343,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_new: py_class_wrap_newfunc!{$class::__new__ []}, + tp_new: $crate::py_class_wrap_newfunc!{$class::__new__ []}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py,__new__($cls: &$crate::PyType,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py,__new__($cls: &$crate::PyType,) $res_type; { $($body)* } [] } } $members }}; @@ -1367,19 +1367,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_new: py_argparse_parse_plist_impl!{py_class_wrap_newfunc {$class::__new__} [] ($($p)+,)}, + tp_new: $crate::py_argparse_parse_plist_impl!{py_class_wrap_newfunc {$class::__new__} [] ($($p)+,)}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, __new__($cls: &$crate::PyType,) $res_type; { $($body)* } } [] ($($p)+,) } @@ -1394,29 +1394,29 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_iternext: py_class_unary_slot!($class::__next__, *mut $crate::_detail::ffi::PyObject, $crate::py_class::slots::IterNextResultConverter), + tp_iternext: $crate::py_class_unary_slot!($class::__next__, *mut $crate::_detail::ffi::PyObject, $crate::py_class::slots::IterNextResultConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __next__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __next__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __next__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __next__" } + $crate::py_error! { "Invalid signature for operator __next__" } }; { { def __nonzero__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__nonzero__ is not supported by py_class!; use the Python 3 spelling __bool__ instead." } + $crate::py_error! { "__nonzero__ is not supported by py_class!; use the Python 3 spelling __bool__ instead." } }; { { def __or__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1427,26 +1427,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_or: py_class_binary_numeric_slot!($class::__or__), + nb_or: $crate::py_class_binary_numeric_slot!($class::__or__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __or__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __or__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __or__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __or__" } + $crate::py_error! { "Invalid signature for binary numeric operator __or__" } }; { { def __pos__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1457,46 +1457,46 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_positive: py_class_unary_slot!($class::__pos__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_positive: $crate::py_class_unary_slot!($class::__pos__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __pos__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __pos__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __pos__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __pos__" } + $crate::py_error! { "Invalid signature for operator __pos__" } }; { { def __pow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__pow__ is not supported by py_class! yet." } + $crate::py_error! { "__pow__ is not supported by py_class! yet." } }; { { def __radd__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __radd__ is not supported by py_class! Use __add__ instead!" } + $crate::py_error! { "Reflected numeric operator __radd__ is not supported by py_class! Use __add__ instead!" } }; { { def __rand__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rand__ is not supported by py_class! Use __and__ instead!" } + $crate::py_error! { "Reflected numeric operator __rand__ is not supported by py_class! Use __and__ instead!" } }; { { def __rdiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rdiv__ is not supported by py_class! Use __div__ instead!" } + $crate::py_error! { "Reflected numeric operator __rdiv__ is not supported by py_class! Use __div__ instead!" } }; { { def __rdivmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rdivmod__ is not supported by py_class! Use __divmod__ instead!" } + $crate::py_error! { "Reflected numeric operator __rdivmod__ is not supported by py_class! Use __divmod__ instead!" } }; { { def __repr__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1506,29 +1506,29 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), + tp_repr: $crate::py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __repr__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __repr__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __repr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __repr__" } + $crate::py_error! { "Invalid signature for operator __repr__" } }; { { def __rfloordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rfloordiv__ is not supported by py_class! Use __floordiv__ instead!" } + $crate::py_error! { "Reflected numeric operator __rfloordiv__ is not supported by py_class! Use __floordiv__ instead!" } }; { { def __richcmp__(&$slf:ident, $other:ident : $other_type:ty, $op:ident : $op_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1538,57 +1538,57 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_richcompare: py_class_richcompare_slot!($class::__richcmp__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + tp_richcompare: $crate::py_class_richcompare_slot!($class::__richcmp__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __richcmp__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} } { $op : $op_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __richcmp__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} } { $op : $op_type = {} }] } } $members }}; { { def __richcmp__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __richcmp__" } + $crate::py_error! { "Invalid signature for operator __richcmp__" } }; { { def __rlshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rlshift__ is not supported by py_class! Use __lshift__ instead!" } + $crate::py_error! { "Reflected numeric operator __rlshift__ is not supported by py_class! Use __lshift__ instead!" } }; { { def __rmatmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmatmul__ is not supported by py_class! Use __matmul__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmatmul__ is not supported by py_class! Use __matmul__ instead!" } }; { { def __rmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmod__ is not supported by py_class! Use __mod__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmod__ is not supported by py_class! Use __mod__ instead!" } }; { { def __rmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmul__ is not supported by py_class! Use __mul__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmul__ is not supported by py_class! Use __mul__ instead!" } }; { { def __ror__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __ror__ is not supported by py_class! Use __or__ instead!" } + $crate::py_error! { "Reflected numeric operator __ror__ is not supported by py_class! Use __or__ instead!" } }; { { def __round__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__round__ is not supported by py_class! yet." } + $crate::py_error! { "__round__ is not supported by py_class! yet." } }; { { def __rpow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rpow__ is not supported by py_class! Use __pow__ instead!" } + $crate::py_error! { "Reflected numeric operator __rpow__ is not supported by py_class! Use __pow__ instead!" } }; { { def __rrshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rrshift__ is not supported by py_class! Use __rshift__ instead!" } + $crate::py_error! { "Reflected numeric operator __rrshift__ is not supported by py_class! Use __rshift__ instead!" } }; { { def __rshift__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1599,46 +1599,46 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_rshift: py_class_binary_numeric_slot!($class::__rshift__), + nb_rshift: $crate::py_class_binary_numeric_slot!($class::__rshift__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __rshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __rshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __rshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __rshift__" } + $crate::py_error! { "Invalid signature for binary numeric operator __rshift__" } }; { { def __rsub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rsub__ is not supported by py_class! Use __sub__ instead!" } + $crate::py_error! { "Reflected numeric operator __rsub__ is not supported by py_class! Use __sub__ instead!" } }; { { def __rtruediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rtruediv__ is not supported by py_class! Use __truediv__ instead!" } + $crate::py_error! { "Reflected numeric operator __rtruediv__ is not supported by py_class! Use __truediv__ instead!" } }; { { def __rxor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rxor__ is not supported by py_class! Use __xor__ instead!" } + $crate::py_error! { "Reflected numeric operator __rxor__ is not supported by py_class! Use __xor__ instead!" } }; { { def __set__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__set__ is not supported by py_class! yet." } + $crate::py_error! { "__set__ is not supported by py_class! yet." } }; { { def __setattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__setattr__ is not supported by py_class! yet." } + $crate::py_error! { "__setattr__ is not supported by py_class! yet." } }; { { def __setitem__(&$slf:ident, $key:ident : $key_type:ty, $value:ident : $value_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1651,25 +1651,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number $as_sequence $as_mapping /* setdelitem */ [ - sdi_setitem: { py_class_ternary_slot!($class::__setitem__, $key_type, $value_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, + sdi_setitem: { $crate::py_class_ternary_slot!($class::__setitem__, $key_type, $value_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, sdi_delitem: $sdi_delitem_slot_value, ] } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __setitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} } { $value : $value_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __setitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} } { $value : $value_type = {} }] } } $members }}; { { def __setitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __setitem__" } + $crate::py_error! { "Invalid signature for operator __setitem__" } }; { { def __str__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1679,25 +1679,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), + tp_str: $crate::py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __str__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __str__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __str__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __str__" } + $crate::py_error! { "Invalid signature for operator __str__" } }; { { def __sub__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1708,34 +1708,34 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_subtract: py_class_binary_numeric_slot!($class::__sub__), + nb_subtract: $crate::py_class_binary_numeric_slot!($class::__sub__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __sub__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __sub__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __sub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __sub__" } + $crate::py_error! { "Invalid signature for binary numeric operator __sub__" } }; { { def __subclasscheck__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__subclasscheck__ is not supported by py_class! yet." } + $crate::py_error! { "__subclasscheck__ is not supported by py_class! yet." } }; { { def __truediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__truediv__ is not supported by py_class! yet." } + $crate::py_error! { "__truediv__ is not supported by py_class! yet." } }; { { def __xor__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1746,107 +1746,107 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_xor: py_class_binary_numeric_slot!($class::__xor__), + nb_xor: $crate::py_class_binary_numeric_slot!($class::__xor__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __xor__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __xor__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __xor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __xor__" } + $crate::py_error! { "Invalid signature for binary numeric operator __xor__" } }; { { $(#[doc=$doc:expr])* def $name:ident (&$slf:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, $name(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, $name(&$slf,) $res_type; { $($body)* } [] } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_class_instance_method!{$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) } []}; + $name = $crate::py_class_instance_method!{$py, $class::$name, { concat!($($doc, "\n"),*) } []}; } }}; { { $(#[doc=$doc:expr])* def $name:ident (&$slf:ident, $($p:tt)+) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, $name(&$slf,) $res_type; { $($body)* } } [] ($($p)+,) } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_argparse_parse_plist_impl!{py_class_instance_method {$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) }} [] ($($p)+,)}; + $name = $crate::py_argparse_parse_plist_impl!{py_class_instance_method {$py, $class::$name, { concat!($($doc, "\n"),*) }} [] ($($p)+,)}; } }}; { { $(#[doc=$doc:expr])*@classmethod def $name:ident ($cls:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py,$name($cls: &$crate::PyType,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py,$name($cls: &$crate::PyType,) $res_type; { $($body)* } [] } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_class_class_method!{$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) } []}; + $name = $crate::py_class_class_method!{$py, $class::$name, { concat!($($doc, "\n"),*) } []}; } }}; { { $(#[doc=$doc:expr])*@classmethod def $name:ident ($cls:ident, $($p:tt)+) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, $name($cls: &$crate::PyType,) $res_type; { $($body)* } } [] ($($p)+,) } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_argparse_parse_plist_impl!{py_class_class_method {$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) }} [] ($($p)+,)}; + $name = $crate::py_argparse_parse_plist_impl!{py_class_class_method {$py, $class::$name, { concat!($($doc, "\n"),*) }} [] ($($p)+,)}; } }}; { { $(#[doc=$doc:expr])* @staticmethod def $name:ident ($($p:tt)*) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_impl_item { $class, $py, $name() $res_type; { $($body)* } } ($($p)*) } @@ -1854,9 +1854,9 @@ macro_rules! py_class_impl { /* members: */ { $( $member_name = $member_expr; )* $name = - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_static_method {$py, $class::$name, { - _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) + concat!($($doc, "\n"),*) } } ($($p)*) } @@ -1866,7 +1866,7 @@ macro_rules! py_class_impl { { { static $name:ident = $init:expr; $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt $impls:tt { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots $impls /* members: */ { @@ -1877,27 +1877,3 @@ macro_rules! py_class_impl { } -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__assert { - ($($inner:tt)*) => { - assert! { $($inner)* } - } -} - diff --git a/src/py_class/py_class_impl3.rs b/src/py_class/py_class_impl3.rs index ae275fde..1dcb3cc7 100644 --- a/src/py_class/py_class_impl3.rs +++ b/src/py_class/py_class_impl3.rs @@ -23,7 +23,7 @@ // DO NOT MODIFY !! // !!!!!!!!!!!!!!!!!!!!!!!!!!! -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_impl { // TT muncher macro. Results are accumulated in $info $slots $impls and $members. @@ -41,12 +41,12 @@ macro_rules! py_class_impl { } $slots:tt { $( $imp:item )* } $members:tt } => { - py_coerce_item! { + $crate::py_coerce_item! { $($class_visibility)* struct $class { _unsafe_inner: $crate::PyObject } } - py_impl_to_py_object_for_python_object!($class); - py_impl_from_py_object_for_python_object!($class); + $crate::py_impl_to_py_object_for_python_object!($class); + $crate::py_impl_from_py_object_for_python_object!($class); impl $crate::PythonObject for $class { #[inline] @@ -82,7 +82,7 @@ macro_rules! py_class_impl { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } @@ -95,14 +95,14 @@ macro_rules! py_class_impl { } else { Err($crate::PythonObjectDowncastError::new( py, - _cpython__py_class__py_class_impl__stringify!($class), + stringify!($class), obj.get_type(py), )) } } } - py_coerce_item! { + $crate::py_coerce_item! { impl $crate::py_class::BaseObject for $class { type InitType = ( $( $init_ty, )* ); @@ -129,7 +129,7 @@ macro_rules! py_class_impl { } } $($imp)* - py_coerce_item! { + $crate::py_coerce_item! { impl $class { fn create_instance(py: $crate::Python $( , $data_name : $init_ty )* ) -> $crate::PyResult<$class> { let obj = unsafe { @@ -141,7 +141,7 @@ macro_rules! py_class_impl { // hide statics in create_instance to avoid name conflicts static mut TYPE_OBJECT : $crate::_detail::ffi::PyTypeObject - = py_class_type_object_static_init!($class, $gc, $slots); + = $crate::py_class_type_object_static_init!($class, $gc, $slots); static mut INIT_ACTIVE: bool = false; // trait implementations that need direct access to TYPE_OBJECT @@ -153,7 +153,7 @@ macro_rules! py_class_impl { } else { // automatically initialize the class on-demand <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, None) - .expect(_cpython__py_class__py_class_impl__concat!("An error occurred while initializing class ", _cpython__py_class__py_class_impl__stringify!($class))) + .expect(concat!("An error occurred while initializing class ", stringify!($class))) } } } @@ -165,9 +165,9 @@ macro_rules! py_class_impl { if $crate::py_class::is_ready(py, &TYPE_OBJECT) { return Ok($crate::PyType::from_type_ptr(py, &mut TYPE_OBJECT)); } - _cpython__py_class__py_class_impl__assert!(!INIT_ACTIVE, - _cpython__py_class__py_class_impl__concat!("Reentrancy detected: already initializing class ", - _cpython__py_class__py_class_impl__stringify!($class))); + assert!(!INIT_ACTIVE, + concat!("Reentrancy detected: already initializing class ", + stringify!($class))); INIT_ACTIVE = true; let res = init(py, module_name); INIT_ACTIVE = false; @@ -177,13 +177,13 @@ macro_rules! py_class_impl { fn add_to_module(py: $crate::Python, module: &$crate::PyModule) -> $crate::PyResult<()> { let ty = <$class as $crate::py_class::PythonObjectFromPyClassMacro>::initialize(py, module.name(py).ok())?; - module.add(py, _cpython__py_class__py_class_impl__stringify!($class), ty) + module.add(py, stringify!($class), ty) } } fn init($py: $crate::Python, module_name: Option<&str>) -> $crate::PyResult<$crate::PyType> { - py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); - py_class_init_members!($class, $py, TYPE_OBJECT, $members); + $crate::py_class_type_object_dynamic_init!($class, $py, TYPE_OBJECT, module_name, $slots); + $crate::py_class_init_members!($class, $py, TYPE_OBJECT, $members); unsafe { if $crate::_detail::ffi::PyType_Ready(&mut TYPE_OBJECT) == 0 { Ok($crate::PyType::from_type_ptr($py, &mut TYPE_OBJECT)) @@ -209,7 +209,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -257,7 +257,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -309,7 +309,7 @@ macro_rules! py_class_impl { $slots:tt { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py /* info: */ { @@ -325,7 +325,7 @@ macro_rules! py_class_impl { $slots /* impl: */ { $($imp)* - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __traverse__(&$slf, $py: $crate::Python, @@ -345,19 +345,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_clear: py_class_tp_clear!($class), + tp_clear: $crate::py_class_tp_clear!($class), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_coerce_item!{ + $crate::py_coerce_item!{ impl $class { fn __clear__(&$slf, $py: $crate::Python) $body } @@ -374,26 +374,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_absolute: py_class_unary_slot!($class::__abs__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_absolute: $crate::py_class_unary_slot!($class::__abs__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __abs__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __abs__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __abs__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __abs__" } + $crate::py_error! { "Invalid signature for operator __abs__" } }; { { def __add__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -404,38 +404,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_add: py_class_binary_numeric_slot!($class::__add__), + nb_add: $crate::py_class_binary_numeric_slot!($class::__add__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __add__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __add__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __add__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __add__" } + $crate::py_error! { "Invalid signature for binary numeric operator __add__" } }; { { def __aenter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aenter__ is not supported by py_class! yet." } + $crate::py_error! { "__aenter__ is not supported by py_class! yet." } }; { { def __aexit__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aexit__ is not supported by py_class! yet." } + $crate::py_error! { "__aexit__ is not supported by py_class! yet." } }; { { def __aiter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__aiter__ is not supported by py_class! yet." } + $crate::py_error! { "__aiter__ is not supported by py_class! yet." } }; { { def __and__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -446,30 +446,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_and: py_class_binary_numeric_slot!($class::__and__), + nb_and: $crate::py_class_binary_numeric_slot!($class::__and__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __and__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __and__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __and__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __and__" } + $crate::py_error! { "Invalid signature for binary numeric operator __and__" } }; { { def __await__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__await__ is not supported by py_class! yet." } + $crate::py_error! { "__await__ is not supported by py_class! yet." } }; { { def __bool__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -480,26 +480,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_bool: py_class_unary_slot!($class::__bool__, $crate::_detail::libc::c_int, $crate::py_class::slots::BoolConverter), + nb_bool: $crate::py_class_unary_slot!($class::__bool__, $crate::_detail::libc::c_int, $crate::py_class::slots::BoolConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __bool__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __bool__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __bool__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __bool__" } + $crate::py_error! { "Invalid signature for operator __bool__" } }; { { def __call__ (&$slf:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -509,19 +509,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_call: py_class_call_slot!{$class::__call__ []}, + tp_call: $crate::py_class_call_slot!{$class::__call__ []}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __call__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __call__(&$slf,) $res_type; { $($body)* } [] } } $members }}; @@ -533,19 +533,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_call: py_argparse_parse_plist_impl!{py_class_call_slot {$class::__call__} [] ($($p)+,)}, + tp_call: $crate::py_argparse_parse_plist_impl!{py_class_call_slot {$class::__call__} [] ($($p)+,)}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, __call__(&$slf,) $res_type; { $($body)* } } [] ($($p)+,) } @@ -554,15 +554,15 @@ macro_rules! py_class_impl { }}; { { def __cmp__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__cmp__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__cmp__ is not supported by py_class! use __richcmp__ instead." } }; { { def __coerce__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__coerce__ is not supported by py_class! yet." } + $crate::py_error! { "__coerce__ is not supported by py_class! yet." } }; { { def __complex__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__complex__ is not supported by py_class! yet." } + $crate::py_error! { "__complex__ is not supported by py_class! yet." } }; { { def __contains__(&$slf:ident, $item:ident : $item_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -573,38 +573,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number /* as_sequence */ [ $( $sq_slot_name : $sq_slot_value, )* - sq_contains: py_class_contains_slot!($class::__contains__, $item_type), + sq_contains: $crate::py_class_contains_slot!($class::__contains__, $item_type), ] $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __contains__(&$slf,) $res_type; { $($body)* } [{ $item : $item_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __contains__(&$slf,) $res_type; { $($body)* } [{ $item : $item_type = {} }] } } $members }}; { { def __contains__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __contains__" } + $crate::py_error! { "Invalid signature for operator __contains__" } }; { { def __del__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__del__ is not supported by py_class!; Use a data member with a Drop impl instead." } + $crate::py_error! { "__del__ is not supported by py_class!; Use a data member with a Drop impl instead." } }; { { def __delattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__delattr__ is not supported by py_class! yet." } + $crate::py_error! { "__delattr__ is not supported by py_class! yet." } }; { { def __delete__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__delete__ is not supported by py_class! yet." } + $crate::py_error! { "__delete__ is not supported by py_class! yet." } }; { { def __delitem__(&$slf:ident, $key:ident : $key_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -617,65 +617,65 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number $as_sequence $as_mapping /* setdelitem */ [ sdi_setitem: $sdi_setitem_slot_value, - sdi_delitem: { py_class_binary_slot!($class::__delitem__, $key_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, + sdi_delitem: { $crate::py_class_binary_slot!($class::__delitem__, $key_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, ] } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __delitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __delitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } } $members }}; { { def __delitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __delitem__" } + $crate::py_error! { "Invalid signature for operator __delitem__" } }; { { def __dir__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__dir__ is not supported by py_class! yet." } + $crate::py_error! { "__dir__ is not supported by py_class! yet." } }; { { def __div__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__div__ is not supported by py_class! yet." } + $crate::py_error! { "__div__ is not supported by py_class! yet." } }; { { def __divmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__divmod__ is not supported by py_class! yet." } + $crate::py_error! { "__divmod__ is not supported by py_class! yet." } }; { { def __eq__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__eq__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__eq__ is not supported by py_class! use __richcmp__ instead." } }; { { def __float__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__float__ is not supported by py_class! yet." } + $crate::py_error! { "__float__ is not supported by py_class! yet." } }; { { def __floordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__floordiv__ is not supported by py_class! yet." } + $crate::py_error! { "__floordiv__ is not supported by py_class! yet." } }; { { def __ge__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ge__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__ge__ is not supported by py_class! use __richcmp__ instead." } }; { { def __get__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__get__ is not supported by py_class! yet." } + $crate::py_error! { "__get__ is not supported by py_class! yet." } }; { { def __getattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__getattr__ is not supported by py_class! yet." } + $crate::py_error! { "__getattr__ is not supported by py_class! yet." } }; { { def __getattribute__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__getattribute__ is not supported by py_class! yet." } + $crate::py_error! { "__getattribute__ is not supported by py_class! yet." } }; { { def __getitem__(&$slf:ident, $key:ident : $key_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -687,7 +687,7 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { @@ -698,23 +698,23 @@ macro_rules! py_class_impl { ] /* as_mapping */ [ $( $mp_slot_name : $mp_slot_value, )* - mp_subscript: py_class_binary_slot!($class::__getitem__, $key_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + mp_subscript: $crate::py_class_binary_slot!($class::__getitem__, $key_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __getitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __getitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} }] } } $members }}; { { def __getitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __getitem__" } + $crate::py_error! { "Invalid signature for operator __getitem__" } }; { { def __gt__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__gt__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__gt__ is not supported by py_class! use __richcmp__ instead." } }; { { def __hash__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -724,25 +724,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_hash: py_class_unary_slot!($class::__hash__, $crate::Py_hash_t, $crate::py_class::slots::HashConverter), + tp_hash: $crate::py_class_unary_slot!($class::__hash__, $crate::Py_hash_t, $crate::py_class::slots::HashConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __hash__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __hash__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __hash__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __hash__" } + $crate::py_error! { "Invalid signature for operator __hash__" } }; { { def __iadd__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -753,26 +753,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_add: py_class_binary_slot!($class::__iadd__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_add: $crate::py_class_binary_slot!($class::__iadd__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iadd__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __iadd__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __iadd__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iadd__" } + $crate::py_error! { "Invalid signature for operator __iadd__" } }; { { def __iand__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -783,30 +783,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_and: py_class_binary_slot!($class::__iand__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_and: $crate::py_class_binary_slot!($class::__iand__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iand__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __iand__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __iand__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iand__" } + $crate::py_error! { "Invalid signature for operator __iand__" } }; { { def __idiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__idiv__ is not supported by py_class! yet." } + $crate::py_error! { "__idiv__ is not supported by py_class! yet." } }; { { def __ifloordiv__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -817,26 +817,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_floor_divide: py_class_binary_slot!($class::__ifloordiv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_floor_divide: $crate::py_class_binary_slot!($class::__ifloordiv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ifloordiv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ifloordiv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ifloordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ifloordiv__" } + $crate::py_error! { "Invalid signature for operator __ifloordiv__" } }; { { def __ilshift__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -847,26 +847,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_lshift: py_class_binary_slot!($class::__ilshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_lshift: $crate::py_class_binary_slot!($class::__ilshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ilshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ilshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ilshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ilshift__" } + $crate::py_error! { "Invalid signature for operator __ilshift__" } }; { { def __imatmul__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -877,26 +877,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_matrix_multiply: py_class_binary_slot!($class::__imatmul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_matrix_multiply: $crate::py_class_binary_slot!($class::__imatmul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imatmul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imatmul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imatmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imatmul__" } + $crate::py_error! { "Invalid signature for operator __imatmul__" } }; { { def __imod__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -907,26 +907,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_remainder: py_class_binary_slot!($class::__imod__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_remainder: $crate::py_class_binary_slot!($class::__imod__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imod__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imod__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imod__" } + $crate::py_error! { "Invalid signature for operator __imod__" } }; { { def __imul__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -937,42 +937,42 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_multiply: py_class_binary_slot!($class::__imul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_multiply: $crate::py_class_binary_slot!($class::__imul__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __imul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __imul__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __imul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __imul__" } + $crate::py_error! { "Invalid signature for operator __imul__" } }; { { def __index__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__index__ is not supported by py_class! yet." } + $crate::py_error! { "__index__ is not supported by py_class! yet." } }; { { def __init__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__init__ is not supported by py_class!; use __new__ instead." } + $crate::py_error! { "__init__ is not supported by py_class!; use __new__ instead." } }; { { def __instancecheck__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__instancecheck__ is not supported by py_class! yet." } + $crate::py_error! { "__instancecheck__ is not supported by py_class! yet." } }; { { def __int__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__int__ is not supported by py_class! yet." } + $crate::py_error! { "__int__ is not supported by py_class! yet." } }; { { def __invert__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -983,26 +983,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_invert: py_class_unary_slot!($class::__invert__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_invert: $crate::py_class_unary_slot!($class::__invert__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __invert__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __invert__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __invert__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __invert__" } + $crate::py_error! { "Invalid signature for operator __invert__" } }; { { def __ior__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1013,30 +1013,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_or: py_class_binary_slot!($class::__ior__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_or: $crate::py_class_binary_slot!($class::__ior__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ior__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ior__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ior__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ior__" } + $crate::py_error! { "Invalid signature for operator __ior__" } }; { { def __ipow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ipow__ is not supported by py_class! yet." } + $crate::py_error! { "__ipow__ is not supported by py_class! yet." } }; { { def __irshift__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1047,26 +1047,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_rshift: py_class_binary_slot!($class::__irshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_rshift: $crate::py_class_binary_slot!($class::__irshift__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __irshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __irshift__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __irshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __irshift__" } + $crate::py_error! { "Invalid signature for operator __irshift__" } }; { { def __isub__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1077,26 +1077,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_subtract: py_class_binary_slot!($class::__isub__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_subtract: $crate::py_class_binary_slot!($class::__isub__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __isub__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __isub__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __isub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __isub__" } + $crate::py_error! { "Invalid signature for operator __isub__" } }; { { def __iter__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1106,25 +1106,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_iter: py_class_unary_slot!($class::__iter__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + tp_iter: $crate::py_class_unary_slot!($class::__iter__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __iter__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __iter__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __iter__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __iter__" } + $crate::py_error! { "Invalid signature for operator __iter__" } }; { { def __itruediv__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1135,26 +1135,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_true_divide: py_class_binary_slot!($class::__itruediv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_true_divide: $crate::py_class_binary_slot!($class::__itruediv__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __itruediv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __itruediv__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __itruediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __itruediv__" } + $crate::py_error! { "Invalid signature for operator __itruediv__" } }; { { def __ixor__(&$slf:ident, $other:ident : $other_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1165,30 +1165,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_inplace_xor: py_class_binary_slot!($class::__ixor__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_inplace_xor: $crate::py_class_binary_slot!($class::__ixor__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __ixor__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __ixor__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} }] } } $members }}; { { def __ixor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __ixor__" } + $crate::py_error! { "Invalid signature for operator __ixor__" } }; { { def __le__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__le__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__le__ is not supported by py_class! use __richcmp__ instead." } }; { { def __len__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1200,14 +1200,14 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number /* as_sequence */ [ $( $sq_slot_name : $sq_slot_value, )* - sq_length: py_class_unary_slot!($class::__len__, $crate::_detail::ffi::Py_ssize_t, $crate::py_class::slots::LenResultConverter), + sq_length: $crate::py_class_unary_slot!($class::__len__, $crate::_detail::ffi::Py_ssize_t, $crate::py_class::slots::LenResultConverter), ] /* as_mapping */ [ $( $mp_slot_name : $mp_slot_value, )* @@ -1217,17 +1217,17 @@ macro_rules! py_class_impl { } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __len__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __len__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __len__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __len__" } + $crate::py_error! { "Invalid signature for operator __len__" } }; { { def __long__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__long__ is not supported by py_class! yet." } + $crate::py_error! { "__long__ is not supported by py_class! yet." } }; { { def __lshift__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1238,38 +1238,38 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_lshift: py_class_binary_numeric_slot!($class::__lshift__), + nb_lshift: $crate::py_class_binary_numeric_slot!($class::__lshift__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __lshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __lshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __lshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __lshift__" } + $crate::py_error! { "Invalid signature for binary numeric operator __lshift__" } }; { { def __lt__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__lt__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__lt__ is not supported by py_class! use __richcmp__ instead." } }; { { def __matmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__matmul__ is not supported by py_class! yet." } + $crate::py_error! { "__matmul__ is not supported by py_class! yet." } }; { { def __mod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__mod__ is not supported by py_class! yet." } + $crate::py_error! { "__mod__ is not supported by py_class! yet." } }; { { def __mul__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1280,30 +1280,30 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_multiply: py_class_binary_numeric_slot!($class::__mul__), + nb_multiply: $crate::py_class_binary_numeric_slot!($class::__mul__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __mul__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __mul__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __mul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __mul__" } + $crate::py_error! { "Invalid signature for binary numeric operator __mul__" } }; { { def __ne__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__ne__ is not supported by py_class! use __richcmp__ instead." } + $crate::py_error! { "__ne__ is not supported by py_class! use __richcmp__ instead." } }; { { def __neg__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1314,26 +1314,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_negative: py_class_unary_slot!($class::__neg__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_negative: $crate::py_class_unary_slot!($class::__neg__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __neg__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __neg__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __neg__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __neg__" } + $crate::py_error! { "Invalid signature for operator __neg__" } }; { { def __new__ ($cls:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1343,19 +1343,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_new: py_class_wrap_newfunc!{$class::__new__ []}, + tp_new: $crate::py_class_wrap_newfunc!{$class::__new__ []}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py,__new__($cls: &$crate::PyType,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py,__new__($cls: &$crate::PyType,) $res_type; { $($body)* } [] } } $members }}; @@ -1367,19 +1367,19 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_new: py_argparse_parse_plist_impl!{py_class_wrap_newfunc {$class::__new__} [] ($($p)+,)}, + tp_new: $crate::py_argparse_parse_plist_impl!{py_class_wrap_newfunc {$class::__new__} [] ($($p)+,)}, ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, __new__($cls: &$crate::PyType,) $res_type; { $($body)* } } [] ($($p)+,) } @@ -1394,29 +1394,29 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_iternext: py_class_unary_slot!($class::__next__, *mut $crate::_detail::ffi::PyObject, $crate::py_class::slots::IterNextResultConverter), + tp_iternext: $crate::py_class_unary_slot!($class::__next__, *mut $crate::_detail::ffi::PyObject, $crate::py_class::slots::IterNextResultConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __next__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __next__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __next__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __next__" } + $crate::py_error! { "Invalid signature for operator __next__" } }; { { def __nonzero__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__nonzero__ is not supported by py_class!; use the Python 3 spelling __bool__ instead." } + $crate::py_error! { "__nonzero__ is not supported by py_class!; use the Python 3 spelling __bool__ instead." } }; { { def __or__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1427,26 +1427,26 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_or: py_class_binary_numeric_slot!($class::__or__), + nb_or: $crate::py_class_binary_numeric_slot!($class::__or__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __or__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __or__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __or__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __or__" } + $crate::py_error! { "Invalid signature for binary numeric operator __or__" } }; { { def __pos__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1457,46 +1457,46 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_positive: py_class_unary_slot!($class::__pos__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + nb_positive: $crate::py_class_unary_slot!($class::__pos__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __pos__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __pos__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __pos__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __pos__" } + $crate::py_error! { "Invalid signature for operator __pos__" } }; { { def __pow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__pow__ is not supported by py_class! yet." } + $crate::py_error! { "__pow__ is not supported by py_class! yet." } }; { { def __radd__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __radd__ is not supported by py_class! Use __add__ instead!" } + $crate::py_error! { "Reflected numeric operator __radd__ is not supported by py_class! Use __add__ instead!" } }; { { def __rand__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rand__ is not supported by py_class! Use __and__ instead!" } + $crate::py_error! { "Reflected numeric operator __rand__ is not supported by py_class! Use __and__ instead!" } }; { { def __rdiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rdiv__ is not supported by py_class! Use __div__ instead!" } + $crate::py_error! { "Reflected numeric operator __rdiv__ is not supported by py_class! Use __div__ instead!" } }; { { def __rdivmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rdivmod__ is not supported by py_class! Use __divmod__ instead!" } + $crate::py_error! { "Reflected numeric operator __rdivmod__ is not supported by py_class! Use __divmod__ instead!" } }; { { def __repr__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1506,29 +1506,29 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_repr: py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), + tp_repr: $crate::py_class_unary_slot!($class::__repr__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __repr__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __repr__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __repr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __repr__" } + $crate::py_error! { "Invalid signature for operator __repr__" } }; { { def __rfloordiv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rfloordiv__ is not supported by py_class! Use __floordiv__ instead!" } + $crate::py_error! { "Reflected numeric operator __rfloordiv__ is not supported by py_class! Use __floordiv__ instead!" } }; { { def __richcmp__(&$slf:ident, $other:ident : $other_type:ty, $op:ident : $op_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1538,57 +1538,57 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_richcompare: py_class_richcompare_slot!($class::__richcmp__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), + tp_richcompare: $crate::py_class_richcompare_slot!($class::__richcmp__, $other_type, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PyObjectCallbackConverter), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __richcmp__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} } { $op : $op_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __richcmp__(&$slf,) $res_type; { $($body)* } [{ $other : $other_type = {} } { $op : $op_type = {} }] } } $members }}; { { def __richcmp__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __richcmp__" } + $crate::py_error! { "Invalid signature for operator __richcmp__" } }; { { def __rlshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rlshift__ is not supported by py_class! Use __lshift__ instead!" } + $crate::py_error! { "Reflected numeric operator __rlshift__ is not supported by py_class! Use __lshift__ instead!" } }; { { def __rmatmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmatmul__ is not supported by py_class! Use __matmul__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmatmul__ is not supported by py_class! Use __matmul__ instead!" } }; { { def __rmod__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmod__ is not supported by py_class! Use __mod__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmod__ is not supported by py_class! Use __mod__ instead!" } }; { { def __rmul__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rmul__ is not supported by py_class! Use __mul__ instead!" } + $crate::py_error! { "Reflected numeric operator __rmul__ is not supported by py_class! Use __mul__ instead!" } }; { { def __ror__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __ror__ is not supported by py_class! Use __or__ instead!" } + $crate::py_error! { "Reflected numeric operator __ror__ is not supported by py_class! Use __or__ instead!" } }; { { def __round__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__round__ is not supported by py_class! yet." } + $crate::py_error! { "__round__ is not supported by py_class! yet." } }; { { def __rpow__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rpow__ is not supported by py_class! Use __pow__ instead!" } + $crate::py_error! { "Reflected numeric operator __rpow__ is not supported by py_class! Use __pow__ instead!" } }; { { def __rrshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rrshift__ is not supported by py_class! Use __rshift__ instead!" } + $crate::py_error! { "Reflected numeric operator __rrshift__ is not supported by py_class! Use __rshift__ instead!" } }; { { def __rshift__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1599,46 +1599,46 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_rshift: py_class_binary_numeric_slot!($class::__rshift__), + nb_rshift: $crate::py_class_binary_numeric_slot!($class::__rshift__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __rshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __rshift__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __rshift__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __rshift__" } + $crate::py_error! { "Invalid signature for binary numeric operator __rshift__" } }; { { def __rsub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rsub__ is not supported by py_class! Use __sub__ instead!" } + $crate::py_error! { "Reflected numeric operator __rsub__ is not supported by py_class! Use __sub__ instead!" } }; { { def __rtruediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rtruediv__ is not supported by py_class! Use __truediv__ instead!" } + $crate::py_error! { "Reflected numeric operator __rtruediv__ is not supported by py_class! Use __truediv__ instead!" } }; { { def __rxor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Reflected numeric operator __rxor__ is not supported by py_class! Use __xor__ instead!" } + $crate::py_error! { "Reflected numeric operator __rxor__ is not supported by py_class! Use __xor__ instead!" } }; { { def __set__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__set__ is not supported by py_class! yet." } + $crate::py_error! { "__set__ is not supported by py_class! yet." } }; { { def __setattr__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__setattr__ is not supported by py_class! yet." } + $crate::py_error! { "__setattr__ is not supported by py_class! yet." } }; { { def __setitem__(&$slf:ident, $key:ident : $key_type:ty, $value:ident : $value_type:ty) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1651,25 +1651,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots $as_number $as_sequence $as_mapping /* setdelitem */ [ - sdi_setitem: { py_class_ternary_slot!($class::__setitem__, $key_type, $value_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, + sdi_setitem: { $crate::py_class_ternary_slot!($class::__setitem__, $key_type, $value_type, $crate::_detail::libc::c_int, $crate::py_class::slots::UnitCallbackConverter) }, sdi_delitem: $sdi_delitem_slot_value, ] } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __setitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} } { $value : $value_type = {} }] } + $crate::py_class_impl_item! { $class, $py, __setitem__(&$slf,) $res_type; { $($body)* } [{ $key : $key_type = {} } { $value : $value_type = {} }] } } $members }}; { { def __setitem__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __setitem__" } + $crate::py_error! { "Invalid signature for operator __setitem__" } }; { { def __str__(&$slf:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1679,25 +1679,25 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { /* type_slots */ [ $( $tp_slot_name : $tp_slot_value, )* - tp_str: py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), + tp_str: $crate::py_class_unary_slot!($class::__str__, *mut $crate::_detail::ffi::PyObject, $crate::_detail::PythonObjectCallbackConverter::<$crate::PyString>(std::marker::PhantomData)), ] $as_number $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __str__(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, __str__(&$slf,) $res_type; { $($body)* } [] } } $members }}; { { def __str__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for operator __str__" } + $crate::py_error! { "Invalid signature for operator __str__" } }; { { def __sub__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1708,34 +1708,34 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_subtract: py_class_binary_numeric_slot!($class::__sub__), + nb_subtract: $crate::py_class_binary_numeric_slot!($class::__sub__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __sub__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __sub__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __sub__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __sub__" } + $crate::py_error! { "Invalid signature for binary numeric operator __sub__" } }; { { def __subclasscheck__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__subclasscheck__ is not supported by py_class! yet." } + $crate::py_error! { "__subclasscheck__ is not supported by py_class! yet." } }; { { def __truediv__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "__truediv__ is not supported by py_class! yet." } + $crate::py_error! { "__truediv__ is not supported by py_class! yet." } }; { { def __xor__($left:ident, $right:ident) -> $res_type:ty { $($body:tt)* } $($tail:tt)* } $class:ident $py:ident $info:tt @@ -1746,107 +1746,107 @@ macro_rules! py_class_impl { } { $( $imp:item )* } $members:tt - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info /* slots: */ { $type_slots /* as_number */ [ $( $nb_slot_name : $nb_slot_value, )* - nb_xor: py_class_binary_numeric_slot!($class::__xor__), + nb_xor: $crate::py_class_binary_numeric_slot!($class::__xor__), ] $as_sequence $as_mapping $setdelitem } /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, __xor__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } + $crate::py_class_impl_item! { $class, $py, __xor__() $res_type; { $($body)* } [ { $left : &$crate::PyObject = {} } { $right : &$crate::PyObject = {} } ] } } $members }}; { { def __xor__ $($tail:tt)* } $( $stuff:tt )* } => { - py_error! { "Invalid signature for binary numeric operator __xor__" } + $crate::py_error! { "Invalid signature for binary numeric operator __xor__" } }; { { $(#[doc=$doc:expr])* def $name:ident (&$slf:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py, $name(&$slf,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py, $name(&$slf,) $res_type; { $($body)* } [] } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_class_instance_method!{$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) } []}; + $name = $crate::py_class_instance_method!{$py, $class::$name, { concat!($($doc, "\n"),*) } []}; } }}; { { $(#[doc=$doc:expr])* def $name:ident (&$slf:ident, $($p:tt)+) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, $name(&$slf,) $res_type; { $($body)* } } [] ($($p)+,) } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_argparse_parse_plist_impl!{py_class_instance_method {$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) }} [] ($($p)+,)}; + $name = $crate::py_argparse_parse_plist_impl!{py_class_instance_method {$py, $class::$name, { concat!($($doc, "\n"),*) }} [] ($($p)+,)}; } }}; { { $(#[doc=$doc:expr])*@classmethod def $name:ident ($cls:ident) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_class_impl_item! { $class, $py,$name($cls: &$crate::PyType,) $res_type; { $($body)* } [] } + $crate::py_class_impl_item! { $class, $py,$name($cls: &$crate::PyType,) $res_type; { $($body)* } [] } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_class_class_method!{$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) } []}; + $name = $crate::py_class_class_method!{$py, $class::$name, { concat!($($doc, "\n"),*) } []}; } }}; { { $(#[doc=$doc:expr])*@classmethod def $name:ident ($cls:ident, $($p:tt)+) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist_impl!{ + $crate::py_argparse_parse_plist_impl!{ py_class_impl_item { $class, $py, $name($cls: &$crate::PyType,) $res_type; { $($body)* } } [] ($($p)+,) } } /* members: */ { $( $member_name = $member_expr; )* - $name = py_argparse_parse_plist_impl!{py_class_class_method {$py, $class::$name, { _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) }} [] ($($p)+,)}; + $name = $crate::py_argparse_parse_plist_impl!{py_class_class_method {$py, $class::$name, { concat!($($doc, "\n"),*) }} [] ($($p)+,)}; } }}; { { $(#[doc=$doc:expr])* @staticmethod def $name:ident ($($p:tt)*) -> $res_type:ty { $( $body:tt )* } $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt { $( $imp:item )* } { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots /* impl: */ { $($imp)* - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_impl_item { $class, $py, $name() $res_type; { $($body)* } } ($($p)*) } @@ -1854,9 +1854,9 @@ macro_rules! py_class_impl { /* members: */ { $( $member_name = $member_expr; )* $name = - py_argparse_parse_plist!{ + $crate::py_argparse_parse_plist!{ py_class_static_method {$py, $class::$name, { - _cpython__py_class__py_class_impl__concat!($($doc, "\n"),*) + concat!($($doc, "\n"),*) } } ($($p)*) } @@ -1866,7 +1866,7 @@ macro_rules! py_class_impl { { { static $name:ident = $init:expr; $($tail:tt)* } $class:ident $py:ident $info:tt $slots:tt $impls:tt { $( $member_name:ident = $member_expr:expr; )* } - } => { py_class_impl! { + } => { $crate::py_class_impl! { { $($tail)* } $class $py $info $slots $impls /* members: */ { @@ -1877,27 +1877,3 @@ macro_rules! py_class_impl { } -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__py_class_impl__assert { - ($($inner:tt)*) => { - assert! { $($inner)* } - } -} - diff --git a/src/py_class/slots.rs b/src/py_class/slots.rs index bc50b56f..61461d0f 100644 --- a/src/py_class/slots.rs +++ b/src/py_class/slots.rs @@ -30,7 +30,7 @@ use crate::py_class::CompareOp; use crate::python::{Python, PythonObject}; use crate::Py_hash_t; -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_type_object_static_init { ($class_name:ident, @@ -45,8 +45,8 @@ macro_rules! py_class_type_object_static_init { $crate::_detail::ffi::PyTypeObject { $( $slot_name : $slot_value, )* tp_dealloc: Some($crate::py_class::slots::tp_dealloc_callback::<$class_name>), - tp_flags: py_class_type_object_flags!($gc), - tp_traverse: py_class_tp_traverse!($class_name, $gc), + tp_flags: $crate::py_class_type_object_flags!($gc), + tp_traverse: $crate::py_class_tp_traverse!($class_name, $gc), .. $crate::_detail::ffi::PyTypeObject_INIT } @@ -76,7 +76,7 @@ pub const TPFLAGS_DEFAULT: ::libc::c_long = ffi::Py_TPFLAGS_DEFAULT | ffi::Py_TP #[cfg(feature = "python3-sys")] pub const TPFLAGS_DEFAULT: ::libc::c_ulong = ffi::Py_TPFLAGS_DEFAULT; -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_type_object_dynamic_init { // initialize those fields of PyTypeObject that we couldn't initialize statically @@ -91,17 +91,16 @@ macro_rules! py_class_type_object_dynamic_init { ) => { unsafe { $type_object.init_ob_type(&mut $crate::_detail::ffi::PyType_Type); - $type_object.tp_name = $crate::py_class::slots::build_tp_name( - $module_name, - _cpython__py_class__slots__stringify!($class), - ); + $type_object.tp_name = + $crate::py_class::slots::build_tp_name($module_name, stringify!($class)); $type_object.tp_basicsize = <$class as $crate::py_class::BaseObject>::size() as $crate::_detail::ffi::Py_ssize_t; } // call slot macros outside of unsafe block - *(unsafe { &mut $type_object.tp_as_sequence }) = py_class_as_sequence!($as_sequence); - *(unsafe { &mut $type_object.tp_as_number }) = py_class_as_number!($as_number); - py_class_as_mapping!($type_object, $as_mapping, $setdelitem); + *(unsafe { &mut $type_object.tp_as_sequence }) = + $crate::py_class_as_sequence!($as_sequence); + *(unsafe { &mut $type_object.tp_as_number }) = $crate::py_class_as_number!($as_number); + $crate::py_class_as_mapping!($type_object, $as_mapping, $setdelitem); }; } @@ -125,7 +124,7 @@ where r } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_wrap_newfunc { ($class:ident :: $f:ident [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ @@ -135,11 +134,11 @@ macro_rules! py_class_wrap_newfunc { kwargs: *mut $crate::_detail::ffi::PyObject) -> *mut $crate::_detail::ffi::PyObject { - const LOCATION: &'static str = _cpython__py_class__slots__concat!(_cpython__py_class__slots__stringify!($class), ".", _cpython__py_class__slots__stringify!($f), "()"); + const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()"); $crate::_detail::handle_callback( LOCATION, $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(LOCATION), args, kwargs, + $crate::py_argparse_raw!(py, Some(LOCATION), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { let cls = $crate::PyType::from_type_ptr(py, cls); @@ -183,7 +182,7 @@ macro_rules! py_class_as_number { }} } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_as_mapping { ( $type_object:ident, [], [ @@ -212,11 +211,11 @@ macro_rules! py_class_as_mapping { val: *mut $crate::_detail::ffi::PyObject ) -> $crate::_detail::libc::c_int { if val.is_null() { - py_class_mp_ass_subscript!($delitem, slf, + $crate::py_class_mp_ass_subscript!($delitem, slf, b"Subscript assignment not supported by %.200s\0", key) } else { - py_class_mp_ass_subscript!($setitem, slf, + $crate::py_class_mp_ass_subscript!($setitem, slf, b"Subscript deletion not supported by %.200s\0", key, val) } @@ -570,7 +569,7 @@ impl CallbackConverter for BoolConverter { } } -#[macro_export(local_inner_macros)] +#[macro_export] #[doc(hidden)] macro_rules! py_class_call_slot { ($class:ident :: $f:ident [ $( { $pname:ident : $ptype:ty = $detail:tt } )* ]) => {{ @@ -580,11 +579,11 @@ macro_rules! py_class_call_slot { kwargs: *mut $crate::_detail::ffi::PyObject) -> *mut $crate::_detail::ffi::PyObject { - const LOCATION: &'static str = _cpython__py_class__slots__concat!(_cpython__py_class__slots__stringify!($class), ".", _cpython__py_class__slots__stringify!($f), "()"); + const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()"); $crate::_detail::handle_callback( LOCATION, $crate::_detail::PyObjectCallbackConverter, |py| { - py_argparse_raw!(py, Some(LOCATION), args, kwargs, + $crate::py_argparse_raw!(py, Some(LOCATION), args, kwargs, [ $( { $pname : $ptype = $detail } )* ] { let slf = $crate::PyObject::from_borrowed_ptr(py, slf).unchecked_cast_into::<$class>(); @@ -611,19 +610,3 @@ pub unsafe extern "C" fn sq_item( ffi::Py_DECREF(arg); ret } - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__slots__concat { - ($($inner:tt)*) => { - concat! { $($inner)* } - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _cpython__py_class__slots__stringify { - ($($inner:tt)*) => { - stringify! { $($inner)* } - } -} diff --git a/tests/test_class.rs b/tests/test_class.rs index d9c2e5c7..761b74fd 100644 --- a/tests/test_class.rs +++ b/tests/test_class.rs @@ -1,7 +1,5 @@ #![allow(dead_code, unused_variables)] -extern crate cpython; - use cpython::_detail::ffi; use cpython::*; use std::cell::{Cell, RefCell}; diff --git a/tests/test_function.rs b/tests/test_function.rs index a32f3260..3f3dfa01 100644 --- a/tests/test_function.rs +++ b/tests/test_function.rs @@ -1,7 +1,4 @@ -#[macro_use] -extern crate cpython; - -use cpython::{NoArgs, ObjectProtocol, PyDict, PyResult, Python}; +use cpython::{py_fn, NoArgs, ObjectProtocol, PyDict, PyResult, Python}; use std::sync::atomic; use std::sync::atomic::Ordering::Relaxed; diff --git a/tests/test_sharedref.rs b/tests/test_sharedref.rs index 3a645f51..438f4e63 100644 --- a/tests/test_sharedref.rs +++ b/tests/test_sharedref.rs @@ -1,7 +1,4 @@ -#[macro_use] -extern crate cpython; - -use cpython::{GILGuard, Python}; +use cpython::{py_class, GILGuard, Python}; py_class!(class Owner |py| { @shared data string: String; From a9e7e49f696c7a1147f09bb0be903c4e3f7bb3db Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Tue, 28 Jan 2020 20:51:37 -0800 Subject: [PATCH 10/10] use paste to generate module init symbol names Use the `paste` crate to generate the module init symbol names (`initfoo` and `PyInit_foo`), rather than requiring the user to pass them in. This makes creating modules less error-prone. --- Cargo.toml | 1 + README.md | 2 +- extensions/hello/src/hello.rs | 2 +- extensions/tests/btree.rs | 2 +- extensions/tests/custom_class.rs | 2 +- extensions/tests/hello.rs | 2 +- src/lib.rs | 61 ++++++++++++++++++-------------- src/objects/capsule.rs | 3 +- 8 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ef3f723a..828d6211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ appveyor = { repository = "dgrunwald/rust-cpython" } [dependencies] libc = "0.2" num-traits = "0.2" +paste = "0.1" # These features are both optional, but you must pick one to # indicate which python ffi you are trying to bind to. diff --git a/README.md b/README.md index e9a768af..32975285 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ use cpython::{PyResult, Python, py_module_initializer, py_fn}; // add bindings to the generated python module // N.B: names: "rust2py" must be the name of the `.so` or `.pyd` file -py_module_initializer!(rust2py, initrust2py, PyInit_rust2py, |py, m| { +py_module_initializer!(rust2py, |py, m| { m.add(py, "__doc__", "This module is implemented in Rust.")?; m.add(py, "sum_as_string", py_fn!(py, sum_as_string_py(a: i64, b:i64)))?; Ok(()) diff --git a/extensions/hello/src/hello.rs b/extensions/hello/src/hello.rs index d5771d9b..c8b9e6a0 100644 --- a/extensions/hello/src/hello.rs +++ b/extensions/hello/src/hello.rs @@ -4,7 +4,7 @@ use cpython::{py_fn, py_module_initializer, PyDict, PyObject, PyResult, PyTuple, // This requires that the output binary file is named `hello.so` (or Windows: `hello.pyd`). // As the output name cannot be configured in cargo (https://github.com/rust-lang/cargo/issues/1970), // you'll have to rename the output file. -py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { +py_module_initializer!(hello, |py, m| { m.add(py, "__doc__", "Module documentation string")?; m.add(py, "func", py_fn!(py, func(a: &str, b: i32)))?; m.add(py, "run", py_fn!(py, run(*args, **kwargs)))?; diff --git a/extensions/tests/btree.rs b/extensions/tests/btree.rs index 6cfe8b40..02a9548e 100644 --- a/extensions/tests/btree.rs +++ b/extensions/tests/btree.rs @@ -3,7 +3,7 @@ use cpython::{PyObject, PyResult, py_module_initializer, py_class}; use std::{cell, cmp, collections}; -py_module_initializer!(btree, initbtree, PyInit_btree, |py, m| { +py_module_initializer!(btree, |py, m| { m.add(py, "__doc__", "Rust BTreeSet for Python.")?; m.add_class::(py)?; Ok(()) diff --git a/extensions/tests/custom_class.rs b/extensions/tests/custom_class.rs index f1d64b50..ed86b272 100644 --- a/extensions/tests/custom_class.rs +++ b/extensions/tests/custom_class.rs @@ -2,7 +2,7 @@ use cpython::{PyObject, PyResult, py_module_initializer, py_class}; -py_module_initializer!(custom_class, initcustom_class, PyInit_custom_class, |py, m| { +py_module_initializer!(custom_class, |py, m| { m.add(py, "__doc__", "Module documentation string")?; m.add_class::(py)?; Ok(()) diff --git a/extensions/tests/hello.rs b/extensions/tests/hello.rs index 87597884..80c171a8 100644 --- a/extensions/tests/hello.rs +++ b/extensions/tests/hello.rs @@ -2,7 +2,7 @@ use cpython::{PyObject, PyResult, Python, PyTuple, PyDict, py_module_initializer, py_fn}; -py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { +py_module_initializer!(hello, |py, m| { m.add(py, "__doc__", "Module documentation string")?; m.add(py, "run", py_fn!(py, run(*args, **kwargs)))?; m.add(py, "val", py_fn!(py, val()))?; diff --git a/src/lib.rs b/src/lib.rs index fb77036c..8e3f7c78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -228,25 +228,28 @@ pub mod _detail { handle_callback, py_fn_impl, AbortOnDrop, PyObjectCallbackConverter, PythonObjectCallbackConverter, }; + pub use paste; } /// Expands to an `extern "C"` function that allows Python to load /// the rust code as a Python extension module. /// -/// Macro syntax: `py_module_initializer!($name, $py2_init, $py3_init, |$py, $m| $body)` +/// Macro syntax: `py_module_initializer!($name, |$py, $m| $body)` /// /// 1. `name`: The module name as a Rust identifier. -/// 2. `py2_init`: "init" + $name. Necessary because macros can't use concat_idents!(). -/// 3. `py3_init`: "PyInit_" + $name. Necessary because macros can't use concat_idents!(). -/// 4. A lambda of type `Fn(Python, &PyModule) -> PyResult<()>`. +/// 2. A lambda of type `Fn(Python, &PyModule) -> PyResult<()>`. /// This function will be called when the module is imported, and is responsible /// for adding the module's members. /// +/// For backwards compatibilty with older versions of rust-cpython, +/// two additional name identifiers (for py2 and py3 initializer names) +/// can be provided, but they will be ignored. +/// /// # Example /// ``` /// use cpython::{Python, PyResult, PyObject, py_module_initializer, py_fn}; /// -/// py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { +/// py_module_initializer!(hello, |py, m| { /// m.add(py, "__doc__", "Module documentation string")?; /// m.add(py, "run", py_fn!(py, run()))?; /// Ok(()) @@ -287,16 +290,18 @@ pub mod _detail { #[macro_export] #[cfg(feature = "python27-sys")] macro_rules! py_module_initializer { - ($name: ident, $py2: ident, $py3: ident, |$py_id: ident, $m_id: ident| $body: expr) => { - #[no_mangle] - #[allow(non_snake_case)] - pub unsafe extern "C" fn $py2() { - // Nest init function so that $body isn't in unsafe context - fn init($py_id: $crate::Python, $m_id: &$crate::PyModule) -> $crate::PyResult<()> { - $body + ($name: ident, $( $_py2: ident, $_py3: ident, )? |$py_id: ident, $m_id: ident| $body: tt) => { + $crate::_detail::paste::item! { + #[no_mangle] + #[allow(non_snake_case)] + pub unsafe extern "C" fn [< init $name >]() { + // Nest init function so that $body isn't in unsafe context + fn init($py_id: $crate::Python, $m_id: &$crate::PyModule) -> $crate::PyResult<()> { + $body + } + let name = concat!(stringify!($name), "\0").as_ptr() as *const _; + $crate::py_module_initializer_impl(name, init) } - let name = concat!(stringify!($name), "\0").as_ptr() as *const _; - $crate::py_module_initializer_impl(name, init) } }; } @@ -335,20 +340,22 @@ pub unsafe fn py_module_initializer_impl( #[macro_export] #[cfg(feature = "python3-sys")] macro_rules! py_module_initializer { - ($name: ident, $py2: ident, $py3: ident, |$py_id: ident, $m_id: ident| $body: expr) => { - #[no_mangle] - #[allow(non_snake_case)] - pub unsafe extern "C" fn $py3() -> *mut $crate::_detail::ffi::PyObject { - // Nest init function so that $body isn't in unsafe context - fn init($py_id: $crate::Python, $m_id: &$crate::PyModule) -> $crate::PyResult<()> { - $body + ($name: ident, $( $_py2: ident, $_py3: ident, )? |$py_id: ident, $m_id: ident| $body: tt) => { + $crate::_detail::paste::item! { + #[no_mangle] + #[allow(non_snake_case)] + pub unsafe extern "C" fn [< PyInit_ $name >]() -> *mut $crate::_detail::ffi::PyObject { + // Nest init function so that $body isn't in unsafe context + fn init($py_id: $crate::Python, $m_id: &$crate::PyModule) -> $crate::PyResult<()> { + $body + } + static mut MODULE_DEF: $crate::_detail::ffi::PyModuleDef = + $crate::_detail::ffi::PyModuleDef_INIT; + // We can't convert &'static str to *const c_char within a static initializer, + // so we'll do it here in the module initialization: + MODULE_DEF.m_name = concat!(stringify!($name), "\0").as_ptr() as *const _; + $crate::py_module_initializer_impl(&mut MODULE_DEF, init) } - static mut MODULE_DEF: $crate::_detail::ffi::PyModuleDef = - $crate::_detail::ffi::PyModuleDef_INIT; - // We can't convert &'static str to *const c_char within a static initializer, - // so we'll do it here in the module initialization: - MODULE_DEF.m_name = concat!(stringify!($name), "\0").as_ptr() as *const _; - $crate::py_module_initializer_impl(&mut MODULE_DEF, init) } }; } diff --git a/src/objects/capsule.rs b/src/objects/capsule.rs index 90e61101..aaf7adf4 100644 --- a/src/objects/capsule.rs +++ b/src/objects/capsule.rs @@ -174,11 +174,12 @@ use crate::python::{Python, ToPythonPointer}; /// # a + b /// # } /// # static DATA: CapsData = CapsData{value: 1, fun: add}; -/// py_module_initializer!(somemod, initsomemod, PyInit_somemod, |py, m| { +/// py_module_initializer!(somemod, |py, m| { /// m.add(py, "__doc__", "A module holding a capsule")?; /// m.add(py, "capsdata", PyCapsule::new_data(py, &DATA, "somemod.capsdata").unwrap())?; /// Ok(()) /// }); +/// # fn main() {} /// ``` /// Another Rust extension could then declare `CapsData` and use `PyCapsule::import_data` to /// fetch it back.