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
1 changed files with 2 additions and 4 deletions

View File

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