Allow borrowed object for PyTuple::get_item.

As per feedback on #890
This commit is contained in:
David Hewitt 2020-05-03 13:39:19 +01:00
parent b7ecec7812
commit 6f74fe6b38

View file

@ -72,10 +72,8 @@ impl PyTuple {
pub fn get_item(&self, index: usize) -> &PyAny { pub fn get_item(&self, index: usize) -> &PyAny {
assert!(index < self.len()); assert!(index < self.len());
unsafe { unsafe {
// PyTuple_GET_ITEM return borrowed ptr; must make owned for safety (see #890). self.py()
let ptr = ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t); .from_borrowed_ptr(ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t))
ffi::Py_INCREF(ptr);
self.py().from_owned_ptr(ptr)
} }
} }