varios cleanups
This commit is contained in:
parent
a448aa54cc
commit
84f5578997
|
@ -22,6 +22,7 @@ exclude = [
|
|||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
libc = "0.2"
|
||||
num-traits = "0.1"
|
||||
pyo3cls = { path = "pyo3cls" }
|
||||
|
|
|
@ -49,25 +49,27 @@ 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 py = _pyo3::PyObjectWithToken::token(self);
|
||||
let ptr = <#cls as _pyo3::python::ToPyPointer>::as_ptr(self);
|
||||
let repr = unsafe {
|
||||
_pyo3::PyString::downcast_from_ptr(
|
||||
self.token(), _pyo3::ffi::PyObject_Repr(ptr))
|
||||
py, _pyo3::ffi::PyObject_Repr(ptr))
|
||||
.map_err(|_| std::fmt::Error)?
|
||||
};
|
||||
f.write_str(&repr.to_string_lossy(self.token()))
|
||||
f.write_str(&repr.to_string_lossy(py))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for #cls {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
let py = _pyo3::PyObjectWithToken::token(self);
|
||||
let ptr = <#cls as _pyo3::python::ToPyPointer>::as_ptr(self);
|
||||
let str_obj = unsafe {
|
||||
_pyo3::PyString::downcast_from_ptr(
|
||||
self.token(), _pyo3::ffi::PyObject_Str(ptr))
|
||||
py, _pyo3::ffi::PyObject_Str(ptr))
|
||||
.map_err(|_| std::fmt::Error)?
|
||||
};
|
||||
f.write_str(&str_obj.to_string_lossy(self.token()))
|
||||
f.write_str(&str_obj.to_string_lossy(py))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -122,7 +124,44 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident, token: Option<syn::Ident>) ->
|
|||
}
|
||||
}
|
||||
}
|
||||
impl _pyo3::python::PyMutDowncastFrom for #cls
|
||||
{
|
||||
fn downcast_mut_from<'a, 'p>(py: Python<'p>, ob: &'a mut _pyo3::PyObject)
|
||||
-> Result<&'a mut #cls, _pyo3::PyDowncastError<'p>>
|
||||
{
|
||||
unsafe {
|
||||
let checked = ffi::PyObject_TypeCheck(
|
||||
ob.as_ptr(), <#cls as _pyo3::typeob::PyTypeInfo>::type_object()) != 0;
|
||||
|
||||
if checked {
|
||||
let offset = <#cls as _pyo3::typeob::PyTypeInfo>::offset();
|
||||
let ptr = (ob.as_ptr() as *mut u8).offset(offset) as *mut #cls;
|
||||
Ok(ptr.as_mut().unwrap())
|
||||
} else {
|
||||
Err(_pyo3::PyDowncastError(py, None))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl _pyo3::ToPyObject for #cls
|
||||
{
|
||||
#[inline]
|
||||
fn to_object<'p>(&self, py: _pyo3::Python<'p>) -> _pyo3::PyObject {
|
||||
_pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_borrowed_ptr<F, R>(&self, _py: _pyo3::Python, f: F) -> R
|
||||
where F: FnOnce(*mut ffi::PyObject) -> R
|
||||
{
|
||||
f(self.as_ptr())
|
||||
}
|
||||
}
|
||||
impl std::convert::AsRef<PyObject> for #cls {
|
||||
fn as_ref(&self) -> &_pyo3::PyObject {
|
||||
unsafe{std::mem::transmute(self.as_ptr())}
|
||||
}
|
||||
}
|
||||
impl _pyo3::python::ToPyPointer for #cls {
|
||||
#[inline]
|
||||
fn as_ptr(&self) -> *mut ffi::PyObject {
|
||||
|
|
|
@ -260,7 +260,7 @@ fn impl_arg_param(arg: &FnArg, spec: &FnSpec, body: &Tokens) -> Tokens {
|
|||
|
||||
if spec.is_args(&name) {
|
||||
quote! {
|
||||
match <#ty as _pyo3::FromPyObject>::extract(py, &args)
|
||||
match <#ty as _pyo3::FromPyObject>::extract(py, &args.into())
|
||||
{
|
||||
Ok(#name) => {
|
||||
#body
|
||||
|
@ -310,7 +310,7 @@ fn impl_arg_param(arg: &FnArg, spec: &FnSpec, body: &Tokens) -> Tokens {
|
|||
quote! {
|
||||
match match _iter.next().unwrap().as_ref() {
|
||||
Some(obj) => {
|
||||
if obj.is_none() {
|
||||
if obj.is_none(py) {
|
||||
Ok(#default)
|
||||
} else {
|
||||
match obj.extract(py) {
|
||||
|
|
|
@ -19,10 +19,10 @@ pub fn build_ptr(cls: syn::Ident, ast: &mut syn::DeriveInput) -> Tokens {
|
|||
unsafe impl Send for #ptr {}
|
||||
unsafe impl Sync for #ptr {}
|
||||
|
||||
impl _pyo3::Park<#cls> for #cls {
|
||||
type ParkTarget = #ptr;
|
||||
impl _pyo3::ToInstancePtr<#cls> for #cls {
|
||||
type Target = #ptr;
|
||||
|
||||
fn park(&self) -> #ptr {
|
||||
fn to_inst_ptr(&self) -> #ptr {
|
||||
let token = _pyo3::PyObjectWithToken::token(self);
|
||||
let ptr = self.as_ptr();
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub fn build_ptr(cls: syn::Ident, ast: &mut syn::DeriveInput) -> Tokens {
|
|||
}
|
||||
}
|
||||
|
||||
impl _pyo3::PythonPtr<#cls> for #ptr {
|
||||
impl _pyo3::InstancePtr<#cls> for #ptr {
|
||||
|
||||
#[inline]
|
||||
fn as_ref(&self, _py: Python) -> &#cls {
|
||||
|
@ -64,7 +64,6 @@ pub fn build_ptr(cls: syn::Ident, ast: &mut syn::DeriveInput) -> Tokens {
|
|||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl _pyo3::PyClone for #ptr {
|
||||
fn clone_ref(&self, _py: _pyo3::Python) -> #ptr {
|
||||
#ptr(unsafe{ _pyo3::PyPtr::from_borrowed_ptr(self.as_ptr()) })
|
||||
|
@ -88,6 +87,39 @@ pub fn build_ptr(cls: syn::Ident, ast: &mut syn::DeriveInput) -> Tokens {
|
|||
self.0.into_ptr()
|
||||
}
|
||||
}
|
||||
impl _pyo3::PyDowncastInto for #ptr
|
||||
{
|
||||
fn downcast_into<'p, I>(py: _pyo3::Python<'p>, ob: I)
|
||||
-> Result<Self, _pyo3::PyDowncastError<'p>>
|
||||
where I: _pyo3::IntoPyPointer
|
||||
{
|
||||
<#ptr as _pyo3::PyDowncastInto>::downcast_from_ptr(py, ob.into_ptr())
|
||||
}
|
||||
|
||||
fn downcast_from_ptr<'p>(py: _pyo3::Python<'p>, ptr: *mut _pyo3::ffi::PyObject)
|
||||
-> Result<#ptr, _pyo3::PyDowncastError<'p>>
|
||||
{
|
||||
unsafe{
|
||||
let checked = ffi::PyObject_TypeCheck(
|
||||
ptr, <#cls as _pyo3::typeob::PyTypeInfo>::type_object()) != 0;
|
||||
|
||||
if checked {
|
||||
Ok(#ptr(PyPtr::from_owned_ptr(ptr)))
|
||||
} else {
|
||||
_pyo3::ffi::Py_DECREF(ptr);
|
||||
Err(_pyo3::PyDowncastError(py, None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn unchecked_downcast_into<'p, I>(ob: I) -> Self where I: _pyo3::IntoPyPointer
|
||||
{
|
||||
unsafe{
|
||||
#ptr(_pyo3::PyPtr::from_owned_ptr(ob.into_ptr()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<#ptr> for _pyo3::PyObject {
|
||||
fn from(ob: #ptr) -> Self {
|
||||
unsafe{std::mem::transmute(ob)}
|
||||
|
|
|
@ -450,16 +450,16 @@ pub fn with_extracted_or_default<'p, P: ?Sized, R, F>(
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use python::{Python};
|
||||
use python::Python;
|
||||
use objects::PyTuple;
|
||||
use conversion::{ToPyTuple};
|
||||
use conversion::IntoPyTuple;
|
||||
|
||||
#[test]
|
||||
pub fn test_parse() {
|
||||
let gil_guard = Python::acquire_gil();
|
||||
let py = gil_guard.python();
|
||||
let mut called = false;
|
||||
let tuple = ("abc", 42).to_py_tuple(py);
|
||||
let tuple = ("abc", 42).into_tuple(py);
|
||||
py_argparse!(py, None, &tuple, None, (x: &str, y: i32) {
|
||||
assert_eq!(x, "abc");
|
||||
assert_eq!(y, 42);
|
||||
|
@ -474,7 +474,7 @@ mod test {
|
|||
let gil_guard = Python::acquire_gil();
|
||||
let py = gil_guard.python();
|
||||
let mut called = false;
|
||||
let tuple = ("abc",).to_py_tuple(py);
|
||||
let tuple = ("abc",).into_tuple(py);
|
||||
py_argparse!(py, None, &tuple, None, (x) {
|
||||
assert_eq!(*x, tuple.get_item(py, 0));
|
||||
called = true;
|
||||
|
@ -488,7 +488,7 @@ mod test {
|
|||
let gil_guard = Python::acquire_gil();
|
||||
let py = gil_guard.python();
|
||||
let mut called = false;
|
||||
let tuple = (0, "foo").to_py_tuple(py);
|
||||
let tuple = (0, "foo").into_tuple(py);
|
||||
py_argparse!(py, None, &tuple, None, (x: usize = 42, y: &str = "abc") {
|
||||
assert_eq!(x, 0);
|
||||
assert_eq!(y, "foo");
|
||||
|
|
|
@ -9,7 +9,7 @@ use objects::exc;
|
|||
use conversion::IntoPyObject;
|
||||
use ffi::{self, Py_hash_t};
|
||||
use err::{PyErr, PyResult};
|
||||
use token::{Park, PythonPtr};
|
||||
use token::{InstancePtr, ToInstancePtr};
|
||||
use typeob::PyTypeInfo;
|
||||
|
||||
|
||||
|
@ -199,7 +199,7 @@ pub unsafe fn cb_unary<Slf, F, T, C>(location: &str,
|
|||
slf: *mut ffi::PyObject, _c: C, f: F) -> C::R
|
||||
where F: for<'p> FnOnce(Python<'p>, &'p mut Slf) -> PyResult<T>,
|
||||
F: panic::UnwindSafe,
|
||||
Slf: PyTypeInfo + Park<Slf>,
|
||||
Slf: PyTypeInfo + ToInstancePtr<Slf>,
|
||||
C: CallbackConverter<T>
|
||||
{
|
||||
let guard = AbortOnDrop(location);
|
||||
|
@ -234,7 +234,7 @@ pub unsafe fn cb_unary<Slf, F, T, C>(location: &str,
|
|||
pub unsafe fn cb_unary_unit<Slf, F>(location: &str, slf: *mut ffi::PyObject, f: F) -> c_int
|
||||
where F: for<'p> FnOnce(Python<'p>, &'p mut Slf) -> c_int,
|
||||
F: panic::UnwindSafe,
|
||||
Slf: PyTypeInfo + Park<Slf>,
|
||||
Slf: PyTypeInfo + ToInstancePtr<Slf>,
|
||||
{
|
||||
let guard = AbortOnDrop(location);
|
||||
let ret = panic::catch_unwind(|| {
|
||||
|
|
|
@ -10,7 +10,7 @@ use ffi;
|
|||
use err::PyResult;
|
||||
use python::Python;
|
||||
use callback::PyObjectCallbackConverter;
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use typeob::PyTypeInfo;
|
||||
use class::methods::PyMethodDef;
|
||||
|
||||
|
@ -125,7 +125,7 @@ impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyAsyncAwaitProtocolImpl for T where T: for<'p> PyAsyncAwaitProtocol<'p> + Park<T>
|
||||
impl<T> PyAsyncAwaitProtocolImpl for T where T: for<'p> PyAsyncAwaitProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn am_await() -> Option<ffi::unaryfunc> {
|
||||
|
@ -146,7 +146,7 @@ impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyAsyncAiterProtocolImpl for T where T: for<'p> PyAsyncAiterProtocol<'p> + Park<T>
|
||||
impl<T> PyAsyncAiterProtocolImpl for T where T: for<'p> PyAsyncAiterProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn am_aiter() -> Option<ffi::unaryfunc> {
|
||||
|
@ -167,7 +167,7 @@ impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyAsyncAnextProtocolImpl for T where T: for<'p> PyAsyncAnextProtocol<'p> + Park<T>
|
||||
impl<T> PyAsyncAnextProtocolImpl for T where T: for<'p> PyAsyncAnextProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn am_anext() -> Option<ffi::unaryfunc> {
|
||||
|
|
|
@ -14,7 +14,7 @@ use err::{PyErr, PyResult};
|
|||
use python::{Python, IntoPyPointer};
|
||||
use objects::PyObject;
|
||||
use objects::exc;
|
||||
use token::{Park, PythonPtr};
|
||||
use token::{InstancePtr, ToInstancePtr};
|
||||
use typeob::PyTypeInfo;
|
||||
use conversion::{FromPyObject, IntoPyObject};
|
||||
use callback::{PyObjectCallbackConverter, HashConverter, BoolCallbackConverter};
|
||||
|
@ -165,7 +165,7 @@ impl<'p, T> PyObjectGetAttrProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectGetAttrProtocolImpl for T where T: for<'p> PyObjectGetAttrProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectGetAttrProtocolImpl for T where T: for<'p> PyObjectGetAttrProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_getattro() -> Option<ffi::binaryfunc> {
|
||||
|
@ -186,7 +186,7 @@ impl<'p, T> PyObjectSetAttrProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_setattro() -> Option<ffi::setattrofunc> {
|
||||
|
@ -205,7 +205,7 @@ impl<'p, T> PyObjectDelAttrProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
default fn tp_delattro() -> Option<ffi::setattrofunc> {
|
||||
|
@ -213,7 +213,7 @@ impl<T> PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtoc
|
|||
}
|
||||
}
|
||||
impl<T> PyObjectDelAttrProtocolImpl for T
|
||||
where T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_delattro() -> Option<ffi::setattrofunc> {
|
||||
|
@ -233,7 +233,7 @@ impl<'p, T> PyObjectStrProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectStrProtocolImpl for T where T: for<'p> PyObjectStrProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectStrProtocolImpl for T where T: for<'p> PyObjectStrProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_str() -> Option<ffi::unaryfunc> {
|
||||
|
@ -252,7 +252,7 @@ impl<'p, T> PyObjectReprProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_repr() -> Option<ffi::unaryfunc> {
|
||||
|
@ -296,7 +296,7 @@ impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectHashProtocolImpl for T where T: for<'p> PyObjectHashProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectHashProtocolImpl for T where T: for<'p> PyObjectHashProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_hash() -> Option<ffi::hashfunc> {
|
||||
|
@ -315,7 +315,7 @@ impl<'p, T> PyObjectBoolProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyObjectBoolProtocolImpl for T where T: for<'p> PyObjectBoolProtocol<'p> + Park<T>
|
||||
impl<T> PyObjectBoolProtocolImpl for T where T: for<'p> PyObjectBoolProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn nb_bool() -> Option<ffi::inquiry> {
|
||||
|
@ -334,14 +334,14 @@ impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p>
|
|||
}
|
||||
}
|
||||
impl<T> PyObjectRichcmpProtocolImpl for T
|
||||
where T: for<'p> PyObjectRichcmpProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyObjectRichcmpProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_richcompare() -> Option<ffi::richcmpfunc> {
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
arg: *mut ffi::PyObject,
|
||||
op: c_int) -> *mut ffi::PyObject
|
||||
where T: for<'p> PyObjectRichcmpProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyObjectRichcmpProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!(T), ".__richcmp__()");
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::os::raw::c_int;
|
|||
use ffi;
|
||||
use err::PyResult;
|
||||
use python::Python;
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use typeob::PyTypeInfo;
|
||||
use callback::UnitCallbackConverter;
|
||||
|
||||
|
@ -45,7 +45,7 @@ impl<T> PyBufferProtocolImpl for T {
|
|||
default fn tp_as_buffer() -> Option<ffi::PyBufferProcs> { None }
|
||||
}
|
||||
|
||||
impl<'p, T> PyBufferProtocolImpl for T where T: PyBufferProtocol<'p> + Park<T>
|
||||
impl<'p, T> PyBufferProtocolImpl for T where T: PyBufferProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_as_buffer() -> Option<ffi::PyBufferProcs> {
|
||||
|
@ -69,14 +69,14 @@ impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PyBufferGetBufferProtocolImpl for T
|
||||
where T: for<'p> PyBufferGetBufferProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyBufferGetBufferProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> {
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
arg1: *mut ffi::Py_buffer,
|
||||
arg2: c_int) -> c_int
|
||||
where T: for<'p> PyBufferGetBufferProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyBufferGetBufferProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!(T), ".buffer_get::<PyBufferProtocol>()");
|
||||
::callback::cb_unary::<T, _, _, _>(LOCATION, slf, UnitCallbackConverter, |py, slf| {
|
||||
|
|
|
@ -13,7 +13,7 @@ use python::Python;
|
|||
use objects::{PyType, PyObject};
|
||||
use callback::{PyObjectCallbackConverter, UnitCallbackConverter};
|
||||
use typeob::PyTypeInfo;
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use class::methods::PyMethodDef;
|
||||
use conversion::{IntoPyObject, FromPyObject};
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl<'p, T> PyDescrGetProtocolImpl for T where T: PyDescrProtocol<'p> {
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyDescrGetProtocolImpl for T where T: for<'p> PyDescrGetProtocol<'p> + Park<T>
|
||||
impl<T> PyDescrGetProtocolImpl for T where T: for<'p> PyDescrGetProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn tp_descr_get() -> Option<ffi::descrgetfunc> {
|
||||
py_ternary_func!(PyDescrGetProtocol, T::__get__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -81,7 +81,7 @@ impl<'p, T> PyDescrSetProtocolImpl for T where T: PyDescrProtocol<'p> {
|
|||
None
|
||||
}
|
||||
}
|
||||
impl<T> PyDescrSetProtocolImpl for T where T: for<'p> PyDescrSetProtocol<'p> + Park<T>
|
||||
impl<T> PyDescrSetProtocolImpl for T where T: for<'p> PyDescrSetProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn tp_descr_set() -> Option<ffi::descrsetfunc> {
|
||||
py_ternary_func!(PyDescrSetProtocol, T::__set__, (), UnitCallbackConverter, c_int)
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::os::raw::{c_int, c_void};
|
|||
use ffi;
|
||||
use python::{Python, ToPyPointer};
|
||||
use callback::AbortOnDrop;
|
||||
use token::{Park, PythonPtr};
|
||||
use token::{InstancePtr, ToInstancePtr};
|
||||
use typeob::PyTypeInfo;
|
||||
|
||||
pub struct PyTraverseError(c_int);
|
||||
|
@ -93,14 +93,14 @@ impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p>
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl<T> PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p> + Park<T>
|
||||
impl<T> PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_traverse() -> Option<ffi::traverseproc> {
|
||||
unsafe extern "C" fn tp_traverse<T>(slf: *mut ffi::PyObject,
|
||||
visit: ffi::visitproc,
|
||||
arg: *mut c_void) -> c_int
|
||||
where T: for<'p> PyGCTraverseProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyGCTraverseProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!(T), ".__traverse__()");
|
||||
|
||||
|
@ -134,12 +134,12 @@ impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p> + Park<T>
|
||||
impl<T> PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_clear() -> Option<ffi::inquiry> {
|
||||
unsafe extern "C" fn tp_clear<T>(slf: *mut ffi::PyObject) -> c_int
|
||||
where T: for<'p> PyGCClearProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyGCClearProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!(T), ".__clear__()");
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
use ffi;
|
||||
use err::PyResult;
|
||||
use python::Python;
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use typeob::PyTypeInfo;
|
||||
use callback::PyObjectCallbackConverter;
|
||||
|
||||
|
@ -66,7 +66,7 @@ impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyIterIterProtocolImpl for T where T: for<'p> PyIterIterProtocol<'p> + Park<T>
|
||||
impl<T> PyIterIterProtocolImpl for T where T: for<'p> PyIterIterProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_iter() -> Option<ffi::getiterfunc> {
|
||||
|
@ -87,7 +87,7 @@ impl<'p, T> PyIterNextProtocolImpl for T
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyIterNextProtocolImpl for T where T: for<'p> PyIterNextProtocol<'p> + Park<T>
|
||||
impl<T> PyIterNextProtocolImpl for T where T: for<'p> PyIterNextProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn tp_iternext() -> Option<ffi::iternextfunc> {
|
||||
|
|
|
@ -8,9 +8,9 @@ macro_rules! py_unary_func {
|
|||
};
|
||||
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:ty, $ret_type:ty) => {{
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject) -> $ret_type
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
|
@ -57,9 +57,9 @@ macro_rules! py_unary_func {
|
|||
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:ty) => {{
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject)
|
||||
-> *mut $crate::ffi::PyObject
|
||||
where T: for<'p> $trait<'p> + Park<T>
|
||||
where T: for<'p> $trait<'p> + ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
|
@ -107,7 +107,7 @@ macro_rules! py_len_func {
|
|||
($trait:ident, $class:ident :: $f:ident, $conv:expr) => {{
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject)
|
||||
-> $crate::ffi::Py_ssize_t
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
$crate::callback::cb_unary::<T, _, _, _>(LOCATION, slf, $conv, |py, slf| {
|
||||
|
@ -128,9 +128,9 @@ macro_rules! py_binary_func{
|
|||
#[allow(unused_mut)]
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
arg: *mut ffi::PyObject) -> $return
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
|
@ -186,9 +186,9 @@ macro_rules! py_binary_self_func{
|
|||
#[allow(unused_mut)]
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
arg: *mut ffi::PyObject) -> *mut $crate::ffi::PyObject
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
|
@ -243,9 +243,9 @@ macro_rules! py_ssizearg_func {
|
|||
#[allow(unused_mut)]
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
arg: $crate::Py_ssize_t) -> *mut $crate::ffi::PyObject
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
|
@ -296,9 +296,9 @@ macro_rules! py_ternary_func{
|
|||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
|
||||
arg1: *mut $crate::ffi::PyObject,
|
||||
arg2: *mut $crate::ffi::PyObject) -> $return_type
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
let ret = $crate::std::panic::catch_unwind(|| {
|
||||
|
@ -359,9 +359,9 @@ macro_rules! py_ternary_self_func{
|
|||
arg1: *mut $crate::ffi::PyObject,
|
||||
arg2: *mut $crate::ffi::PyObject)
|
||||
-> *mut $crate::ffi::PyObject
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
let ret = $crate::std::panic::catch_unwind(|| {
|
||||
|
@ -417,7 +417,7 @@ macro_rules! py_func_set{
|
|||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
|
||||
name: *mut $crate::ffi::PyObject,
|
||||
value: *mut $crate::ffi::PyObject) -> $crate::c_int
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
$crate::callback::cb_unary_unit::<T, _>(LOCATION, slf, |py, slf| {
|
||||
|
@ -467,9 +467,9 @@ macro_rules! py_func_del{
|
|||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
|
||||
name: *mut $crate::ffi::PyObject,
|
||||
value: *mut $crate::ffi::PyObject) -> $crate::c_int
|
||||
where T: for<'p> $trait<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
let ret = $crate::std::panic::catch_unwind(|| {
|
||||
|
@ -530,9 +530,9 @@ macro_rules! py_func_set_del{
|
|||
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
|
||||
name: *mut $crate::ffi::PyObject,
|
||||
value: *mut $crate::ffi::PyObject) -> $crate::c_int
|
||||
where T: for<'p> $trait<'p> + for<'p> $trait2<'p> + $crate::Park<T>
|
||||
where T: for<'p> $trait<'p> + for<'p> $trait2<'p> + $crate::ToInstancePtr<T>
|
||||
{
|
||||
use token::PythonPtr;
|
||||
use token::InstancePtr;
|
||||
const LOCATION: &'static str = concat!(stringify!($class), ".", stringify!($f), "()");
|
||||
let guard = $crate::callback::AbortOnDrop(LOCATION);
|
||||
let ret = $crate::std::panic::catch_unwind(|| {
|
||||
|
|
|
@ -9,7 +9,7 @@ use python::Python;
|
|||
use objects::{exc, PyObject};
|
||||
use callback::{PyObjectCallbackConverter, LenResultConverter};
|
||||
use conversion::{IntoPyObject, FromPyObject};
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use typeob::PyTypeInfo;
|
||||
use class::methods::PyMethodDef;
|
||||
|
||||
|
@ -144,7 +144,7 @@ impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyMappingLenProtocolImpl for T where T: for<'p> PyMappingLenProtocol<'p> + Park<T>
|
||||
impl<T> PyMappingLenProtocolImpl for T where T: for<'p> PyMappingLenProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn mp_length() -> Option<ffi::lenfunc> {
|
||||
|
@ -164,7 +164,7 @@ impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyMappingGetItemProtocolImpl for T where T: for<'p> PyMappingGetItemProtocol<'p> + Park<T>
|
||||
impl<T> PyMappingGetItemProtocolImpl for T where T: for<'p> PyMappingGetItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn mp_subscript() -> Option<ffi::binaryfunc> {
|
||||
|
@ -185,7 +185,7 @@ impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProtocol<'p> + Park<T>
|
||||
impl<T> PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn mp_ass_subscript() -> Option<ffi::objobjargproc> {
|
||||
|
@ -206,7 +206,7 @@ impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProtocol<'p> + Park<T>
|
||||
impl<T> PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
default fn mp_del_subscript() -> Option<ffi::objobjargproc> {
|
||||
|
@ -216,7 +216,7 @@ impl<T> PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProt
|
|||
|
||||
|
||||
impl<T> PyMappingDelItemProtocolImpl for T
|
||||
where T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn mp_del_subscript() -> Option<ffi::objobjargproc> {
|
||||
|
|
|
@ -10,7 +10,7 @@ use callback::PyObjectCallbackConverter;
|
|||
use typeob::PyTypeInfo;
|
||||
use class::methods::PyMethodDef;
|
||||
use class::basic::PyObjectProtocolImpl;
|
||||
use ::{c_void, IntoPyObject, FromPyObject, Park};
|
||||
use ::{c_void, IntoPyObject, FromPyObject, ToInstancePtr};
|
||||
|
||||
/// Number interface
|
||||
#[allow(unused_variables)]
|
||||
|
@ -495,7 +495,7 @@ trait PyNumberAddProtocolImpl {
|
|||
impl<'p, T> PyNumberAddProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_add() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberAddProtocolImpl for T where T: for<'p> PyNumberAddProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberAddProtocolImpl for T where T: for<'p> PyNumberAddProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_add() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberAddProtocol, T::__add__, T::Success, PyObjectCallbackConverter)
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ trait PyNumberSubProtocolImpl {
|
|||
impl<'p, T> PyNumberSubProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_subtract() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberSubProtocolImpl for T where T: for<'p> PyNumberSubProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberSubProtocolImpl for T where T: for<'p> PyNumberSubProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_subtract() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberSubProtocol, T::__sub__, T::Success, PyObjectCallbackConverter)
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ trait PyNumberMulProtocolImpl {
|
|||
impl<'p, T> PyNumberMulProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_multiply() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberMulProtocolImpl for T where T: for<'p> PyNumberMulProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberMulProtocolImpl for T where T: for<'p> PyNumberMulProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_multiply() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberMulProtocol, T::__mul__, T::Success, PyObjectCallbackConverter)
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ trait PyNumberMatmulProtocolImpl {
|
|||
impl<'p, T> PyNumberMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_matrix_multiply() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberMatmulProtocolImpl for T where T: for<'p> PyNumberMatmulProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberMatmulProtocolImpl for T where T: for<'p> PyNumberMatmulProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_matrix_multiply() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberMatmulProtocol,
|
||||
T::__matmul__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -545,7 +545,7 @@ impl<'p, T> PyNumberTruedivProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_true_divide() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberTruedivProtocolImpl for T
|
||||
where T: for<'p> PyNumberTruedivProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberTruedivProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_true_divide() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberTruedivProtocol,
|
||||
|
@ -560,7 +560,7 @@ impl<'p, T> PyNumberFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_floor_divide() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberFloordivProtocolImpl for T
|
||||
where T: for<'p> PyNumberFloordivProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberFloordivProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_floor_divide() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberFloordivProtocol,
|
||||
|
@ -574,7 +574,7 @@ trait PyNumberModProtocolImpl {
|
|||
impl<'p, T> PyNumberModProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_remainder() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberModProtocolImpl for T where T: for<'p> PyNumberModProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberModProtocolImpl for T where T: for<'p> PyNumberModProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_remainder() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberModProtocol, T::__mod__, T::Success, PyObjectCallbackConverter)
|
||||
}
|
||||
|
@ -586,7 +586,7 @@ trait PyNumberDivmodProtocolImpl {
|
|||
impl<'p, T> PyNumberDivmodProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_divmod() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberDivmodProtocolImpl for T where T: for<'p> PyNumberDivmodProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberDivmodProtocolImpl for T where T: for<'p> PyNumberDivmodProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_divmod() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberDivmodProtocol,
|
||||
T::__divmod__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -599,7 +599,7 @@ trait PyNumberPowProtocolImpl {
|
|||
impl<'p, T> PyNumberPowProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_power() -> Option<ffi::ternaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberPowProtocolImpl for T where T: for<'p> PyNumberPowProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberPowProtocolImpl for T where T: for<'p> PyNumberPowProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_power() -> Option<ffi::ternaryfunc> {
|
||||
py_ternary_func!(PyNumberPowProtocol,
|
||||
T::__pow__, <T as PyNumberPowProtocol>::Success,
|
||||
|
@ -613,7 +613,7 @@ trait PyNumberLShiftProtocolImpl {
|
|||
impl<'p, T> PyNumberLShiftProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_lshift() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberLShiftProtocolImpl for T where T: for<'p> PyNumberLShiftProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberLShiftProtocolImpl for T where T: for<'p> PyNumberLShiftProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_lshift() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberLShiftProtocol,
|
||||
T::__lshift__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -626,7 +626,7 @@ trait PyNumberRShiftProtocolImpl {
|
|||
impl<'p, T> PyNumberRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_rshift() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberRShiftProtocolImpl for T where T: for<'p> PyNumberRShiftProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberRShiftProtocolImpl for T where T: for<'p> PyNumberRShiftProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_rshift() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberRShiftProtocol,
|
||||
T::__rshift__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -640,7 +640,7 @@ trait PyNumberAndProtocolImpl {
|
|||
impl<'p, T> PyNumberAndProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_and() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberAndProtocolImpl for T where T: for<'p> PyNumberAndProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberAndProtocolImpl for T where T: for<'p> PyNumberAndProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_and() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberAndProtocol,
|
||||
T::__and__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -653,7 +653,7 @@ trait PyNumberXorProtocolImpl {
|
|||
impl<'p, T> PyNumberXorProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_xor() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberXorProtocolImpl for T where T: for<'p> PyNumberXorProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberXorProtocolImpl for T where T: for<'p> PyNumberXorProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_xor() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberXorProtocol,
|
||||
T::__xor__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -666,7 +666,7 @@ trait PyNumberOrProtocolImpl {
|
|||
impl<'p, T> PyNumberOrProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_or() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberOrProtocolImpl for T where T: for<'p> PyNumberOrProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberOrProtocolImpl for T where T: for<'p> PyNumberOrProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_or() -> Option<ffi::binaryfunc> {
|
||||
py_binary_func!(PyNumberOrProtocol,
|
||||
T::__or__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -680,7 +680,7 @@ trait PyNumberIAddProtocolImpl {
|
|||
impl<'p, T> PyNumberIAddProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_add() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIAddProtocolImpl for T where T: for<'p> PyNumberIAddProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIAddProtocolImpl for T where T: for<'p> PyNumberIAddProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_add() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIAddProtocol, T::__iadd__)
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ trait PyNumberISubProtocolImpl {
|
|||
impl<'p, T> PyNumberISubProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_subtract() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberISubProtocolImpl for T where T: for<'p> PyNumberISubProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberISubProtocolImpl for T where T: for<'p> PyNumberISubProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_subtract() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberISubProtocol, T::__isub__)
|
||||
}
|
||||
|
@ -704,7 +704,7 @@ trait PyNumberIMulProtocolImpl {
|
|||
impl<'p, T> PyNumberIMulProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_multiply() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIMulProtocolImpl for T where T: for<'p> PyNumberIMulProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIMulProtocolImpl for T where T: for<'p> PyNumberIMulProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_multiply() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIMulProtocol, T::__imul__)
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ impl<'p, T> PyNumberIMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIMatmulProtocolImpl for T
|
||||
where T: for<'p> PyNumberIMatmulProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberIMatmulProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIMatmulProtocol, T::__imatmul__)
|
||||
|
@ -731,7 +731,7 @@ impl<'p, T> PyNumberITruedivProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_inplace_true_divide() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberITruedivProtocolImpl for T
|
||||
where T: for<'p> PyNumberITruedivProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberITruedivProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_inplace_true_divide() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberITruedivProtocol, T::__itruediv__)
|
||||
|
@ -745,7 +745,7 @@ impl<'p, T> PyNumberIFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIFloordivProtocolImpl for T
|
||||
where T: for<'p> PyNumberIFloordivProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberIFloordivProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIFloordivProtocol, T::__ifloordiv__)
|
||||
|
@ -758,7 +758,7 @@ trait PyNumberIModProtocolImpl {
|
|||
impl<'p, T> PyNumberIModProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_remainder() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIModProtocolImpl for T where T: for<'p> PyNumberIModProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIModProtocolImpl for T where T: for<'p> PyNumberIModProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_remainder() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIModProtocol, T::__imod__)
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ trait PyNumberIPowProtocolImpl {
|
|||
impl<'p, T> PyNumberIPowProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_power() -> Option<ffi::ternaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIPowProtocolImpl for T where T: for<'p> PyNumberIPowProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIPowProtocolImpl for T where T: for<'p> PyNumberIPowProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_power() -> Option<ffi::ternaryfunc> {
|
||||
py_ternary_self_func!(PyNumberIPowProtocol, T::__ipow__)
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ impl<'p, T> PyNumberILShiftProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_inplace_lshift() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberILShiftProtocolImpl for T
|
||||
where T: for<'p> PyNumberILShiftProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberILShiftProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_inplace_lshift() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberILShiftProtocol, T::__ilshift__)
|
||||
|
@ -797,7 +797,7 @@ impl<'p, T> PyNumberIRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_inplace_rshift() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIRShiftProtocolImpl for T
|
||||
where T: for<'p> PyNumberIRShiftProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberIRShiftProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_inplace_rshift() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIRShiftProtocol, T::__irshift__)
|
||||
|
@ -811,7 +811,7 @@ trait PyNumberIAndProtocolImpl {
|
|||
impl<'p, T> PyNumberIAndProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_and() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIAndProtocolImpl for T where T: for<'p> PyNumberIAndProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIAndProtocolImpl for T where T: for<'p> PyNumberIAndProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_and() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIAndProtocol, T::__iand__)
|
||||
}
|
||||
|
@ -823,7 +823,7 @@ trait PyNumberIXorProtocolImpl {
|
|||
impl<'p, T> PyNumberIXorProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_xor() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIXorProtocolImpl for T where T: for<'p> PyNumberIXorProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIXorProtocolImpl for T where T: for<'p> PyNumberIXorProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_xor() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIXorProtocol, T::__ixor__)
|
||||
}
|
||||
|
@ -835,7 +835,7 @@ trait PyNumberIOrProtocolImpl {
|
|||
impl<'p, T> PyNumberIOrProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_inplace_or() -> Option<ffi::binaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIOrProtocolImpl for T where T: for<'p> PyNumberIOrProtocol<'p> + Park<T> {
|
||||
impl<T> PyNumberIOrProtocolImpl for T where T: for<'p> PyNumberIOrProtocol<'p> + ToInstancePtr<T> {
|
||||
fn nb_inplace_or() -> Option<ffi::binaryfunc> {
|
||||
py_binary_self_func!(PyNumberIOrProtocol, T::__ior__)
|
||||
}
|
||||
|
@ -947,7 +947,7 @@ trait PyNumberNegProtocolImpl {
|
|||
impl<'p, T> PyNumberNegProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_negative() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberNegProtocolImpl for T where T: for<'p> PyNumberNegProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberNegProtocolImpl for T where T: for<'p> PyNumberNegProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn nb_negative() -> Option<ffi::unaryfunc> {
|
||||
|
@ -961,7 +961,7 @@ trait PyNumberPosProtocolImpl {
|
|||
impl<'p, T> PyNumberPosProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_positive() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberPosProtocolImpl for T where T: for<'p> PyNumberPosProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberPosProtocolImpl for T where T: for<'p> PyNumberPosProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_positive() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberPosProtocol, T::__pos__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -974,7 +974,7 @@ trait PyNumberAbsProtocolImpl {
|
|||
impl<'p, T> PyNumberAbsProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_absolute() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberAbsProtocolImpl for T where T: for<'p> PyNumberAbsProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberAbsProtocolImpl for T where T: for<'p> PyNumberAbsProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_absolute() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberAbsProtocol, T::__abs__, T::Success, PyObjectCallbackConverter)
|
||||
|
@ -987,7 +987,7 @@ trait PyNumberInvertProtocolImpl {
|
|||
impl<'p, T> PyNumberInvertProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_invert() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberInvertProtocolImpl for T where T: for<'p> PyNumberInvertProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberInvertProtocolImpl for T where T: for<'p> PyNumberInvertProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_invert() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberInvertProtocol, T::__invert__,
|
||||
|
@ -1001,7 +1001,7 @@ trait PyNumberIntProtocolImpl {
|
|||
impl<'p, T> PyNumberIntProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_int() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIntProtocolImpl for T where T: for<'p> PyNumberIntProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberIntProtocolImpl for T where T: for<'p> PyNumberIntProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_int() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberIntProtocol, T::__int__,
|
||||
|
@ -1015,7 +1015,7 @@ trait PyNumberFloatProtocolImpl {
|
|||
impl<'p, T> PyNumberFloatProtocolImpl for T where T: PyNumberProtocol<'p> {
|
||||
default fn nb_float() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberFloatProtocolImpl for T where T: for<'p> PyNumberFloatProtocol<'p> + Park<T>
|
||||
impl<T> PyNumberFloatProtocolImpl for T where T: for<'p> PyNumberFloatProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_float() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberFloatProtocol, T::__float__,
|
||||
|
@ -1030,7 +1030,7 @@ impl<'p, T> PyNumberIndexProtocolImpl for T where T: PyNumberProtocol<'p> {
|
|||
default fn nb_index() -> Option<ffi::unaryfunc> {None}
|
||||
}
|
||||
impl<T> PyNumberIndexProtocolImpl for T
|
||||
where T: for<'p> PyNumberIndexProtocol<'p> + Park<T>
|
||||
where T: for<'p> PyNumberIndexProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
fn nb_index() -> Option<ffi::unaryfunc> {
|
||||
py_unary_func!(PyNumberIndexProtocol,
|
||||
|
|
|
@ -11,7 +11,7 @@ use err::{PyErr, PyResult};
|
|||
use objects::exc;
|
||||
use objects::PyObject;
|
||||
use callback::{PyObjectCallbackConverter, LenResultConverter, BoolCallbackConverter};
|
||||
use token::Park;
|
||||
use token::ToInstancePtr;
|
||||
use typeob::PyTypeInfo;
|
||||
use conversion::{IntoPyObject, FromPyObject};
|
||||
|
||||
|
@ -141,7 +141,7 @@ impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PySequenceLenProtocolImpl for T where T: for<'p> PySequenceLenProtocol<'p> + Park<T>
|
||||
impl<T> PySequenceLenProtocolImpl for T where T: for<'p> PySequenceLenProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_length() -> Option<ffi::lenfunc> {
|
||||
|
@ -162,7 +162,7 @@ impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PySequenceGetItemProtocolImpl for T
|
||||
where T: for<'p> PySequenceGetItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceGetItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_item() -> Option<ffi::ssizeargfunc> {
|
||||
|
@ -184,14 +184,14 @@ impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PySequenceSetItemProtocolImpl for T
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_ass_item() -> Option<ffi::ssizeobjargproc> {
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
key: ffi::Py_ssize_t,
|
||||
value: *mut ffi::PyObject) -> c_int
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = "foo.__setitem__()";
|
||||
::callback::cb_unary_unit::<T, _>(LOCATION, slf, |py, slf| {
|
||||
|
@ -235,14 +235,14 @@ impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PySequenceDelItemProtocolImpl for T
|
||||
where T: for<'p> PySequenceDelItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
default fn sq_del_item() -> Option<ffi::ssizeobjargproc> {
|
||||
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
|
||||
key: ffi::Py_ssize_t,
|
||||
value: *mut ffi::PyObject) -> c_int
|
||||
where T: for<'p> PySequenceDelItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = "T.__detitem__()";
|
||||
::callback::cb_unary_unit::<T, _>(LOCATION, slf, |py, slf| {
|
||||
|
@ -269,7 +269,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
}
|
||||
|
||||
impl<T> PySequenceDelItemProtocolImpl for T
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_del_item() -> Option<ffi::ssizeobjargproc> {
|
||||
|
@ -277,7 +277,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
key: ffi::Py_ssize_t,
|
||||
value: *mut ffi::PyObject) -> c_int
|
||||
where T: for<'p> PySequenceSetItemProtocol<'p> +
|
||||
for<'p> PySequenceDelItemProtocol<'p> + Park<T>
|
||||
for<'p> PySequenceDelItemProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
const LOCATION: &'static str = "T.__set/del_item__()";
|
||||
::callback::cb_unary_unit::<T, _>(LOCATION, slf, |py, slf| {
|
||||
|
@ -326,7 +326,7 @@ impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PySequenceContainsProtocolImpl for T
|
||||
where T: for<'p> PySequenceContainsProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceContainsProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_contains() -> Option<ffi::objobjproc> {
|
||||
|
@ -348,7 +348,7 @@ impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p>
|
|||
}
|
||||
|
||||
impl<T> PySequenceConcatProtocolImpl for T
|
||||
where T: for<'p> PySequenceConcatProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceConcatProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_concat() -> Option<ffi::binaryfunc> {
|
||||
|
@ -370,7 +370,7 @@ impl<'p, T> PySequenceRepeatProtocolImpl for T
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PySequenceRepeatProtocolImpl for T where T: for<'p> PySequenceRepeatProtocol<'p> + Park<T>
|
||||
impl<T> PySequenceRepeatProtocolImpl for T where T: for<'p> PySequenceRepeatProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_repeat() -> Option<ffi::ssizeargfunc> {
|
||||
|
@ -392,7 +392,7 @@ impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtoco
|
|||
}
|
||||
|
||||
impl<T> PySequenceInplaceConcatProtocolImpl for T
|
||||
where T: for<'p> PySequenceInplaceConcatProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceInplaceConcatProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_inplace_concat() -> Option<ffi::binaryfunc> {
|
||||
|
@ -414,7 +414,7 @@ impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtoco
|
|||
}
|
||||
|
||||
impl<T> PySequenceInplaceRepeatProtocolImpl for T
|
||||
where T: for<'p> PySequenceInplaceRepeatProtocol<'p> + Park<T>
|
||||
where T: for<'p> PySequenceInplaceRepeatProtocol<'p> + ToInstancePtr<T>
|
||||
{
|
||||
#[inline]
|
||||
fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> {
|
||||
|
|
|
@ -21,7 +21,9 @@ pub trait ToPyObject {
|
|||
where F: FnOnce(*mut ffi::PyObject) -> R
|
||||
{
|
||||
let obj = self.to_object(py);
|
||||
f(obj.as_ptr())
|
||||
let result = f(obj.as_ptr());
|
||||
py.release(obj);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,20 +37,11 @@ pub trait IntoPyObject {
|
|||
|
||||
|
||||
/// Conversion trait that allows various objects to be converted into PyTuple object.
|
||||
pub trait ToPyTuple {
|
||||
pub trait IntoPyTuple {
|
||||
|
||||
/// Converts self into a PyTuple object.
|
||||
fn to_py_tuple(&self, py: Python) -> PyTuple;
|
||||
fn into_tuple(self, py: Python) -> PyTuple;
|
||||
|
||||
/// Converts self into a PyTuple object and calls the specified closure
|
||||
/// on the native FFI pointer underlying the Python object.
|
||||
#[inline]
|
||||
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
|
||||
where F: FnOnce(*mut ffi::PyObject) -> R
|
||||
{
|
||||
let obj = self.to_py_tuple(py);
|
||||
f(obj.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +128,6 @@ impl <T> ToPyObject for Option<T> where T: ToPyObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoPyObject for Option<T> where T: IntoPyObject {
|
||||
|
||||
fn into_object(self, py: Python) -> ::PyObject {
|
||||
|
@ -152,9 +144,14 @@ impl ToPyObject for () {
|
|||
py.None()
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for () {
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
py.None()
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract reference to instance from PyObject
|
||||
impl<'source, T> ::FromPyObject<'source> for &'source T
|
||||
impl<'source, T> FromPyObject<'source> for &'source T
|
||||
where T: PyTypeInfo + PyDowncastFrom
|
||||
{
|
||||
#[inline]
|
||||
|
|
25
src/err.rs
25
src/err.rs
|
@ -7,7 +7,7 @@ use ffi;
|
|||
use python::{ToPyPointer, IntoPyPointer, Python, PyDowncastInto, PyClone};
|
||||
use objects::{PyObject, PyType, exc};
|
||||
use typeob::{PyTypeObject};
|
||||
use conversion::{ToPyObject, ToPyTuple, IntoPyObject};
|
||||
use conversion::{ToPyObject, IntoPyTuple, IntoPyObject};
|
||||
|
||||
/**
|
||||
Defines a new exception type.
|
||||
|
@ -240,13 +240,12 @@ impl PyErr {
|
|||
/// `exc` is the exception type; usually one of the standard exceptions like `py.get_type::<exc::RuntimeError>()`.
|
||||
/// `args` is the a tuple of arguments to pass to the exception constructor.
|
||||
#[inline]
|
||||
pub fn new_err<A>(py: Python, exc: PyType, args: A) -> PyErr
|
||||
where A: ToPyTuple
|
||||
pub fn new_err<A>(py: Python, exc: &PyType, args: A) -> PyErr
|
||||
where A: IntoPyTuple
|
||||
{
|
||||
let pval = args.to_py_tuple(py);
|
||||
PyErr {
|
||||
ptype: exc,
|
||||
pvalue: Some(pval.into_object(py)),
|
||||
ptype: exc.clone_ref(py),
|
||||
pvalue: Some(args.into_tuple(py).into()),
|
||||
ptraceback: None
|
||||
}
|
||||
}
|
||||
|
@ -333,13 +332,13 @@ impl PyErr {
|
|||
}
|
||||
}
|
||||
|
||||
//pub fn clone_ref(&self, py: Python) -> PyErr {
|
||||
// PyErr {
|
||||
// ptype: self.ptype.clone_ref(py),
|
||||
// pvalue: self.pvalue.clone_ref(py),
|
||||
// ptraceback: self.ptraceback.clone_ref(py),
|
||||
// }
|
||||
//}
|
||||
pub fn clone_ref(&self, py: Python) -> PyErr {
|
||||
PyErr {
|
||||
ptype: self.ptype.clone_ref(py),
|
||||
pvalue: self.pvalue.clone_ref(py),
|
||||
ptraceback: self.ptraceback.clone_ref(py),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts `PyDowncastError` to Python `TypeError`.
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
//! ```
|
||||
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[macro_use]
|
||||
|
@ -66,14 +67,15 @@ pub mod pointers;
|
|||
pub use pointers::PyPtr;
|
||||
|
||||
mod token;
|
||||
pub use token::{PyToken, PyObjectWithToken, Park, PythonPtr};
|
||||
pub use token::{PyToken, PyObjectWithToken, ToInstancePtr, InstancePtr};
|
||||
|
||||
pub use err::{PyErr, PyResult, PyDowncastError};
|
||||
pub use objects::*;
|
||||
pub use objectprotocol::ObjectProtocol;
|
||||
pub use python::{Python, ToPyPointer, IntoPyPointer, PyClone, PyDowncastFrom, PyDowncastInto};
|
||||
pub use python::{Python, ToPyPointer, IntoPyPointer, PyClone,
|
||||
PyMutDowncastFrom, PyDowncastFrom, PyDowncastInto};
|
||||
pub use pythonrun::{GILGuard, GILProtected, prepare_freethreaded_python};
|
||||
pub use conversion::{FromPyObject, RefFromPyObject, ToPyObject, IntoPyObject, ToPyTuple};
|
||||
pub use conversion::{FromPyObject, RefFromPyObject, ToPyObject, IntoPyObject, IntoPyTuple};
|
||||
pub use class::{CompareOp};
|
||||
pub mod class;
|
||||
pub use class::*;
|
||||
|
|
|
@ -8,8 +8,8 @@ use std::cmp::Ordering;
|
|||
use ffi;
|
||||
use err::{PyErr, PyResult, self};
|
||||
use python::{Python, PyDowncastInto, ToPyPointer};
|
||||
use objects::{PyObject, PyDict, PyString, PyIterator};
|
||||
use conversion::{ToPyObject, ToPyTuple};
|
||||
use objects::{PyObject, PyDict, PyString, PyIterator, PyType};
|
||||
use conversion::{ToPyObject, IntoPyTuple};
|
||||
|
||||
|
||||
pub trait ObjectProtocol {
|
||||
|
@ -74,14 +74,14 @@ pub trait ObjectProtocol {
|
|||
/// Calls the object.
|
||||
/// This is equivalent to the Python expression: 'self(*args, **kwargs)'
|
||||
fn call<A>(&self, py: Python, args: A, kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple;
|
||||
where A: IntoPyTuple;
|
||||
|
||||
/// Calls a method on the object.
|
||||
/// This is equivalent to the Python expression: 'self.name(*args, **kwargs)'
|
||||
fn call_method<A>(&self, py: Python,
|
||||
name: &str, args: A,
|
||||
kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple;
|
||||
where A: IntoPyTuple;
|
||||
|
||||
/// Retrieves the hash code of the object.
|
||||
/// This is equivalent to the Python expression: 'hash(self)'
|
||||
|
@ -117,6 +117,10 @@ pub trait ObjectProtocol {
|
|||
/// is an iterator, this returns itself.
|
||||
fn iter<'p>(&self, py: Python<'p>) -> PyResult<PyIterator<'p>>;
|
||||
|
||||
/// Gets the Python type object for this object's type.
|
||||
#[inline]
|
||||
fn get_type(&self, py: Python) -> PyType;
|
||||
|
||||
fn get_refcnt(&self) -> isize;
|
||||
}
|
||||
|
||||
|
@ -260,14 +264,15 @@ impl<T> ObjectProtocol for T where T: ToPyPointer {
|
|||
/// This is equivalent to the Python expression: 'self(*args, **kwargs)'
|
||||
#[inline]
|
||||
fn call<A>(&self, py: Python, args: A, kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple
|
||||
where A: IntoPyTuple
|
||||
{
|
||||
let t = args.to_py_tuple(py);
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_err(
|
||||
py,
|
||||
ffi::PyObject_Call(self.as_ptr(), t.as_ptr(), kwargs.as_ptr()))
|
||||
}
|
||||
let t = args.into_tuple(py);
|
||||
let result = unsafe {
|
||||
PyObject::from_borrowed_ptr_or_err(
|
||||
py, ffi::PyObject_Call(self.as_ptr(), t.as_ptr(), kwargs.as_ptr()))
|
||||
};
|
||||
py.release(t);
|
||||
result
|
||||
}
|
||||
|
||||
/// Calls a method on the object.
|
||||
|
@ -276,14 +281,15 @@ impl<T> ObjectProtocol for T where T: ToPyPointer {
|
|||
fn call_method<A>(&self, py: Python,
|
||||
name: &str, args: A,
|
||||
kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple
|
||||
where A: IntoPyTuple
|
||||
{
|
||||
name.with_borrowed_ptr(py, |name| unsafe {
|
||||
let t = args.to_py_tuple(py);
|
||||
let t = args.into_tuple(py);
|
||||
let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name);
|
||||
PyObject::from_owned_ptr_or_err(
|
||||
py,
|
||||
ffi::PyObject_Call(ptr, t.as_ptr(), kwargs.as_ptr()))
|
||||
let result = PyObject::from_borrowed_ptr_or_err(
|
||||
py, ffi::PyObject_Call(ptr, t.as_ptr(), kwargs.as_ptr()));
|
||||
py.release(t);
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -374,6 +380,14 @@ impl<T> ObjectProtocol for T where T: ToPyPointer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets the Python type object for this object's type.
|
||||
#[inline]
|
||||
fn get_type(&self, py: Python) -> PyType {
|
||||
unsafe {
|
||||
PyType::from_type_ptr(py, (*self.as_ptr()).ob_type)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_refcnt(&self) -> isize {
|
||||
unsafe { ffi::Py_REFCNT(self.as_ptr()) }
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@ impl PyList {
|
|||
}
|
||||
}
|
||||
|
||||
/// Construct a new empty list.
|
||||
pub fn empty(_py: Python) -> PyList {
|
||||
unsafe {
|
||||
PyList(PyPtr::from_owned_ptr_or_panic(ffi::PyList_New(0)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the length of the list.
|
||||
#[inline]
|
||||
pub fn len(&self, _py: Python) -> usize {
|
||||
|
|
|
@ -24,7 +24,6 @@ macro_rules! pyobject_nativetype(
|
|||
unsafe{$crate::std::mem::transmute(self)}
|
||||
}
|
||||
}
|
||||
|
||||
impl $crate::PyClone for $name {
|
||||
fn clone_ref(&self, _py: $crate::Python) -> Self {
|
||||
$name(unsafe{$crate::PyPtr::from_borrowed_ptr(self.as_ptr())})
|
||||
|
@ -79,12 +78,11 @@ macro_rules! pyobject_nativetype(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl $crate::python::PyDowncastInto for $name
|
||||
{
|
||||
fn downcast_into<'p, I>(py: $crate::Python<'p>, ob: I)
|
||||
-> Result<Self, $crate::PyDowncastError<'p>>
|
||||
where I: $crate::ToPyPointer + $crate::IntoPyPointer
|
||||
where I: $crate::IntoPyPointer
|
||||
{
|
||||
unsafe{
|
||||
let ptr = ob.into_ptr();
|
||||
|
|
|
@ -7,7 +7,7 @@ use ffi;
|
|||
use std::os::raw::c_char;
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
use conversion::{ToPyObject, ToPyTuple};
|
||||
use conversion::{ToPyObject, IntoPyTuple};
|
||||
use pointers::PyPtr;
|
||||
use python::{Python, ToPyPointer};
|
||||
use objects::{PyObject, PyDict, PyType, exc};
|
||||
|
@ -77,7 +77,7 @@ impl<'p> PyModule {
|
|||
/// This is equivalent to the Python expression: `getattr(module, name)(*args, **kwargs)`
|
||||
pub fn call<A>(&self, py: Python, name: &str,
|
||||
args: A, kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple
|
||||
where A: IntoPyTuple
|
||||
{
|
||||
self.getattr(py, name)?.call(py, args, kwargs)
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ use std;
|
|||
|
||||
use ffi;
|
||||
use pointers::PyPtr;
|
||||
use err::{PyResult, PyDowncastError};
|
||||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
use python::{Python, ToPyPointer};
|
||||
use conversion::FromPyObject;
|
||||
|
||||
pub struct PyObject(PyPtr);
|
||||
|
||||
|
@ -56,6 +57,16 @@ impl PyObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_borrowed_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) -> PyResult<PyObject>
|
||||
{
|
||||
if ptr.is_null() {
|
||||
Err(PyErr::fetch(py))
|
||||
} else {
|
||||
Ok(PyObject(unsafe{PyPtr::from_borrowed_ptr(ptr)}))
|
||||
}
|
||||
}
|
||||
|
||||
/// Transmutes a slice of owned FFI pointers to `&[Py<'p, PyObject>]`.
|
||||
/// Undefined behavior if any pointer in the slice is NULL or invalid.
|
||||
#[inline]
|
||||
|
@ -93,9 +104,9 @@ impl PyObject {
|
|||
/// Extracts some type from the Python object.
|
||||
/// This is a wrapper function around `FromPyObject::extract()`.
|
||||
#[inline]
|
||||
pub fn extract<'a, D>(&'a self, py: Python) -> PyResult<D> where D: ::conversion::FromPyObject<'a>
|
||||
pub fn extract<'a, D>(&'a self, py: Python) -> PyResult<D> where D: FromPyObject<'a>
|
||||
{
|
||||
::conversion::FromPyObject::extract(py, &self)
|
||||
FromPyObject::extract(py, &self)
|
||||
}
|
||||
|
||||
pub fn get_refcnt(&self) -> isize {
|
||||
|
|
|
@ -8,7 +8,7 @@ use ffi::{self, Py_ssize_t};
|
|||
use err::{PyErr, PyResult};
|
||||
use pointers::PyPtr;
|
||||
use python::{Python, ToPyPointer, IntoPyPointer};
|
||||
use conversion::{FromPyObject, ToPyObject, ToPyTuple, IntoPyObject};
|
||||
use conversion::{FromPyObject, ToPyObject, IntoPyTuple, IntoPyObject};
|
||||
use objects::PyObject;
|
||||
use super::exc;
|
||||
|
||||
|
@ -87,14 +87,14 @@ impl PyTuple {
|
|||
//}
|
||||
}
|
||||
|
||||
impl ToPyTuple for PyTuple {
|
||||
fn to_py_tuple(&self, _py: Python) -> PyTuple {
|
||||
unsafe { PyTuple(PyPtr::from_borrowed_ptr(self.0.as_ptr())) }
|
||||
impl IntoPyTuple for PyTuple {
|
||||
fn into_tuple(self, _py: Python) -> PyTuple {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToPyTuple for &'a str {
|
||||
fn to_py_tuple(&self, py: Python) -> PyTuple {
|
||||
impl<'a> IntoPyTuple for &'a str {
|
||||
fn into_tuple(self, py: Python) -> PyTuple {
|
||||
PyTuple::new(py, &[py_coerce_expr!(self.to_object(py))])
|
||||
}
|
||||
}
|
||||
|
@ -114,11 +114,18 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+
|
|||
]).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl <$($T: ToPyObject),+> ToPyTuple for ($($T,)+) {
|
||||
fn to_py_tuple(&self, py: Python) -> PyTuple {
|
||||
impl <$($T: IntoPyObject),+> IntoPyObject for ($($T,)+) {
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyTuple::new(py, &[
|
||||
$(py_coerce_expr!(self.$n.to_object(py)),)+
|
||||
$(py_coerce_expr!(self.$n.into_object(py)),)+
|
||||
]).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl <$($T: IntoPyObject),+> IntoPyTuple for ($($T,)+) {
|
||||
fn into_tuple(self, py: Python) -> PyTuple {
|
||||
PyTuple::new(py, &[
|
||||
$(py_coerce_expr!(self.$n.into_object(py)),)+
|
||||
])
|
||||
}
|
||||
}
|
||||
|
@ -186,17 +193,17 @@ impl IntoPyObject for NoArgs
|
|||
}
|
||||
|
||||
/// Converts `NoArgs` to an empty Python tuple.
|
||||
impl ToPyTuple for NoArgs {
|
||||
impl IntoPyTuple for NoArgs {
|
||||
|
||||
fn to_py_tuple(&self, py: Python) -> PyTuple {
|
||||
fn into_tuple(self, py: Python) -> PyTuple {
|
||||
PyTuple::empty(py)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts `()` to an empty Python tuple.
|
||||
impl ToPyTuple for () {
|
||||
impl IntoPyTuple for () {
|
||||
|
||||
fn to_py_tuple(&self, py: Python) -> PyTuple {
|
||||
fn into_tuple(self, py: Python) -> PyTuple {
|
||||
PyTuple::empty(py)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ use std::borrow::Cow;
|
|||
use ffi;
|
||||
use pointers::PyPtr;
|
||||
use python::{Python, ToPyPointer};
|
||||
use conversion::ToPyTuple;
|
||||
use objects::{PyObject, PyDict};
|
||||
use err::PyResult;
|
||||
use objects::PyObject;
|
||||
|
||||
/// Represents a reference to a Python type object.
|
||||
pub struct PyType(PyPtr);
|
||||
|
@ -52,19 +50,6 @@ impl PyType {
|
|||
pub fn is_instance<T: ToPyPointer>(&self, _py: Python, obj: &T) -> bool {
|
||||
unsafe { ffi::PyObject_TypeCheck(obj.as_ptr(), self.as_type_ptr()) != 0 }
|
||||
}
|
||||
|
||||
// /// Calls the type object, thus creating a new instance.
|
||||
// /// This is equivalent to the Python expression: `self(*args, **kwargs)`
|
||||
#[inline]
|
||||
pub fn call<A>(&self, py: Python, args: A, kwargs: Option<&PyDict>) -> PyResult<PyObject>
|
||||
where A: ToPyTuple
|
||||
{
|
||||
let args = args.to_py_tuple(py);
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_err(
|
||||
py, ffi::PyObject_Call(self.as_ptr(), args.as_ptr(), kwargs.as_ptr()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PyType {
|
||||
|
|
|
@ -22,7 +22,8 @@ impl PyPtr {
|
|||
/// Undefined behavior if the pointer is NULL or invalid.
|
||||
#[inline]
|
||||
pub unsafe fn from_owned_ptr(ptr: *mut ffi::PyObject) -> PyPtr {
|
||||
debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0);
|
||||
debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0,
|
||||
format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)));
|
||||
PyPtr(ptr)
|
||||
}
|
||||
|
||||
|
@ -59,7 +60,8 @@ impl PyPtr {
|
|||
/// Undefined behavior if the pointer is NULL or invalid.
|
||||
#[inline]
|
||||
pub unsafe fn from_borrowed_ptr(ptr: *mut ffi::PyObject) -> PyPtr {
|
||||
debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0);
|
||||
debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0,
|
||||
format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)));
|
||||
ffi::Py_INCREF(ptr);
|
||||
PyPtr::from_owned_ptr(ptr)
|
||||
}
|
||||
|
@ -132,13 +134,12 @@ impl PartialEq for PyPtr {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Dropping a `PyPtr` instance decrements the reference count on the object by 1.
|
||||
impl Drop for PyPtr {
|
||||
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
println!("drop PyPtr: {:?} {} {:?}",
|
||||
debug!("drop PyPtr: {:?} {} {:?}",
|
||||
self.0, ffi::Py_REFCNT(self.0), &self as *const _);
|
||||
}
|
||||
let _gil_guard = Python::acquire_gil();
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::os::raw::c_int;
|
|||
|
||||
use ffi;
|
||||
use typeob::{PyTypeInfo, PyTypeObject, PyObjectAlloc};
|
||||
use token::{PyToken, Park};
|
||||
use token::{PyToken, ToInstancePtr};
|
||||
use objects::{PyObject, PyType, PyBool, PyDict, PyModule};
|
||||
use err::{PyErr, PyResult, PyDowncastError};
|
||||
use pythonrun::GILGuard;
|
||||
|
@ -34,9 +34,15 @@ pub trait PyDowncastFrom : Sized {
|
|||
|
||||
/// Cast from PyObject to a concrete Python object type.
|
||||
fn downcast_from<'a, 'p>(Python<'p>, &'a PyObject) -> Result<&'a Self, PyDowncastError<'p>>;
|
||||
|
||||
}
|
||||
|
||||
/// Trait implemented by Python object types that allow a checked downcast.
|
||||
pub trait PyMutDowncastFrom : Sized {
|
||||
|
||||
/// Cast from PyObject to a concrete Python object type.
|
||||
fn downcast_mut_from<'a, 'p>(Python<'p>, &'a mut PyObject) ->
|
||||
Result<&'a mut Self, PyDowncastError<'p>>;
|
||||
}
|
||||
|
||||
/// Trait implemented by Python object types that allow a checked downcast.
|
||||
pub trait PyDowncastInto : Sized {
|
||||
|
@ -67,7 +73,6 @@ pub trait IntoPyPointer {
|
|||
fn into_ptr(self) -> *mut ffi::PyObject;
|
||||
}
|
||||
|
||||
|
||||
/// Convert None into a null pointer.
|
||||
impl<'p, T> ToPyPointer for Option<&'p T> where T: ToPyPointer {
|
||||
#[inline]
|
||||
|
@ -223,18 +228,18 @@ impl<'p> Python<'p> {
|
|||
unsafe { PyObject::from_borrowed_ptr(self, ffi::Py_NotImplemented()) }
|
||||
}
|
||||
|
||||
/// Execute closure `F` with Python Token instance.
|
||||
pub fn with<T, F>(self, f: F) -> PyResult<T::ParkTarget>
|
||||
/// Create new python object and move T instance under python management
|
||||
pub fn init<T, F>(self, f: F) -> PyResult<T::Target>
|
||||
where F: FnOnce(PyToken) -> T,
|
||||
T: Park<T> + PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
T: ToInstancePtr<T> + PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
{
|
||||
::token::with(self, f)
|
||||
::token::init(self, f)
|
||||
}
|
||||
|
||||
/// Release PyObject reference
|
||||
pub fn release<T>(self, ob: T) where T: IntoPyPointer {
|
||||
unsafe {
|
||||
ffi::Py_INCREF(ob.into_ptr());
|
||||
ffi::Py_DECREF(ob.into_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ pub struct GILGuard {
|
|||
/// The Drop implementation for GILGuard will release the GIL.
|
||||
impl Drop for GILGuard {
|
||||
fn drop(&mut self) {
|
||||
println!("RELEASE");
|
||||
debug!("RELEASE");
|
||||
unsafe { ffi::PyGILState_Release(self.gstate) }
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ impl GILGuard {
|
|||
/// See [prepare_freethreaded_python()](fn.prepare_freethreaded_python.html) for details.
|
||||
pub fn acquire() -> GILGuard {
|
||||
::pythonrun::prepare_freethreaded_python();
|
||||
println!("ACQUIRE");
|
||||
debug!("ACQUIRE");
|
||||
let gstate = unsafe { ffi::PyGILState_Ensure() }; // acquire GIL
|
||||
GILGuard { gstate: gstate, no_send: marker::PhantomData }
|
||||
}
|
||||
|
|
32
src/token.rs
32
src/token.rs
|
@ -19,9 +19,9 @@ impl PyToken {
|
|||
|
||||
/// Create new python object and move T instance under python management
|
||||
#[inline]
|
||||
pub fn with<'p, T, F>(py: Python<'p>, f: F) -> PyResult<T::ParkTarget>
|
||||
pub fn init<'p, T, F>(py: Python<'p>, f: F) -> PyResult<T::Target>
|
||||
where F: FnOnce(PyToken) -> T,
|
||||
T: Park<T> + PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
T: ToInstancePtr<T> + PyTypeInfo + PyObjectAlloc<Type=T>
|
||||
{
|
||||
let ob = f(PyToken(PhantomData));
|
||||
|
||||
|
@ -36,22 +36,36 @@ pub trait PyObjectWithToken : Sized {
|
|||
fn token<'p>(&'p self) -> Python<'p>;
|
||||
}
|
||||
|
||||
pub trait ToInstancePtr<T> : Sized {
|
||||
type Target: InstancePtr<T> + IntoPyPointer;
|
||||
|
||||
pub trait Park<T> : Sized {
|
||||
type ParkTarget: PythonPtr<T> + IntoPyPointer;
|
||||
fn to_inst_ptr(&self) -> Self::Target;
|
||||
|
||||
fn park(&self) -> Self::ParkTarget;
|
||||
unsafe fn from_owned_ptr(*mut ffi::PyObject) -> Self::Target;
|
||||
|
||||
unsafe fn from_owned_ptr(*mut ffi::PyObject) -> Self::ParkTarget;
|
||||
|
||||
unsafe fn from_borrowed_ptr(*mut ffi::PyObject) -> Self::ParkTarget;
|
||||
unsafe fn from_borrowed_ptr(*mut ffi::PyObject) -> Self::Target;
|
||||
|
||||
}
|
||||
|
||||
pub trait PythonPtr<T> : Sized {
|
||||
pub trait InstancePtr<T> : Sized {
|
||||
|
||||
fn as_ref(&self, py: Python) -> &T;
|
||||
|
||||
fn as_mut(&self, py: Python) -> &mut T;
|
||||
|
||||
fn with<F, R>(&self, f: F) -> R where F: FnOnce(Python, &T) -> R
|
||||
{
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
f(py, self.as_ref(py))
|
||||
}
|
||||
|
||||
fn with_mut<F, R>(&self, f: F) -> R where F: FnOnce(Python, &mut T) -> R
|
||||
{
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
f(py, self.as_mut(py))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ pub fn initialize_type<T>(py: Python, module_name: Option<&str>, type_name: &str
|
|||
unsafe extern "C" fn tp_dealloc_callback<T>(obj: *mut ffi::PyObject)
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
println!("DEALLOC: {:?}", obj);
|
||||
debug!("DEALLOC: {:?}", obj);
|
||||
let guard = AbortOnDrop("Cannot unwind out of tp_dealloc");
|
||||
let py = Python::assume_gil_acquired();
|
||||
let r = <T as PyObjectAlloc>::dealloc(py, obj);
|
||||
|
|
|
@ -72,7 +72,7 @@ fn test_buffer() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let t = py.with(|t| TestClass{vec: vec![b' ', b'2', b'3'], token: t}).unwrap();
|
||||
let t = py.init(|t| TestClass{vec: vec![b' ', b'2', b'3'], token: t}).unwrap();
|
||||
|
||||
let d = PyDict::new(py);
|
||||
let _ = d.set_item(py, "ob", t);
|
||||
|
|
|
@ -79,7 +79,7 @@ struct EmptyClassWithNewPtr(PyPtr);
|
|||
impl EmptyClassWithNew {
|
||||
#[__new__]
|
||||
fn __new__(cls: &PyType, py: Python) -> PyResult<EmptyClassWithNewPtr> {
|
||||
py.with(|t| EmptyClassWithNew{token: t})
|
||||
py.init(|t| EmptyClassWithNew{token: t})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ struct NewWithOneArgPtr(PyPtr);
|
|||
impl NewWithOneArg {
|
||||
#[new]
|
||||
fn __new__(_cls: &PyType, py: Python, arg: i32) -> PyResult<NewWithOneArgPtr> {
|
||||
py.with(|t| NewWithOneArg{_data: arg, token: t})
|
||||
py.init(|t| NewWithOneArg{_data: arg, token: t})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ struct NewWithTwoArgsPtr(PyPtr);
|
|||
impl NewWithTwoArgs {
|
||||
#[new]
|
||||
fn __new__(_cls: &PyType, py: Python, arg1: i32, arg2: i32) -> PyResult<NewWithTwoArgsPtr> {
|
||||
py.with(|t| NewWithTwoArgs{_data1: arg1, _data2: arg2, token: t})
|
||||
py.init(|t| NewWithTwoArgs{_data1: arg1, _data2: arg2, token: t})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn data_is_dropped() {
|
|||
|
||||
let drop_called1 = Arc::new(AtomicBool::new(false));
|
||||
let drop_called2 = Arc::new(AtomicBool::new(false));
|
||||
let inst = py.with(|t| DataIsDropped{
|
||||
let inst = py.init(|t| DataIsDropped{
|
||||
member1: TestDropCall { drop_called: drop_called1.clone() },
|
||||
member2: TestDropCall { drop_called: drop_called2.clone() },
|
||||
token: t
|
||||
|
@ -206,7 +206,7 @@ fn instance_method() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = py.with(|t| InstanceMethod{member: 42, token: t}).unwrap();
|
||||
let obj = py.init(|t| InstanceMethod{member: 42, token: t}).unwrap();
|
||||
assert!(obj.as_ref(py).method(py).unwrap() == 42);
|
||||
let d = PyDict::new(py);
|
||||
d.set_item(py, "obj", obj).unwrap();
|
||||
|
@ -233,7 +233,7 @@ fn instance_method_with_args() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = py.with(|t| InstanceMethodWithArgs{member: 7, token: t}).unwrap();
|
||||
let obj = py.init(|t| InstanceMethodWithArgs{member: 7, token: t}).unwrap();
|
||||
assert!(obj.as_ref(py).method(py, 6).unwrap() == 42);
|
||||
let d = PyDict::new(py);
|
||||
d.set_item(py, "obj", obj).unwrap();
|
||||
|
@ -297,7 +297,7 @@ struct StaticMethodPtr(PyPtr);
|
|||
impl StaticMethod {
|
||||
#[new]
|
||||
fn __new__(cls: &PyType, py: Python) -> PyResult<StaticMethodPtr> {
|
||||
py.with(|t| StaticMethod{token: t})
|
||||
py.init(|t| StaticMethod{token: t})
|
||||
}
|
||||
|
||||
//#[staticmethod]
|
||||
|
@ -364,7 +364,7 @@ fn gc_integration() {
|
|||
let py = gil.python();
|
||||
|
||||
let drop_called = Arc::new(AtomicBool::new(false));
|
||||
let inst = py.with(|t| GCIntegration{
|
||||
let inst = py.init(|t| GCIntegration{
|
||||
self_ref: RefCell::new(py.None()),
|
||||
dropped: TestDropCall { drop_called: drop_called.clone() },
|
||||
token: t}).unwrap();
|
||||
|
@ -397,14 +397,14 @@ fn len() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let inst = py.with(|t| Len{l: 10, token: t}).unwrap();
|
||||
let inst = py.init(|t| Len{l: 10, token: t}).unwrap();
|
||||
py_assert!(py, inst, "len(inst) == 10");
|
||||
unsafe {
|
||||
assert_eq!(ffi::PyObject_Size(inst.as_ptr()), 10);
|
||||
assert_eq!(ffi::PyMapping_Size(inst.as_ptr()), 10);
|
||||
}
|
||||
|
||||
let inst = py.with(|t| Len{l: (isize::MAX as usize) + 1, token: t}).unwrap();
|
||||
let inst = py.init(|t| Len{l: (isize::MAX as usize) + 1, token: t}).unwrap();
|
||||
py_expect_exception!(py, inst, "len(inst)", OverflowError);
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ fn string_methods() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = py.with(|t| StringMethods{token: t}).unwrap();
|
||||
let obj = py.init(|t| StringMethods{token: t}).unwrap();
|
||||
py_assert!(py, obj, "str(obj) == 'str'");
|
||||
py_assert!(py, obj, "repr(obj) == 'repr'");
|
||||
py_assert!(py, obj, "'{0:x}'.format(obj) == 'format(x)'");
|
||||
|
@ -497,10 +497,10 @@ fn comparisons() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let zero = py.with(|t| Comparisons{val: 0, token: t}).unwrap();
|
||||
let one = py.with(|t| Comparisons{val: 1, token: t}).unwrap();
|
||||
let ten = py.with(|t| Comparisons{val: 10, token: t}).unwrap();
|
||||
let minus_one = py.with(|t| Comparisons{val: -1, token: t}).unwrap();
|
||||
let zero = py.init(|t| Comparisons{val: 0, token: t}).unwrap();
|
||||
let one = py.init(|t| Comparisons{val: 1, token: t}).unwrap();
|
||||
let ten = py.init(|t| Comparisons{val: 10, token: t}).unwrap();
|
||||
let minus_one = py.init(|t| Comparisons{val: -1, token: t}).unwrap();
|
||||
py_assert!(py, one, "hash(one) == 1");
|
||||
py_assert!(py, ten, "hash(ten) == 10");
|
||||
py_assert!(py, minus_one, "hash(minus_one) == -2");
|
||||
|
@ -537,7 +537,7 @@ fn sequence() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| Sequence{token: t}).unwrap();
|
||||
let c = py.init(|t| Sequence{token: t}).unwrap();
|
||||
py_assert!(py, c, "list(c) == [0, 1, 2, 3, 4]");
|
||||
py_expect_exception!(py, c, "c['abc']", TypeError);
|
||||
}
|
||||
|
@ -563,11 +563,11 @@ fn callable() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| Callable{token: t}).unwrap();
|
||||
let c = py.init(|t| Callable{token: t}).unwrap();
|
||||
py_assert!(py, c, "callable(c)");
|
||||
py_assert!(py, c, "c(7) == 42");
|
||||
|
||||
let nc = py.with(|t| Comparisons{val: 0, token: t}).unwrap();
|
||||
let nc = py.init(|t| Comparisons{val: 0, token: t}).unwrap();
|
||||
py_assert!(py, nc, "not callable(nc)");
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ fn setitem() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| SetItem{key: 0, val: 0, token: t}).unwrap();
|
||||
let c = py.init(|t| SetItem{key: 0, val: 0, token: t}).unwrap();
|
||||
py_run!(py, c, "c[1] = 2");
|
||||
assert_eq!(c.as_ref(py).key, 1);
|
||||
assert_eq!(c.as_ref(py).val, 2);
|
||||
|
@ -624,7 +624,7 @@ fn delitem() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| DelItem{key:0, token:t}).unwrap();
|
||||
let c = py.init(|t| DelItem{key:0, token:t}).unwrap();
|
||||
py_run!(py, c, "del c[1]");
|
||||
assert_eq!(c.as_ref(py).key, 1);
|
||||
py_expect_exception!(py, c, "c[1] = 2", NotImplementedError);
|
||||
|
@ -657,7 +657,7 @@ fn setdelitem() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| SetDelItem{val: None, token: t}).unwrap();
|
||||
let c = py.init(|t| SetDelItem{val: None, token: t}).unwrap();
|
||||
py_run!(py, c, "c[1] = 2");
|
||||
assert_eq!(c.as_ref(py).val, Some(2));
|
||||
py_run!(py, c, "del c[1]");
|
||||
|
@ -682,7 +682,7 @@ fn reversed() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| Reversed{token: t}).unwrap();
|
||||
let c = py.init(|t| Reversed{token: t}).unwrap();
|
||||
py_run!(py, c, "assert reversed(c) == 'I am reversed'");
|
||||
}
|
||||
|
||||
|
@ -704,7 +704,7 @@ fn contains() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| Contains{token: t}).unwrap();
|
||||
let c = py.init(|t| Contains{token: t}).unwrap();
|
||||
py_run!(py, c, "assert 1 in c");
|
||||
py_run!(py, c, "assert -1 not in c");
|
||||
py_expect_exception!(py, c, "assert 'wrong type' not in c", TypeError);
|
||||
|
@ -743,7 +743,7 @@ fn unary_arithmetic() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| UnaryArithmetic{token: t}).unwrap();
|
||||
let c = py.init(|t| UnaryArithmetic{token: t}).unwrap();
|
||||
py_run!(py, c, "assert -c == 'neg'");
|
||||
py_run!(py, c, "assert +c == 'pos'");
|
||||
py_run!(py, c, "assert abs(c) == 'abs'");
|
||||
|
@ -806,7 +806,7 @@ fn binary_arithmetic() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| BinaryArithmetic{token: t}).unwrap();
|
||||
let c = py.init(|t| BinaryArithmetic{token: t}).unwrap();
|
||||
py_run!(py, c, "assert c + c == 'BA + BA'");
|
||||
py_run!(py, c, "assert c + 1 == 'BA + 1'");
|
||||
py_run!(py, c, "assert 1 + c == '1 + BA'");
|
||||
|
@ -883,7 +883,7 @@ fn rich_comparisons() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| RichComparisons{token: t}).unwrap();
|
||||
let c = py.init(|t| RichComparisons{token: t}).unwrap();
|
||||
py_run!(py, c, "assert (c < c) == 'RC < RC'");
|
||||
py_run!(py, c, "assert (c < 1) == 'RC < 1'");
|
||||
py_run!(py, c, "assert (1 < c) == 'RC > 1'");
|
||||
|
@ -909,7 +909,7 @@ fn rich_comparisons_python_3_type_error() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c2 = py.with(|t| RichComparisons2{py: t}).unwrap();
|
||||
let c2 = py.init(|t| RichComparisons2{py: t}).unwrap();
|
||||
py_expect_exception!(py, c2, "c2 < c2", TypeError);
|
||||
py_expect_exception!(py, c2, "c2 < 1", TypeError);
|
||||
py_expect_exception!(py, c2, "1 < c2", TypeError);
|
||||
|
@ -994,28 +994,28 @@ fn inplace_operations() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 0, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 0, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c += 1; assert repr(c) == repr(d) == 'IPO(1)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value:10, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value:10, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c -= 1; assert repr(c) == repr(d) == 'IPO(9)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 3, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 3, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c *= 3; assert repr(c) == repr(d) == 'IPO(9)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 3, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 3, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c <<= 2; assert repr(c) == repr(d) == 'IPO(12)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c >>= 2; assert repr(c) == repr(d) == 'IPO(3)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c &= 10; assert repr(c) == repr(d) == 'IPO(8)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c |= 3; assert repr(c) == repr(d) == 'IPO(15)'");
|
||||
|
||||
let c = py.with(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap();
|
||||
py_run!(py, c, "d = c; c ^= 5; assert repr(c) == repr(d) == 'IPO(9)'");
|
||||
}
|
||||
|
||||
|
@ -1053,7 +1053,7 @@ fn context_manager() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let c = py.with(|t| ContextManager{exit_called: false, token: t}).unwrap();
|
||||
let c = py.init(|t| ContextManager{exit_called: false, token: t}).unwrap();
|
||||
py_run!(py, c, "with c as x:\n assert x == 42");
|
||||
assert!(c.as_ref(py).exit_called);
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ fn class_with_properties() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let inst = py.with(|t| ClassWithProperties{num: 10, token: t}).unwrap();
|
||||
let inst = py.init(|t| ClassWithProperties{num: 10, token: t}).unwrap();
|
||||
|
||||
py_run!(py, inst, "assert inst.get_num() == 10");
|
||||
py_run!(py, inst, "assert inst.get_num() == inst.DATA");
|
||||
|
|
|
@ -51,7 +51,7 @@ fn test_cls_impl() {
|
|||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let ob = py.with(|t| Test{token: t}).unwrap();
|
||||
let ob = py.init(|t| Test{token: t}).unwrap();
|
||||
let d = PyDict::new(py);
|
||||
d.set_item(py, "ob", ob).unwrap();
|
||||
|
||||
|
|
Loading…
Reference in New Issue