better naming
This commit is contained in:
parent
fc762288fe
commit
cbfdfa2d07
|
@ -28,6 +28,7 @@ pub fn build_py_class(ast: &mut syn::DeriveInput) -> Tokens {
|
|||
#[allow(non_upper_case_globals, unused_attributes,
|
||||
unused_qualifications, unused_variables, non_camel_case_types)]
|
||||
const #dummy_const: () = {
|
||||
use std;
|
||||
extern crate pyo3 as _pyo3;
|
||||
|
||||
#tokens
|
||||
|
@ -40,7 +41,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident, token: Option<syn::Ident>) ->
|
|||
|
||||
let extra = if let Some(token) = token {
|
||||
Some(quote! {
|
||||
impl _pyo3::PythonObjectWithToken for #cls {
|
||||
impl _pyo3::PyObjectWithToken for #cls {
|
||||
fn token<'p>(&'p self) -> _pyo3::python::Python<'p> {
|
||||
self.#token.token()
|
||||
}
|
||||
|
@ -48,7 +49,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident, token: Option<syn::Ident>) ->
|
|||
|
||||
impl std::fmt::Debug for #cls {
|
||||
fn fmt(&self, f : &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
let ptr = <#cls as _pyo3::python::ToPythonPointer>::as_ptr(self);
|
||||
let ptr = <#cls as _pyo3::python::ToPyPointer>::as_ptr(self);
|
||||
let repr = unsafe {
|
||||
PyString::downcast_from_owned_ptr(
|
||||
self.token(), _pyo3::ffi::PyObject_Repr(ptr))
|
||||
|
@ -60,7 +61,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident, token: Option<syn::Ident>) ->
|
|||
|
||||
impl std::fmt::Display for #cls {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
let ptr = <#cls as _pyo3::python::ToPythonPointer>::as_ptr(self);
|
||||
let ptr = <#cls as _pyo3::python::ToPyPointer>::as_ptr(self);
|
||||
let str_obj = unsafe {
|
||||
PyString::downcast_from_owned_ptr(
|
||||
self.token(), _pyo3::ffi::PyObject_Str(ptr))
|
||||
|
@ -122,7 +123,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident, token: Option<syn::Ident>) ->
|
|||
}
|
||||
}
|
||||
|
||||
impl _pyo3::python::ToPythonPointer for #cls {
|
||||
impl _pyo3::python::ToPyPointer for #cls {
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
let offset = <#cls as _pyo3::typeob::PyTypeInfo>::offset();
|
||||
|
@ -140,7 +141,7 @@ fn is_python_token(field: &syn::Field) -> bool {
|
|||
match field.ty {
|
||||
syn::Ty::Path(_, ref path) => {
|
||||
if let Some(segment) = path.segments.last() {
|
||||
return segment.ident.as_ref() == "PythonToken"
|
||||
return segment.ident.as_ref() == "PyToken"
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -23,7 +23,7 @@ pub fn build_ptr(cls: syn::Ident, ast: &mut syn::DeriveInput) -> Tokens {
|
|||
type Target = #ptr;
|
||||
|
||||
fn park(&self) -> #ptr {
|
||||
let token = _pyo3::PythonObjectWithToken::token(self);
|
||||
let token = _pyo3::PyObjectWithToken::token(self);
|
||||
let ptr = self.clone_ref(token).into_ptr();
|
||||
|
||||
#ptr(unsafe{_pyo3::PyPtr::from_owned_ptr(ptr)})
|
||||
|
|
|
@ -24,8 +24,8 @@ use libc;
|
|||
use ffi;
|
||||
use exc;
|
||||
use err::{self, PyResult};
|
||||
use python::{Python, ToPythonPointer};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use python::{Python, ToPyPointer};
|
||||
use token::PyObjectWithGilToken;
|
||||
use objects::PyObject;
|
||||
|
||||
/// Allows access to the underlying buffer used by a python object such as `bytes`, `bytearray` or `array.array`.
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{any, mem, ptr, isize, io, panic};
|
|||
use libc;
|
||||
|
||||
use pointers::Py;
|
||||
use python::{Python, IntoPythonPointer};
|
||||
use python::{Python, IntoPyPointer};
|
||||
use objects::exc;
|
||||
use conversion::IntoPyObject;
|
||||
use ffi::{self, Py_hash_t};
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::os::raw::c_int;
|
|||
use ::{Py, CompareOp};
|
||||
use ffi;
|
||||
use err::{PyErr, PyResult};
|
||||
use python::{Python, IntoPythonPointer};
|
||||
use python::{Python, IntoPyPointer};
|
||||
use objects::PyObject;
|
||||
use objects::exc;
|
||||
use typeob::PyTypeInfo;
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::os::raw::{c_int, c_void};
|
|||
|
||||
use ffi;
|
||||
use pointers::Py;
|
||||
use python::{Python, ToPythonPointer};
|
||||
use python::{Python, ToPyPointer};
|
||||
use callback::AbortOnDrop;
|
||||
use typeob::PyTypeInfo;
|
||||
|
||||
|
@ -69,7 +69,7 @@ pub struct PyVisit<'p> {
|
|||
|
||||
impl <'p> PyVisit<'p> {
|
||||
pub fn call<T>(&self, obj: &T) -> Result<(), PyTraverseError>
|
||||
where T: ToPythonPointer
|
||||
where T: ToPyPointer
|
||||
{
|
||||
let r = unsafe { (self.visit)(obj.as_ptr(), self.arg) };
|
||||
if r == 0 {
|
||||
|
|
|
@ -44,7 +44,7 @@ pub enum CompareOp {
|
|||
pub trait PyCustomObject : PyTypeInfo + Sized {}
|
||||
|
||||
|
||||
impl<T> ::python::PyClone for T where T: ::PythonObjectWithToken + PyTypeInfo {
|
||||
impl<T> ::python::PyClone for T where T: ::PyObjectWithToken + PyTypeInfo {
|
||||
#[inline]
|
||||
fn clone_ref<'p>(&self, py: ::Python<'p>) -> ::PyObject<'p> {
|
||||
unsafe {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ffi;
|
||||
use err::PyResult;
|
||||
use python::{Python, ToPythonPointer, PyDowncastFrom, Park};
|
||||
use python::{Python, ToPyPointer, PyDowncastFrom, Park};
|
||||
use objects::{PyObject, PyTuple};
|
||||
use typeob::PyTypeInfo;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::os::raw::c_char;
|
|||
use libc;
|
||||
|
||||
use ffi;
|
||||
use python::{ToPythonPointer, IntoPythonPointer, Python, Park, PyDowncastInto, PyClone};
|
||||
use python::{ToPyPointer, IntoPyPointer, Python, Park, PyDowncastInto, PyClone};
|
||||
use objects::{PyObject, PyObjectPtr, PyType, PyTypePtr, exc};
|
||||
use typeob::{PyTypeObject};
|
||||
use conversion::{ToPyObject, ToPyTuple, IntoPyObject};
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::fmt;
|
|||
use ffi;
|
||||
use typeob::PyTypeInfo;
|
||||
use pointers::{Py, Ptr, PyPtr};
|
||||
use python::{Python, PyDowncastInto, ToPythonPointer};
|
||||
use python::{Python, PyDowncastInto, ToPyPointer};
|
||||
use objectprotocol::ObjectProtocol;
|
||||
|
||||
|
||||
|
|
|
@ -68,12 +68,12 @@ pub mod pointers;
|
|||
pub use pointers::{Py, PyPtr};
|
||||
|
||||
mod token;
|
||||
pub use token::{PythonToken, PythonObjectWithToken, PythonObjectWithGilToken};
|
||||
pub use token::{PyToken, PyObjectWithToken, PyObjectWithGilToken};
|
||||
|
||||
pub use err::{PyErr, PyResult, PyDowncastError};
|
||||
pub use objects::*;
|
||||
pub use objectprotocol::ObjectProtocol;
|
||||
pub use python::{Python, ToPythonPointer, IntoPythonPointer,
|
||||
pub use python::{Python, ToPyPointer, IntoPyPointer,
|
||||
Park, ParkRef,
|
||||
PyClone, PyDowncastFrom, PyDowncastInto};
|
||||
pub use pythonrun::{GILGuard, GILProtected, prepare_freethreaded_python};
|
||||
|
|
|
@ -8,9 +8,9 @@ use std::cmp::Ordering;
|
|||
use ffi;
|
||||
use err::{PyErr, PyResult, self};
|
||||
use pointers::Ptr;
|
||||
use python::{Python, PyDowncastInto, ToPythonPointer};
|
||||
use python::{Python, PyDowncastInto, ToPyPointer};
|
||||
use objects::{PyObject, PyDict, PyString, PyIterator};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use conversion::{ToPyObject, ToPyTuple};
|
||||
|
||||
|
||||
|
@ -123,7 +123,7 @@ pub trait ObjectProtocol<'p> {
|
|||
}
|
||||
|
||||
|
||||
impl<'p, T> ObjectProtocol<'p> for T where T: PythonObjectWithGilToken<'p> + ToPythonPointer {
|
||||
impl<'p, T> ObjectProtocol<'p> for T where T: PyObjectWithGilToken<'p> + ToPyPointer {
|
||||
|
||||
/// Determines whether this object has the given attribute.
|
||||
/// This is equivalent to the Python expression 'hasattr(self, attr_name)'.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ffi;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{ToPythonPointer, Python};
|
||||
use python::{ToPyPointer, Python};
|
||||
use objects::PyObject;
|
||||
use conversion::ToPyObject;
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ use std;
|
|||
use std::ptr;
|
||||
use std::os::raw::c_char;
|
||||
use ffi;
|
||||
use python::{Python, ToPythonPointer};
|
||||
use python::{Python, ToPyPointer};
|
||||
use objects::PyObject;
|
||||
use err::{PyResult, PyErr};
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
|
||||
|
||||
/// Represents a Python bytearray.
|
||||
|
|
|
@ -6,10 +6,10 @@ use std::{mem, collections, hash, cmp};
|
|||
|
||||
use ffi;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{Python, ToPythonPointer, PyDowncastInto};
|
||||
use python::{Python, ToPyPointer, PyDowncastInto};
|
||||
use conversion::{ToPyObject};
|
||||
use objects::{PyObject, PyList};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use err::{self, PyResult, PyErr};
|
||||
|
||||
/// Represents a Python `dict`.
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::{self, mem, ops};
|
|||
use std::ffi::CStr;
|
||||
|
||||
use ffi;
|
||||
use python::{Python, ToPythonPointer, Park};
|
||||
use python::{Python, ToPyPointer, Park};
|
||||
use err::PyResult;
|
||||
use super::{PyTuple, PyType, PyTypePtr};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use ffi;
|
||||
use pointers::Ptr;
|
||||
use python::{Python, ToPythonPointer, IntoPythonPointer};
|
||||
use python::{Python, ToPyPointer, IntoPyPointer};
|
||||
use objects::PyObject;
|
||||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl <'p> PyIterator<'p> {
|
|||
/// Constructs a PyIterator from a Python iterator object.
|
||||
pub fn from_object<T>(py: Python<'p>, obj: T)
|
||||
-> Result<PyIterator<'p>, PyDowncastError<'p>>
|
||||
where T: IntoPythonPointer
|
||||
where T: IntoPyPointer
|
||||
{
|
||||
unsafe {
|
||||
let ptr = obj.into_ptr();
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
use err::{self, PyResult};
|
||||
use ffi::{self, Py_ssize_t};
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{Python, ToPythonPointer, IntoPythonPointer, Park};
|
||||
use python::{Python, ToPyPointer, IntoPyPointer, Park};
|
||||
use objects::PyObject;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use conversion::{ToPyObject, IntoPyObject};
|
||||
|
||||
/// Represents a Python `list`.
|
||||
|
|
|
@ -83,7 +83,7 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
|
||||
impl $crate::python::IntoPythonPointer for $ptr {
|
||||
impl $crate::python::IntoPyPointer for $ptr {
|
||||
/// Gets the underlying FFI pointer, returns a owned pointer.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
|
@ -92,7 +92,7 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
|
||||
impl $crate::python::ToPythonPointer for $ptr {
|
||||
impl $crate::python::ToPyPointer for $ptr {
|
||||
/// Gets the underlying FFI pointer, returns a owned pointer.
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut $crate::ffi::PyObject {
|
||||
|
@ -104,7 +104,7 @@ macro_rules! pyobject_nativetype(
|
|||
{
|
||||
fn downcast_into<I>(py: $crate::Python<'p>, ob: I)
|
||||
-> Result<Self, $crate::PyDowncastError<'p>>
|
||||
where I: $crate::ToPythonPointer + $crate::IntoPythonPointer
|
||||
where I: $crate::ToPyPointer + $crate::IntoPyPointer
|
||||
{
|
||||
unsafe{
|
||||
let ptr = ob.into_ptr();
|
||||
|
@ -175,7 +175,7 @@ macro_rules! pyobject_nativetype(
|
|||
|
||||
impl<'p> $crate::std::clone::Clone for $name<'p> {
|
||||
fn clone(&self) -> Self {
|
||||
use $crate::token::PythonObjectWithGilToken;
|
||||
use $crate::token::PyObjectWithGilToken;
|
||||
unsafe {
|
||||
$name($crate::pointers::Ptr::from_borrowed_ptr(
|
||||
self.gil(), self.as_ptr()))
|
||||
|
@ -183,7 +183,7 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p> $crate::token::PythonObjectWithGilToken<'p> for $name<'p> {
|
||||
impl<'p> $crate::token::PyObjectWithGilToken<'p> for $name<'p> {
|
||||
fn gil(&self) -> $crate::python::Python<'p> {
|
||||
self.0.token()
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ macro_rules! pyobject_nativetype(
|
|||
fn downcast_from(py: &'p $crate::PyObject<'p>)
|
||||
-> Result<&'p $name<'p>, $crate::PyDowncastError<'p>>
|
||||
{
|
||||
use $crate::{ToPythonPointer, PythonObjectWithGilToken};
|
||||
use $crate::{ToPyPointer, PyObjectWithGilToken};
|
||||
|
||||
unsafe {
|
||||
if $crate::ffi::$checkfunction(py.as_ptr()) > 0 {
|
||||
|
@ -217,7 +217,7 @@ macro_rules! pyobject_nativetype(
|
|||
{
|
||||
fn downcast_into<I>(py: $crate::Python<'p>, ob: I)
|
||||
-> Result<Self, $crate::PyDowncastError<'p>>
|
||||
where I: $crate::ToPythonPointer + $crate::IntoPythonPointer
|
||||
where I: $crate::ToPyPointer + $crate::IntoPyPointer
|
||||
{
|
||||
unsafe{
|
||||
let ptr = ob.into_ptr();
|
||||
|
@ -244,7 +244,7 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p> $crate::python::ToPythonPointer for $name<'p> {
|
||||
impl<'p> $crate::python::ToPyPointer for $name<'p> {
|
||||
/// Gets the underlying FFI pointer, returns a borrowed pointer.
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut $crate::ffi::PyObject {
|
||||
|
@ -252,7 +252,7 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p> $crate::python::IntoPythonPointer for $name<'p> {
|
||||
impl<'p> $crate::python::IntoPyPointer for $name<'p> {
|
||||
/// Gets the underlying FFI pointer, returns a owned pointer.
|
||||
#[inline]
|
||||
fn into_ptr(self) -> *mut $crate::ffi::PyObject {
|
||||
|
@ -267,7 +267,7 @@ macro_rules! pyobject_nativetype(
|
|||
/// Extracts `Self` from the source `Py<PyObject>`.
|
||||
fn extract(py: &'a $crate::PyObject<'a>) -> $crate::PyResult<Self>
|
||||
{
|
||||
use $crate::token::PythonObjectWithGilToken;
|
||||
use $crate::token::PyObjectWithGilToken;
|
||||
|
||||
unsafe {
|
||||
if ffi::$checkfunction(py.as_ptr()) != 0 {
|
||||
|
@ -289,7 +289,7 @@ macro_rules! pyobject_nativetype(
|
|||
Ok($crate::std::mem::transmute(py))
|
||||
} else {
|
||||
Err($crate::PyDowncastError(
|
||||
$crate::token::PythonObjectWithGilToken::gil(py), None).into())
|
||||
$crate::token::PyObjectWithGilToken::gil(py), None).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -325,10 +325,10 @@ macro_rules! pyobject_nativetype(
|
|||
{
|
||||
use $crate::python::PyDowncastInto;
|
||||
|
||||
let py = <$name as $crate::token::PythonObjectWithGilToken>::gil(self);
|
||||
let py = <$name as $crate::token::PyObjectWithGilToken>::gil(self);
|
||||
let s = unsafe { $crate::PyString::downcast_from_owned_ptr(
|
||||
py, $crate::ffi::PyObject_Repr(
|
||||
$crate::python::ToPythonPointer::as_ptr(self))) };
|
||||
$crate::python::ToPyPointer::as_ptr(self))) };
|
||||
let repr_obj = try!(s.map_err(|_| $crate::std::fmt::Error));
|
||||
f.write_str(&repr_obj.to_string_lossy())
|
||||
}
|
||||
|
@ -340,10 +340,10 @@ macro_rules! pyobject_nativetype(
|
|||
{
|
||||
use $crate::python::PyDowncastInto;
|
||||
|
||||
let py = <$name as $crate::token::PythonObjectWithGilToken>::gil(self);
|
||||
let py = <$name as $crate::token::PyObjectWithGilToken>::gil(self);
|
||||
let s = unsafe { $crate::PyString::downcast_from_owned_ptr(
|
||||
py, $crate::ffi::PyObject_Str(
|
||||
$crate::python::ToPythonPointer::as_ptr(self))) };
|
||||
$crate::python::ToPyPointer::as_ptr(self))) };
|
||||
let str_obj = try!(s.map_err(|_| $crate::std::fmt::Error));
|
||||
f.write_str(&str_obj.to_string_lossy())
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ use std::ffi::{CStr, CString};
|
|||
|
||||
use conversion::{ToPyObject, ToPyTuple};
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{ToPythonPointer, Python};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use python::{ToPyPointer, Python};
|
||||
use token::PyObjectWithGilToken;
|
||||
use objects::{PyObject, PyDict, PyType, exc};
|
||||
use objectprotocol::ObjectProtocol;
|
||||
use err::{PyResult, PyErr};
|
||||
|
|
|
@ -10,9 +10,9 @@ use std::os::raw::{c_long, c_double};
|
|||
use ffi;
|
||||
use objects::exc;
|
||||
use objects::PyObject;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{ToPythonPointer, Python};
|
||||
use python::{ToPyPointer, Python};
|
||||
use err::{PyResult, PyErr};
|
||||
use conversion::{ToPyObject, FromPyObject};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use std;
|
|||
use ffi;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
use python::{Python, ToPythonPointer};
|
||||
use python::{Python, ToPyPointer};
|
||||
|
||||
pub struct PyObject<'p>(Ptr<'p>);
|
||||
pub struct PyObjectPtr(PyPtr);
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
use ffi;
|
||||
use pointers::Ptr;
|
||||
use python::{ToPythonPointer, PyDowncastFrom, PyDowncastInto};
|
||||
use python::{ToPyPointer, PyDowncastFrom, PyDowncastInto};
|
||||
use conversion::{FromPyObject, ToPyObject};
|
||||
use objects::{PyObject, PyList, PyTuple};
|
||||
use ffi::Py_ssize_t;
|
||||
use err;
|
||||
use err::{PyErr, PyResult};
|
||||
// use buffer;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use objectprotocol::ObjectProtocol;
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
use std::{hash, collections};
|
||||
use ffi;
|
||||
use python::{Python, ToPythonPointer};
|
||||
use python::{Python, ToPyPointer};
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use conversion::ToPyObject;
|
||||
use objects::PyObject;
|
||||
use err::{self, PyResult, PyErr};
|
||||
use token::{PythonObjectWithGilToken};
|
||||
use token::{PyObjectWithGilToken};
|
||||
|
||||
|
||||
/// Represents a Python `set`
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
use std::os::raw::c_long;
|
||||
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{ToPythonPointer, Python};
|
||||
use python::{ToPyPointer, Python};
|
||||
use err::{PyErr, PyResult};
|
||||
use ffi::{self, Py_ssize_t};
|
||||
use objects::PyObject;
|
||||
use conversion::ToPyObject;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
|
||||
/// Represents a Python `slice`. Only `c_long` indeces supprted
|
||||
/// at the moment by PySlice object.
|
||||
|
|
|
@ -10,9 +10,9 @@ use std::os::raw::c_char;
|
|||
|
||||
use ffi;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{ToPythonPointer, Python};
|
||||
use python::{ToPyPointer, Python};
|
||||
use super::{exc, PyObject};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use err::{PyResult, PyErr};
|
||||
use conversion::{ToPyObject, RefFromPyObject};
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ use std::slice;
|
|||
use ffi::{self, Py_ssize_t};
|
||||
use err::{PyErr, PyResult};
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{Python, ToPythonPointer, IntoPythonPointer};
|
||||
use python::{Python, ToPyPointer, IntoPyPointer};
|
||||
use conversion::{FromPyObject, ToPyObject, ToPyTuple, IntoPyObject};
|
||||
use objects::PyObject;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use super::exc;
|
||||
|
||||
/// Represents a Python tuple object.
|
||||
|
|
|
@ -6,9 +6,9 @@ use std::ffi::CStr;
|
|||
use std::borrow::Cow;
|
||||
|
||||
use ffi;
|
||||
use token::PythonObjectWithGilToken;
|
||||
use token::PyObjectWithGilToken;
|
||||
use pointers::{Ptr, PyPtr};
|
||||
use python::{Python, ToPythonPointer};
|
||||
use python::{Python, ToPyPointer};
|
||||
use conversion::ToPyTuple;
|
||||
use objects::{PyObject, PyDict};
|
||||
use err::{PyErr, PyResult};
|
||||
|
@ -51,7 +51,7 @@ impl<'p> PyType<'p> {
|
|||
|
||||
/// Return true if `obj` is an instance of `self`.
|
||||
#[inline]
|
||||
pub fn is_instance<T: ToPythonPointer>(&self, obj: &T) -> bool {
|
||||
pub fn is_instance<T: ToPyPointer>(&self, obj: &T) -> bool {
|
||||
unsafe { ffi::PyObject_TypeCheck(obj.as_ptr(), self.as_type_ptr()) != 0 }
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ use ffi;
|
|||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
use conversion::{ToPyObject, IntoPyObject};
|
||||
use objects::{PyObject, PyObjectPtr};
|
||||
use python::{Python, ToPythonPointer, IntoPythonPointer};
|
||||
use token::PythonObjectWithGilToken;
|
||||
use python::{Python, ToPyPointer, IntoPyPointer};
|
||||
use token::PyObjectWithGilToken;
|
||||
use typeob::{PyTypeInfo, PyObjectAlloc};
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl PyPtr {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPythonPointer for PyPtr {
|
||||
impl ToPyPointer for PyPtr {
|
||||
/// Gets the underlying FFI pointer, returns a borrowed pointer.
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
|
@ -92,7 +92,7 @@ impl ToPythonPointer for PyPtr {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoPythonPointer for PyPtr {
|
||||
impl IntoPyPointer for PyPtr {
|
||||
/// Gets the underlying FFI pointer, returns a owned pointer.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
|
@ -222,7 +222,7 @@ impl<'p> Ptr<'p> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p> ToPythonPointer for Ptr<'p> {
|
||||
impl<'p> ToPyPointer for Ptr<'p> {
|
||||
/// Gets the underlying FFI pointer, returns a borrowed pointer.
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
|
@ -230,7 +230,7 @@ impl<'p> ToPythonPointer for Ptr<'p> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p> IntoPythonPointer for Ptr<'p> {
|
||||
impl<'p> IntoPyPointer for Ptr<'p> {
|
||||
/// Gets the underlying FFI pointer, returns a owned pointer.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
|
@ -332,13 +332,13 @@ impl<'p, T> Py<'p, T> where T: PyTypeInfo
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p, T> PythonObjectWithGilToken<'p> for Py<'p, T> {
|
||||
impl<'p, T> PyObjectWithGilToken<'p> for Py<'p, T> {
|
||||
fn gil(&self) -> Python<'p> {
|
||||
self.py
|
||||
}
|
||||
}
|
||||
|
||||
impl<'p, T> ToPythonPointer for Py<'p, T> {
|
||||
impl<'p, T> ToPyPointer for Py<'p, T> {
|
||||
/// Gets the underlying FFI pointer, returns a borrowed pointer.
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
|
@ -346,7 +346,7 @@ impl<'p, T> ToPythonPointer for Py<'p, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'p, T> IntoPythonPointer for Py<'p, T> {
|
||||
impl<'p, T> IntoPyPointer for Py<'p, T> {
|
||||
|
||||
/// Gets the underlying FFI pointer.
|
||||
/// Consumes `self` without calling `Py_DECREF()`, thus returning an owned pointer.
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::os::raw::c_int;
|
|||
|
||||
use ffi;
|
||||
use typeob::{PyTypeInfo, PyTypeObject, PyObjectAlloc};
|
||||
use token::{PythonToken};
|
||||
use token::{PyToken};
|
||||
use objects::{PyObject, PyObjectPtr, PyType, PyBool, PyDict, PyModule};
|
||||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
use pointers::{Py};
|
||||
|
@ -44,7 +44,7 @@ pub trait PyDowncastInto<'p> : Sized {
|
|||
|
||||
/// Cast Self to a concrete Python object type.
|
||||
fn downcast_into<I>(Python<'p>, I) -> Result<Self, PyDowncastError<'p>>
|
||||
where I: ToPythonPointer + IntoPythonPointer;
|
||||
where I: ToPyPointer + IntoPyPointer;
|
||||
|
||||
/// Cast from ffi::PyObject to a concrete Python object type.
|
||||
fn downcast_from_owned_ptr(py: Python<'p>, ptr: *mut ffi::PyObject)
|
||||
|
@ -70,14 +70,14 @@ pub trait Unpark<'p> : Sized {
|
|||
}
|
||||
|
||||
/// This trait allows retrieving the underlying FFI pointer from Python objects.
|
||||
pub trait ToPythonPointer {
|
||||
pub trait ToPyPointer {
|
||||
/// Retrieves the underlying FFI pointer (as a borrowed pointer).
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject;
|
||||
|
||||
}
|
||||
|
||||
/// This trait allows retrieving the underlying FFI pointer from Python objects.
|
||||
pub trait IntoPythonPointer {
|
||||
pub trait IntoPyPointer {
|
||||
/// Retrieves the underlying FFI pointer. Whether pointer owned or borrowed
|
||||
/// depends on implementation.
|
||||
fn into_ptr(self) -> *mut ffi::PyObject;
|
||||
|
@ -85,7 +85,7 @@ pub trait IntoPythonPointer {
|
|||
|
||||
|
||||
/// Convert None into a null pointer.
|
||||
impl<'p, T> ToPythonPointer for Option<&'p T> where T: ToPythonPointer {
|
||||
impl<'p, T> ToPyPointer for Option<&'p T> where T: ToPyPointer {
|
||||
#[inline]
|
||||
default fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
match *self {
|
||||
|
@ -96,7 +96,7 @@ impl<'p, T> ToPythonPointer for Option<&'p T> where T: ToPythonPointer {
|
|||
}
|
||||
|
||||
/// Convert None into a null pointer.
|
||||
impl <T> IntoPythonPointer for Option<T> where T: IntoPythonPointer {
|
||||
impl <T> IntoPyPointer for Option<T> where T: IntoPyPointer {
|
||||
#[inline]
|
||||
fn into_ptr(self) -> *mut ffi::PyObject {
|
||||
match self {
|
||||
|
@ -202,7 +202,7 @@ impl<'p> Python<'p> {
|
|||
}
|
||||
|
||||
pub fn with_token<T, F>(self, f: F) -> Py<'p, T>
|
||||
where F: FnOnce(PythonToken) -> T,
|
||||
where F: FnOnce(PyToken) -> T,
|
||||
T: PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
{
|
||||
::token::with_token(self, f)
|
||||
|
|
12
src/token.rs
12
src/token.rs
|
@ -8,9 +8,9 @@ use python::Python;
|
|||
use typeob::{PyTypeInfo, PyObjectAlloc};
|
||||
|
||||
|
||||
pub struct PythonToken(PhantomData<Rc<()>>);
|
||||
pub struct PyToken(PhantomData<Rc<()>>);
|
||||
|
||||
impl PythonToken {
|
||||
impl PyToken {
|
||||
pub fn token<'p>(&'p self) -> Python<'p> {
|
||||
unsafe { Python::assume_gil_acquired() }
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ impl PythonToken {
|
|||
|
||||
#[inline]
|
||||
pub fn with_token<'p, T, F>(py: Python<'p>, f: F) -> Py<'p, T>
|
||||
where F: FnOnce(PythonToken) -> T,
|
||||
where F: FnOnce(PyToken) -> T,
|
||||
T: PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
{
|
||||
let value = f(PythonToken(PhantomData));
|
||||
let value = f(PyToken(PhantomData));
|
||||
if let Ok(ob) = Py::new(py, value) {
|
||||
ob
|
||||
} else {
|
||||
|
@ -30,10 +30,10 @@ pub fn with_token<'p, T, F>(py: Python<'p>, f: F) -> Py<'p, T>
|
|||
}
|
||||
|
||||
|
||||
pub trait PythonObjectWithGilToken<'p> : Sized {
|
||||
pub trait PyObjectWithGilToken<'p> : Sized {
|
||||
fn gil(&self) -> Python<'p>;
|
||||
}
|
||||
|
||||
pub trait PythonObjectWithToken : Sized {
|
||||
pub trait PyObjectWithToken : Sized {
|
||||
fn token<'p>(&'p self) -> Python<'p>;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::cell::RefCell;
|
|||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use pyo3::ffi;
|
||||
use pyo3::python::ToPythonPointer;
|
||||
use pyo3::python::ToPyPointer;
|
||||
|
||||
|
||||
macro_rules! py_run {
|
||||
|
@ -69,7 +69,7 @@ fn empty_class_in_module() {
|
|||
|
||||
#[py::class]
|
||||
struct EmptyClassWithNew {
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::ptr(EmptyClassWithNew)]
|
||||
|
@ -94,7 +94,7 @@ fn empty_class_with_new() {
|
|||
#[py::class]
|
||||
struct NewWithOneArg {
|
||||
_data: i32,
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::ptr(NewWithOneArg)]
|
||||
|
@ -123,7 +123,7 @@ struct NewWithTwoArgs {
|
|||
_data1: i32,
|
||||
_data2: i32,
|
||||
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::ptr(NewWithTwoArgs)]
|
||||
|
@ -161,7 +161,7 @@ impl Drop for TestDropCall {
|
|||
struct DataIsDropped {
|
||||
member1: TestDropCall,
|
||||
member2: TestDropCall,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -187,7 +187,7 @@ fn data_is_dropped() {
|
|||
#[py::class]
|
||||
struct InstanceMethod {
|
||||
member: i32,
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::methods]
|
||||
|
@ -212,7 +212,7 @@ fn instance_method() {
|
|||
#[py::class]
|
||||
struct InstanceMethodWithArgs {
|
||||
member: i32,
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
#[py::methods]
|
||||
impl InstanceMethodWithArgs {
|
||||
|
@ -280,7 +280,7 @@ fn class_method() {
|
|||
|
||||
#[py::class]
|
||||
struct StaticMethod {
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::ptr(StaticMethod)]
|
||||
|
@ -334,7 +334,7 @@ impl StaticMethod {
|
|||
struct GCIntegration {
|
||||
self_ref: RefCell<PyObjectPtr>,
|
||||
dropped: TestDropCall,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::ptr(GCIntegration)]
|
||||
|
@ -372,7 +372,7 @@ fn gc_integration() {
|
|||
#[py::class]
|
||||
pub struct Len {
|
||||
l: usize,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -421,7 +421,7 @@ fn iterator() {
|
|||
}*/
|
||||
|
||||
#[py::class]
|
||||
struct StringMethods {token: PythonToken}
|
||||
struct StringMethods {token: PyToken}
|
||||
|
||||
#[py::proto]
|
||||
impl<'p> PyObjectProtocol<'p> for StringMethods {
|
||||
|
@ -462,7 +462,7 @@ fn string_methods() {
|
|||
#[py::class]
|
||||
struct Comparisons {
|
||||
val: i32,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -496,7 +496,7 @@ fn comparisons() {
|
|||
|
||||
#[py::class]
|
||||
struct Sequence {
|
||||
token: PythonToken}
|
||||
token: PyToken}
|
||||
|
||||
#[py::proto]
|
||||
impl PySequenceProtocol for Sequence {
|
||||
|
@ -524,7 +524,7 @@ fn sequence() {
|
|||
|
||||
|
||||
#[py::class]
|
||||
struct Callable {token: PythonToken}
|
||||
struct Callable {token: PyToken}
|
||||
|
||||
#[py::methods]
|
||||
impl Callable {
|
||||
|
@ -552,7 +552,7 @@ fn callable() {
|
|||
struct SetItem {
|
||||
key: i32,
|
||||
val: i32,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -579,7 +579,7 @@ fn setitem() {
|
|||
#[py::class]
|
||||
struct DelItem {
|
||||
key: i32,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -604,7 +604,7 @@ fn delitem() {
|
|||
#[py::class]
|
||||
struct SetDelItem {
|
||||
val: Option<i32>,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -633,7 +633,7 @@ fn setdelitem() {
|
|||
}
|
||||
|
||||
#[py::class]
|
||||
struct Reversed {token: PythonToken}
|
||||
struct Reversed {token: PyToken}
|
||||
|
||||
#[py::proto]
|
||||
impl PyMappingProtocol for Reversed{
|
||||
|
@ -652,7 +652,7 @@ fn reversed() {
|
|||
}
|
||||
|
||||
#[py::class]
|
||||
struct Contains {token: PythonToken}
|
||||
struct Contains {token: PyToken}
|
||||
|
||||
#[py::proto]
|
||||
impl PySequenceProtocol for Contains {
|
||||
|
@ -675,7 +675,7 @@ fn contains() {
|
|||
|
||||
|
||||
#[py::class]
|
||||
struct UnaryArithmetic {token: PythonToken}
|
||||
struct UnaryArithmetic {token: PyToken}
|
||||
|
||||
#[py::proto]
|
||||
impl PyNumberProtocol for UnaryArithmetic {
|
||||
|
@ -712,7 +712,7 @@ fn unary_arithmetic() {
|
|||
|
||||
#[py::class]
|
||||
struct BinaryArithmetic {
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -786,7 +786,7 @@ fn binary_arithmetic() {
|
|||
|
||||
#[py::class]
|
||||
struct RichComparisons {
|
||||
token: PythonToken
|
||||
token: PyToken
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -809,7 +809,7 @@ impl PyObjectProtocol for RichComparisons {
|
|||
|
||||
#[py::class]
|
||||
struct RichComparisons2 {
|
||||
py: PythonToken
|
||||
py: PyToken
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -883,7 +883,7 @@ fn rich_comparisons_python_3_type_error() {
|
|||
#[py::class]
|
||||
struct InPlaceOperations {
|
||||
value: u32,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::proto]
|
||||
|
@ -969,7 +969,7 @@ fn inplace_operations() {
|
|||
#[py::class]
|
||||
struct ContextManager {
|
||||
exit_called: bool,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
|
||||
|
@ -1016,7 +1016,7 @@ fn context_manager() {
|
|||
#[py::class]
|
||||
struct ClassWithProperties {
|
||||
num: i32,
|
||||
token: PythonToken,
|
||||
token: PyToken,
|
||||
}
|
||||
|
||||
#[py::methods]
|
||||
|
|
Loading…
Reference in New Issue