make cast_xxx api consistent with PyObject::from_xxx api
This commit is contained in:
parent
5dad22e3db
commit
e44365bec6
|
@ -65,7 +65,7 @@ pub fn py3_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
|
|||
|
||||
let _pool = pyo3::GILPool::new();
|
||||
let _py = pyo3::Python::assume_gil_acquired();
|
||||
let _module = match _py.cast_from_ptr_or_err::<pyo3::PyModule>(_module) {
|
||||
let _module = match _py.from_owned_ptr_or_err::<pyo3::PyModule>(_module) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
pyo3::PyErr::from(e).restore(_py);
|
||||
|
@ -135,7 +135,7 @@ pub fn py2_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
|
|||
return
|
||||
}
|
||||
|
||||
let _module = match _py.cast_from_borrowed_ptr_or_err::<pyo3::PyModule>(_module) {
|
||||
let _module = match _py.from_borrowed_ptr_or_err::<pyo3::PyModule>(_module) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
pyo3::PyErr::from(e).restore(_py);
|
||||
|
@ -327,7 +327,7 @@ pub fn impl_wrap(name: &syn::Ident, spec: &method::FnSpec) -> Tokens {
|
|||
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: #output = {
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn impl_wrap(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec, noargs: b
|
|||
stringify!(#cls), ".", stringify!(#name), "()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
|
||||
let _result: #output = {
|
||||
#cb
|
||||
|
@ -80,8 +80,8 @@ pub fn impl_wrap(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec, noargs: b
|
|||
stringify!(#cls), ".", stringify!(#name), "()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: #output = {
|
||||
|
@ -109,8 +109,8 @@ pub fn impl_proto_wrap(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) ->
|
|||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result = {
|
||||
|
@ -145,7 +145,7 @@ pub fn impl_wrap_type(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) -> T
|
|||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _cls = _pyo3::PyType::from_type_ptr(_py, _cls);
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: #output = {
|
||||
|
@ -172,8 +172,8 @@ fn impl_wrap_init(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) -> Token
|
|||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: PyResult<()> = {
|
||||
|
@ -212,7 +212,7 @@ pub fn impl_wrap_class(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) ->
|
|||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _cls = _pyo3::PyType::from_type_ptr(_py, _cls as *mut _pyo3::ffi::PyTypeObject);
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: #output = {
|
||||
|
@ -246,7 +246,7 @@ pub fn impl_wrap_static(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) ->
|
|||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _args = _py.cast_from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _args = _py.from_borrowed_ptr::<_pyo3::PyTuple>(_args);
|
||||
let _kwargs = _pyo3::argparse::get_kwargs(_py, _kwargs);
|
||||
|
||||
let _result: #output = {
|
||||
|
@ -269,7 +269,7 @@ fn impl_wrap_getter(cls: &Box<syn::Ty>, name: &syn::Ident, _spec: &FnSpec) -> To
|
|||
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
|
||||
match _slf.#name() {
|
||||
Ok(val) => {
|
||||
|
@ -300,8 +300,8 @@ fn impl_wrap_setter(cls: &Box<syn::Ty>, name: &syn::Ident, spec: &FnSpec) -> Tok
|
|||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = _pyo3::GILPool::new();
|
||||
let _py = _pyo3::Python::assume_gil_acquired();
|
||||
let _slf = _py.mut_cast_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _value = _py.cast_from_borrowed_ptr(_value);
|
||||
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
|
||||
let _value = _py.from_borrowed_ptr(_value);
|
||||
|
||||
let _result = match <#val_ty as _pyo3::FromPyObject>::extract(_value) {
|
||||
Ok(_val) => _slf.#name(_val),
|
||||
|
|
|
@ -97,6 +97,6 @@ pub unsafe fn get_kwargs(py: Python, ptr: *mut ffi::PyObject) -> Option<&PyDict>
|
|||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(py.cast_from_borrowed_ptr::<PyDict>(ptr))
|
||||
Some(py.from_borrowed_ptr::<PyDict>(ptr))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,8 +362,8 @@ impl<T> PyObjectRichcmpProtocolImpl for T
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.cast_from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.cast_from_borrowed_ptr::<PyObjectRef>(arg);
|
||||
let slf = py.from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.from_borrowed_ptr::<PyObjectRef>(arg);
|
||||
|
||||
let res = match extract_op(op) {
|
||||
Ok(op) => match arg.extract() {
|
||||
|
|
|
@ -82,7 +82,7 @@ impl<T> PyBufferGetBufferProtocolImpl for T
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = ::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
let result = slf.bf_getbuffer(arg1, arg2).into();
|
||||
::callback::cb_convert(UnitCallbackConverter, py, result)
|
||||
|
|
|
@ -89,7 +89,7 @@ impl<T> PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p>
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
let visit = PyVisit { visit: visit, arg: arg, _py: py };
|
||||
match slf.__traverse__(visit) {
|
||||
|
@ -124,7 +124,7 @@ impl<T> PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p>
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
slf.__clear__();
|
||||
0
|
||||
|
|
|
@ -12,7 +12,7 @@ macro_rules! py_unary_func {
|
|||
{
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let res = slf.$f().into();
|
||||
$crate::callback::cb_convert($conv, py, res)
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ macro_rules! py_unary_func {
|
|||
use $crate::ObjectProtocol;
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let res = slf.$f().into();
|
||||
$crate::callback::cb_convert($conv, py, res)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ macro_rules! py_len_func {
|
|||
{
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
let result = slf.$f().into();
|
||||
$crate::callback::cb_convert($conv, py, result)
|
||||
|
@ -74,8 +74,8 @@ macro_rules! py_binary_func{
|
|||
use $crate::ObjectProtocol;
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg);
|
||||
|
||||
let result = match arg.extract() {
|
||||
Ok(arg) => slf.$f(arg).into(),
|
||||
|
@ -99,8 +99,8 @@ macro_rules! py_binary_num_func{
|
|||
use $crate::ObjectProtocol;
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let lhs = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(lhs);
|
||||
let rhs = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(rhs);
|
||||
let lhs = py.from_borrowed_ptr::<$crate::PyObjectRef>(lhs);
|
||||
let rhs = py.from_borrowed_ptr::<$crate::PyObjectRef>(rhs);
|
||||
|
||||
let result = match lhs.extract() {
|
||||
Ok(lhs) => match rhs.extract() {
|
||||
|
@ -128,8 +128,8 @@ macro_rules! py_binary_self_func{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf1 = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg);
|
||||
let slf1 = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let arg = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg);
|
||||
|
||||
let result = match arg.extract() {
|
||||
Ok(arg) => slf1.$f(arg).into(),
|
||||
|
@ -162,7 +162,7 @@ macro_rules! py_ssizearg_func {
|
|||
{
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let result = slf.$f(arg as isize).into();
|
||||
$crate::callback::cb_convert($conv, py, result)
|
||||
}
|
||||
|
@ -186,9 +186,9 @@ macro_rules! py_ternary_func{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let arg1 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
|
||||
let result = match arg1.extract() {
|
||||
Ok(arg1) => match arg2.extract() {
|
||||
|
@ -217,9 +217,9 @@ macro_rules! py_ternary_num_func{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let arg1 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
let arg3 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg3);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
let arg3 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg3);
|
||||
|
||||
let result = match arg1.extract() {
|
||||
Ok(arg1) => match arg2.extract() {
|
||||
|
@ -252,9 +252,9 @@ macro_rules! py_ternary_self_func{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf1 = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let arg1 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
let slf1 = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyObjectRef>(arg2);
|
||||
|
||||
let result = match arg1.extract() {
|
||||
Ok(arg1) => match arg2.extract() {
|
||||
|
@ -290,7 +290,7 @@ macro_rules! py_func_set{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
if value.is_null() {
|
||||
let e = $crate::PyErr::new::<exc::NotImplementedError, _>(
|
||||
|
@ -298,8 +298,8 @@ macro_rules! py_func_set{
|
|||
e.restore(py);
|
||||
-1
|
||||
} else {
|
||||
let name = py.mut_cast_from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
let value = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(value);
|
||||
let name = py.mut_from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value);
|
||||
let result = match name.extract() {
|
||||
Ok(name) => match value.extract() {
|
||||
Ok(value) =>
|
||||
|
@ -340,8 +340,8 @@ macro_rules! py_func_del{
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
|
||||
if value.is_null() {
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let name = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let name = py.from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
|
||||
let result = match name.extract() {
|
||||
Ok(name) => slf.$f(name).into(),
|
||||
|
@ -380,8 +380,8 @@ macro_rules! py_func_set_del{
|
|||
|
||||
let _pool = $crate::GILPool::new();
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let name = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
let name = py.from_borrowed_ptr::<$crate::PyObjectRef>(name);
|
||||
|
||||
if value.is_null() {
|
||||
let result = match name.extract() {
|
||||
|
@ -396,7 +396,7 @@ macro_rules! py_func_set_del{
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let value = py.cast_from_borrowed_ptr::<$crate::PyObjectRef>(value);
|
||||
let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value);
|
||||
let result = match name.extract() {
|
||||
Ok(name) => match value.extract() {
|
||||
Ok(value) => {
|
||||
|
|
|
@ -218,7 +218,7 @@ impl<T> PySequenceSetItemProtocolImpl for T
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
if value.is_null() {
|
||||
let e = PyErr::new::<exc::NotImplementedError, _>(
|
||||
|
@ -226,7 +226,7 @@ impl<T> PySequenceSetItemProtocolImpl for T
|
|||
e.restore(py);
|
||||
-1
|
||||
} else {
|
||||
let value = py.cast_from_borrowed_ptr::<PyObjectRef>(value);
|
||||
let value = py.from_borrowed_ptr::<PyObjectRef>(value);
|
||||
let result = match value.extract() {
|
||||
Ok(value) => {
|
||||
slf.__setitem__(key as isize, value).into()
|
||||
|
@ -269,7 +269,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
if value.is_null() {
|
||||
let result = slf.__delitem__(key as isize).into();
|
||||
|
@ -304,7 +304,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
{
|
||||
let _pool = ::GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let slf = py.mut_cast_from_borrowed_ptr::<T>(slf);
|
||||
let slf = py.mut_from_borrowed_ptr::<T>(slf);
|
||||
|
||||
if value.is_null() {
|
||||
let result = slf.__delitem__(key as isize).into();
|
||||
|
@ -316,7 +316,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let value = py.cast_from_borrowed_ptr::<PyObjectRef>(value);
|
||||
let value = py.from_borrowed_ptr::<PyObjectRef>(value);
|
||||
let result = match value.extract() {
|
||||
Ok(value) => {
|
||||
slf.__setitem__(key as isize, value).into()
|
||||
|
|
|
@ -181,7 +181,7 @@ impl<T> Py<T> where T: PyTypeInfo,
|
|||
|
||||
unsafe {
|
||||
let ob = try!(<T as PyObjectAlloc<T>>::alloc(py, ob));
|
||||
Ok(py.cast_from_ptr(ob))
|
||||
Ok(py.from_owned_ptr(ob))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ impl<T> Py<T> where T: PyTypeInfo,
|
|||
|
||||
unsafe {
|
||||
let ob = try!(<T as PyObjectAlloc<T>>::alloc(py, ob));
|
||||
Ok(py.mut_cast_from_ptr(ob))
|
||||
Ok(py.mut_from_owned_ptr(ob))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
fn getattr<N>(&self, attr_name: N) -> PyResult<&PyObjectRef> where N: ToPyObject
|
||||
{
|
||||
attr_name.with_borrowed_ptr(self.py(), |attr_name| unsafe {
|
||||
self.py().cast_from_ptr_or_err(
|
||||
self.py().from_owned_ptr_or_err(
|
||||
ffi::PyObject_GetAttr(self.as_ptr(), attr_name))
|
||||
})
|
||||
}
|
||||
|
@ -231,14 +231,14 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
#[inline]
|
||||
fn repr(&self) -> PyResult<&PyString> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(ffi::PyObject_Repr(self.as_ptr()))
|
||||
self.py().from_owned_ptr_or_err(ffi::PyObject_Repr(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn str(&self) -> PyResult<&PyString> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(ffi::PyObject_Str(self.as_ptr()))
|
||||
self.py().from_owned_ptr_or_err(ffi::PyObject_Str(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
{
|
||||
let t = args.into_tuple(self.py());
|
||||
let result = unsafe {
|
||||
self.py().cast_from_ptr_or_err(
|
||||
self.py().from_owned_ptr_or_err(
|
||||
ffi::PyObject_Call(self.as_ptr(), t.as_ptr(), kwargs.as_ptr()))
|
||||
};
|
||||
self.py().release(t);
|
||||
|
@ -270,7 +270,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
name.with_borrowed_ptr(self.py(), |name| unsafe {
|
||||
let t = args.into_tuple(self.py());
|
||||
let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name);
|
||||
let result = self.py().cast_from_ptr_or_err(
|
||||
let result = self.py().from_owned_ptr_or_err(
|
||||
ffi::PyObject_Call(ptr, t.as_ptr(), kwargs.as_ptr()));
|
||||
ffi::Py_DECREF(ptr);
|
||||
self.py().release(t);
|
||||
|
@ -316,7 +316,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
#[inline]
|
||||
fn get_item<K>(&self, key: K) -> PyResult<&PyObjectRef> where K: ToBorrowedObject {
|
||||
key.with_borrowed_ptr(self.py(), |key| unsafe {
|
||||
self.py().cast_from_ptr_or_err(
|
||||
self.py().from_owned_ptr_or_err(
|
||||
ffi::PyObject_GetItem(self.as_ptr(), key))
|
||||
})
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ impl<T> ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer {
|
|||
|
||||
fn get_super(&self) -> &<Self as PyTypeInfo>::BaseType where Self: PyTypeInfo
|
||||
{
|
||||
unsafe { self.py().cast_from_borrowed_ptr(self.as_ptr()) }
|
||||
unsafe { self.py().from_borrowed_ptr(self.as_ptr()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -16,7 +16,7 @@ impl PyBool {
|
|||
#[inline]
|
||||
pub fn new(py: Python, val: bool) -> &PyBool {
|
||||
unsafe {
|
||||
py.cast_from_borrowed_ptr(if val { ffi::Py_True() } else { ffi::Py_False() })
|
||||
py.from_borrowed_ptr(if val { ffi::Py_True() } else { ffi::Py_False() })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ impl PyByteArray {
|
|||
let ptr = src.as_ptr() as *const c_char;
|
||||
let len = src.len() as ffi::Py_ssize_t;
|
||||
unsafe {
|
||||
py.cast_from_ptr::<PyByteArray>(
|
||||
py.from_owned_ptr::<PyByteArray>(
|
||||
ffi::PyByteArray_FromStringAndSize(ptr, len))
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ impl PyByteArray {
|
|||
where I: ToPyPointer
|
||||
{
|
||||
unsafe {
|
||||
py.cast_from_ptr_or_err(
|
||||
py.from_owned_ptr_or_err(
|
||||
ffi::PyByteArray_FromObject(src.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl PyDict {
|
|||
/// May panic when running out of memory.
|
||||
pub fn new(py: Python) -> &PyDict {
|
||||
unsafe {
|
||||
py.cast_from_ptr::<PyDict>(ffi::PyDict_New())
|
||||
py.from_owned_ptr::<PyDict>(ffi::PyDict_New())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ impl PyDict {
|
|||
/// Corresponds to `dict(self)` in Python.
|
||||
pub fn copy(&self) -> PyResult<&PyDict> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err::<PyDict>(ffi::PyDict_Copy(self.as_ptr()))
|
||||
self.py().from_owned_ptr_or_err::<PyDict>(ffi::PyDict_Copy(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ impl PyDict {
|
|||
/// Returns None if the item is not present, or if an error occurs.
|
||||
pub fn get_item<K>(&self, key: K) -> Option<&PyObjectRef> where K: ToBorrowedObject {
|
||||
key.with_borrowed_ptr(self.py(), |key| unsafe {
|
||||
self.py().cast_from_borrowed_ptr_or_opt(
|
||||
self.py().from_borrowed_ptr_or_opt(
|
||||
ffi::PyDict_GetItem(self.as_ptr(), key))
|
||||
})
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ impl PyDict {
|
|||
/// This is equivalent to the python expression `list(dict.keys())`.
|
||||
pub fn keys(&self) -> &PyList {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr::<PyList>(ffi::PyDict_Keys(self.as_ptr()))
|
||||
self.py().from_owned_ptr::<PyList>(ffi::PyDict_Keys(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ impl PyDict {
|
|||
/// This is equivalent to the python expression `list(dict.values())`.
|
||||
pub fn values(&self) -> &PyList {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr::<PyList>(ffi::PyDict_Values(self.as_ptr()))
|
||||
self.py().from_owned_ptr::<PyList>(ffi::PyDict_Values(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ impl PyDict {
|
|||
/// This is equivalent to the python expression `list(dict.items())`.
|
||||
pub fn items(&self) -> &PyList {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr::<PyList>(ffi::PyDict_Items(self.as_ptr()))
|
||||
self.py().from_owned_ptr::<PyList>(ffi::PyDict_Items(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ impl<'a> Iterator for PyDictIterator<'a> {
|
|||
let mut value: *mut ffi::PyObject = mem::uninitialized();
|
||||
if ffi::PyDict_Next(self.dict.as_ptr(), &mut self.pos, &mut key, &mut value) != 0 {
|
||||
let py = self.dict.py();
|
||||
Some((py.cast_from_borrowed_ptr(key), py.cast_from_borrowed_ptr(value)))
|
||||
Some((py.from_borrowed_ptr(key), py.from_borrowed_ptr(value)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ impl UnicodeDecodeError {
|
|||
range: ops::Range<usize>, reason: &CStr) -> PyResult<&'p PyObjectRef> {
|
||||
unsafe {
|
||||
let input: &[c_char] = mem::transmute(input);
|
||||
py.cast_from_ptr_or_err(
|
||||
py.from_owned_ptr_or_err(
|
||||
ffi::PyUnicodeDecodeError_Create(
|
||||
encoding.as_ptr(),
|
||||
input.as_ptr(),
|
||||
|
|
|
@ -24,7 +24,8 @@ impl <'p> PyIterator<'p> {
|
|||
let ptr = ffi::PyObject_GetIter(obj.as_ptr());
|
||||
|
||||
if ffi::PyIter_Check(ptr) != 0 {
|
||||
Ok(PyIterator(py.cast_from_borrowed_ptr(ptr)))
|
||||
// this is not right, but this cause of segfault check #71
|
||||
Ok(PyIterator(py.from_borrowed_ptr(ptr)))
|
||||
} else {
|
||||
Err(PyDowncastError)
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ impl<'p> Iterator for PyIterator<'p> {
|
|||
let py = self.0.py();
|
||||
|
||||
match unsafe {
|
||||
py.cast_from_ptr_or_opt(ffi::PyIter_Next(self.0.as_ptr())) }
|
||||
py.from_owned_ptr_or_opt(ffi::PyIter_Next(self.0.as_ptr())) }
|
||||
{
|
||||
Some(obj) => Some(Ok(obj)),
|
||||
None => {
|
||||
|
|
|
@ -25,14 +25,14 @@ impl PyList {
|
|||
let obj = e.to_object(py).into_ptr();
|
||||
ffi::PyList_SetItem(ptr, i as Py_ssize_t, obj);
|
||||
}
|
||||
py.cast_from_ptr::<PyList>(ptr)
|
||||
py.from_owned_ptr::<PyList>(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a new empty list.
|
||||
pub fn empty(py: Python) -> &PyList {
|
||||
unsafe {
|
||||
py.cast_from_ptr::<PyList>(ffi::PyList_New(0))
|
||||
py.from_owned_ptr::<PyList>(ffi::PyList_New(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ impl PyList {
|
|||
/// Panics if the index is out of range.
|
||||
pub fn get_item(&self, index: isize) -> &PyObjectRef {
|
||||
unsafe {
|
||||
self.py().cast_from_borrowed_ptr(
|
||||
self.py().from_borrowed_ptr(
|
||||
ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl PyModule {
|
|||
pub fn new<'p>(py: Python<'p>, name: &str) -> PyResult<&'p PyModule> {
|
||||
let name = CString::new(name)?;
|
||||
unsafe {
|
||||
py.cast_from_ptr_or_err(
|
||||
py.from_owned_ptr_or_err(
|
||||
ffi::PyModule_New(name.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ impl PyModule {
|
|||
pub fn import<'p>(py: Python<'p>, name: &str) -> PyResult<&'p PyModule> {
|
||||
let name = CString::new(name)?;
|
||||
unsafe {
|
||||
py.cast_from_ptr_or_err(
|
||||
py.from_owned_ptr_or_err(
|
||||
ffi::PyImport_ImportModule(name.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ impl PyModule {
|
|||
/// this object is the same as the `__dict__` attribute of the module object.
|
||||
pub fn dict(&self) -> &PyDict {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr::<PyDict>(
|
||||
self.py().from_owned_ptr::<PyDict>(
|
||||
ffi::PyModule_GetDict(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn concat(&self, other: &PySequence) -> PyResult<&PySequence> {
|
||||
unsafe {
|
||||
let ptr = self.py().cast_from_ptr_or_err::<PyObjectRef>(
|
||||
let ptr = self.py().from_owned_ptr_or_err::<PyObjectRef>(
|
||||
ffi::PySequence_Concat(self.as_ptr(), other.as_ptr()))?;
|
||||
Ok(std::mem::transmute(ptr))
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn repeat(&self, count: isize) -> PyResult<&PySequence> {
|
||||
unsafe {
|
||||
let ptr = self.py().cast_from_ptr_or_err::<PyObjectRef>(
|
||||
let ptr = self.py().from_owned_ptr_or_err::<PyObjectRef>(
|
||||
ffi::PySequence_Repeat(self.as_ptr(), count as Py_ssize_t))?;
|
||||
Ok(std::mem::transmute(ptr))
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn get_item(&self, index: isize) -> PyResult<&PyObjectRef> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(
|
||||
self.py().from_owned_ptr_or_err(
|
||||
ffi::PySequence_GetItem(self.as_ptr(), index as Py_ssize_t))
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn get_slice(&self, begin: isize, end: isize) -> PyResult<&PyObjectRef> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(
|
||||
self.py().from_owned_ptr_or_err(
|
||||
ffi::PySequence_GetSlice(
|
||||
self.as_ptr(), begin as Py_ssize_t, end as Py_ssize_t))
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn list(&self) -> PyResult<&PyList> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(ffi::PySequence_List(self.as_ptr()))
|
||||
self.py().from_owned_ptr_or_err(ffi::PySequence_List(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ impl PySequence {
|
|||
#[inline]
|
||||
pub fn tuple(&self) -> PyResult<&PyTuple> {
|
||||
unsafe {
|
||||
self.py().cast_from_ptr_or_err(ffi::PySequence_Tuple(self.as_ptr()))
|
||||
self.py().from_owned_ptr_or_err(ffi::PySequence_Tuple(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ impl PySlice {
|
|||
let ptr = ffi::PySlice_New(ffi::PyLong_FromLong(start as c_long),
|
||||
ffi::PyLong_FromLong(stop as c_long),
|
||||
ffi::PyLong_FromLong(step as c_long));
|
||||
py.cast_from_ptr(ptr)
|
||||
py.from_owned_ptr(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ impl PyString {
|
|||
-> PyResult<&'p PyString>
|
||||
{
|
||||
unsafe {
|
||||
src.py().cast_from_ptr_or_err::<PyString>(
|
||||
src.py().from_owned_ptr_or_err::<PyString>(
|
||||
ffi::PyUnicode_FromEncodedObject(
|
||||
src.as_ptr(),
|
||||
encoding.as_ptr() as *const i8,
|
||||
|
|
|
@ -75,7 +75,7 @@ impl PyTuple {
|
|||
// It's quite inconsistent that this method takes `Python` when `len()` does not.
|
||||
assert!(index < self.len());
|
||||
unsafe {
|
||||
self.py().cast_from_borrowed_ptr(
|
||||
self.py().from_borrowed_ptr(
|
||||
ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ impl PyType {
|
|||
#[inline]
|
||||
pub unsafe fn from_type_ptr(py: Python, p: *mut ffi::PyTypeObject) -> &PyType
|
||||
{
|
||||
py.cast_from_borrowed_ptr::<PyType>(p as *mut ffi::PyObject)
|
||||
py.from_borrowed_ptr::<PyType>(p as *mut ffi::PyObject)
|
||||
}
|
||||
|
||||
/// Gets the name of the PyType.
|
||||
|
|
|
@ -150,13 +150,13 @@ impl<'p> Python<'p> {
|
|||
let res_ptr = ffi::PyRun_StringFlags(code.as_ptr(),
|
||||
start, globals, locals, ::std::ptr::null_mut());
|
||||
|
||||
self.cast_from_ptr_or_err(res_ptr)
|
||||
self.from_owned_ptr_or_err(res_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the Python type object for type `T`.
|
||||
pub fn get_type<T>(self) -> &'p PyType where T: PyTypeObject {
|
||||
unsafe{ self.cast_from_borrowed_ptr(T::type_object().into_ptr()) }
|
||||
unsafe{ self.from_borrowed_ptr(T::type_object().into_ptr()) }
|
||||
}
|
||||
|
||||
/// Import the Python module with the specified name.
|
||||
|
@ -266,7 +266,7 @@ impl<'p> Python<'p> {
|
|||
}
|
||||
|
||||
/// Register `ffi::PyObject` pointer in release pool
|
||||
pub unsafe fn from_borrowed_ptr(self, ptr: *mut ffi::PyObject) -> &'p PyObjectRef
|
||||
pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyObjectRef
|
||||
{
|
||||
if ptr.is_null() {
|
||||
::err::panic_after_error();
|
||||
|
@ -277,7 +277,7 @@ impl<'p> Python<'p> {
|
|||
|
||||
/// Register `ffi::PyObject` pointer in release pool,
|
||||
/// and do unchecked downcast to specific type.
|
||||
pub unsafe fn cast_from_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p T
|
||||
pub unsafe fn from_owned_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p T
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -290,7 +290,7 @@ impl<'p> Python<'p> {
|
|||
|
||||
/// Register `ffi::PyObject` pointer in release pool,
|
||||
/// Do unchecked downcast to specific type. Returns mutable reference.
|
||||
pub unsafe fn mut_cast_from_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p mut T
|
||||
pub unsafe fn mut_from_owned_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p mut T
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -304,7 +304,7 @@ impl<'p> Python<'p> {
|
|||
/// Register owned `ffi::PyObject` pointer in release pool.
|
||||
/// Returns `Err(PyErr)` if the pointer is `null`.
|
||||
/// do unchecked downcast to specific type.
|
||||
pub unsafe fn cast_from_ptr_or_err<T>(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T>
|
||||
pub unsafe fn from_owned_ptr_or_err<T>(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T>
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -318,7 +318,7 @@ impl<'p> Python<'p> {
|
|||
/// Register owned `ffi::PyObject` pointer in release pool.
|
||||
/// Returns `None` if the pointer is `null`.
|
||||
/// do unchecked downcast to specific type.
|
||||
pub unsafe fn cast_from_ptr_or_opt<T>(self, ptr: *mut ffi::PyObject) -> Option<&'p T>
|
||||
pub unsafe fn from_owned_ptr_or_opt<T>(self, ptr: *mut ffi::PyObject) -> Option<&'p T>
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -332,7 +332,7 @@ impl<'p> Python<'p> {
|
|||
/// Register borrowed `ffi::PyObject` pointer in release pool.
|
||||
/// Panics if the pointer is `null`.
|
||||
/// do unchecked downcast to specific type.
|
||||
pub unsafe fn cast_from_borrowed_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p T
|
||||
pub unsafe fn from_borrowed_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p T
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
let p = pythonrun::register_borrowed(self, ptr);
|
||||
|
@ -342,8 +342,7 @@ impl<'p> Python<'p> {
|
|||
/// Register borrowed `ffi::PyObject` pointer in release pool.
|
||||
/// Returns `Err(PyErr)` if the pointer is `null`.
|
||||
/// do unchecked downcast to specific type.
|
||||
pub unsafe fn cast_from_borrowed_ptr_or_err<T>(self, ptr: *mut ffi::PyObject)
|
||||
-> PyResult<&'p T>
|
||||
pub unsafe fn from_borrowed_ptr_or_err<T>(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T>
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -357,8 +356,7 @@ impl<'p> Python<'p> {
|
|||
/// Register borrowed `ffi::PyObject` pointer in release pool.
|
||||
/// Returns `None` if the pointer is `null`.
|
||||
/// do unchecked downcast to specific `T`.
|
||||
pub unsafe fn cast_from_borrowed_ptr_or_opt<T>(self, ptr: *mut ffi::PyObject)
|
||||
-> Option<&'p T>
|
||||
pub unsafe fn from_borrowed_ptr_or_opt<T>(self, ptr: *mut ffi::PyObject) -> Option<&'p T>
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
if ptr.is_null() {
|
||||
|
@ -372,7 +370,7 @@ impl<'p> Python<'p> {
|
|||
/// Register borrowed `ffi::PyObject` pointer in release pool.
|
||||
/// Panics if the pointer is `null`.
|
||||
/// do unchecked downcast to specific `T`, returns mutable reference.
|
||||
pub unsafe fn mut_cast_from_borrowed_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p mut T
|
||||
pub unsafe fn mut_from_borrowed_ptr<T>(self, ptr: *mut ffi::PyObject) -> &'p mut T
|
||||
where T: PyTypeInfo
|
||||
{
|
||||
let p = pythonrun::register_borrowed(self, ptr);
|
||||
|
|
|
@ -244,7 +244,7 @@ impl Drop for ClassWithDrop {
|
|||
|
||||
let _empty1 = PyTuple::empty(py);
|
||||
let _empty2: PyObject = PyTuple::empty(py).into();
|
||||
let _empty3: &PyObjectRef = py.cast_from_ptr(ffi::PyTuple_New(0));
|
||||
let _empty3: &PyObjectRef = py.from_owned_ptr(ffi::PyTuple_New(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue