fix ref counter for get_kwargs

This commit is contained in:
Nikolay Kim 2017-07-04 10:24:04 +06:00
parent 3028dcf58f
commit a90d8c241f
6 changed files with 8 additions and 11 deletions

View File

@ -24,7 +24,7 @@ pyo3cls = { path = "pyo3cls" }
# backtrace = "0.3"
[dev-dependencies]
compiletest_rs = "*"
#compiletest_rs = "*"
[build-dependencies]
regex = "0.2"

View File

@ -100,6 +100,6 @@ pub unsafe fn get_kwargs<'p>(py: Python<'p>, ptr: *mut ffi::PyObject) -> Option<
if ptr.is_null() {
None
} else {
Some(py.cast_from_ptr::<PyDict>(ptr))
Some(py.cast_from_borrowed_ptr::<PyDict>(ptr))
}
}

View File

@ -51,8 +51,7 @@ impl PyList {
pub fn get_item(&self, index: isize) -> &PyObjectRef {
unsafe {
let ptr = ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t);
let ob = PyObject::from_borrowed_ptr(self.token(), ptr);
self.token().track_object(ob)
self.token().cast_from_borrowed_ptr(ptr)
}
}

View File

@ -391,11 +391,6 @@ impl<'p> Python<'p> {
<T as PyDowncastFrom>::unchecked_mut_downcast_from(p)
}
pub fn track_object(self, obj: PyObject) -> &'p PyObjectRef
{
unsafe { pythonrun::register_owned(self, obj.into_ptr()) }
}
/// Release PyObject reference.
#[inline]
pub fn release<T>(self, ob: T) where T: IntoPyPointer {

View File

@ -1,4 +1,4 @@
extern crate compiletest_rs as compiletest;
//extern crate compiletest_rs as compiletest;
//use std::path::PathBuf;
//use std::env::var;

View File

@ -172,7 +172,7 @@ fn new_with_two_args() {
assert_eq!(obj._data2, 20);
}
#[py::class(freelist=10)]
#[py::class(freelist=2)]
struct ClassWithFreelist{token: PyToken}
#[test]
@ -187,6 +187,9 @@ fn class_with_freelist() {
let inst3 = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap();
assert_eq!(ptr, inst3.as_ptr());
let inst4 = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap();
assert_ne!(ptr, inst4.as_ptr())
}
struct TestDropCall {