fix memory leak in PyList::set_item and insert_item
This commit is contained in:
parent
1035aaae49
commit
e23c7247e6
|
@ -97,11 +97,6 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident,
|
|||
unsafe { _pyo3::PyObject::from_borrowed_ptr(py, self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
impl std::convert::AsRef<PyObjectRef> for #cls {
|
||||
fn as_ref(&self) -> &_pyo3::PyObjectRef {
|
||||
unsafe{&*(self.as_ptr() as *const _pyo3::PyObjectRef)}
|
||||
}
|
||||
}
|
||||
impl<'a> std::convert::From<&'a mut #cls> for &'a #cls
|
||||
{
|
||||
fn from(ob: &'a mut #cls) -> Self {
|
||||
|
|
|
@ -216,7 +216,7 @@ impl AsPyRef<PyObjectRef> for PyObject {
|
|||
|
||||
#[inline]
|
||||
fn as_ref(&self, _py: Python) -> &PyObjectRef {
|
||||
unsafe {std::mem::transmute(self)}
|
||||
unsafe {&*(self as *const _ as *mut PyObjectRef)}
|
||||
}
|
||||
#[inline]
|
||||
fn as_mut(&self, _py: Python) -> &mut PyObjectRef {
|
||||
|
|
|
@ -71,10 +71,11 @@ impl PyList {
|
|||
pub fn set_item<I>(&self, index: isize, item: I) -> PyResult<()>
|
||||
where I: ToPyObject
|
||||
{
|
||||
item.with_borrowed_ptr(self.py(), |item| unsafe {
|
||||
let item = item.to_object(self.py());
|
||||
unsafe {
|
||||
err::error_on_minusone(
|
||||
self.py(), ffi::PyList_SetItem(self.as_ptr(), index, item))
|
||||
})
|
||||
self.py(), ffi::PyList_SetItem(self.as_ptr(), index, item.into_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts an item at the specified index.
|
||||
|
@ -83,10 +84,11 @@ impl PyList {
|
|||
pub fn insert_item<I>(&self, index: isize, item: I) -> PyResult<()>
|
||||
where I: ToPyObject
|
||||
{
|
||||
item.with_borrowed_ptr(self.py(), |item| unsafe {
|
||||
let item = item.to_object(self.py());
|
||||
unsafe {
|
||||
err::error_on_minusone(
|
||||
self.py(), ffi::PyList_Insert(self.as_ptr(), index, item))
|
||||
})
|
||||
self.py(), ffi::PyList_Insert(self.as_ptr(), index, item.into_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue