mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-19 17:32:37 +00:00
Fix sequence_item reference leak (#660)
This commit is contained in:
parent
5e92b3e608
commit
a76ed42c3f
@ -254,7 +254,7 @@ public:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
PyObject *result = PySequence_GetItem(obj, index);
|
||||
PyObject *p = PyList_GetItem(obj, index);
|
||||
py::object o = reinterpret_borrow<py::object>(p);
|
||||
// or
|
||||
py::tuple t = reinterpret_borrow<py::tuple>(p); // <-- `p` must be already be a `tuple`
|
||||
@ -453,7 +453,7 @@ struct sequence_item {
|
||||
static object get(handle obj, size_t index) {
|
||||
PyObject *result = PySequence_GetItem(obj.ptr(), static_cast<ssize_t>(index));
|
||||
if (!result) { throw error_already_set(); }
|
||||
return reinterpret_borrow<object>(result);
|
||||
return reinterpret_steal<object>(result);
|
||||
}
|
||||
|
||||
static void set(handle obj, size_t index, handle val) {
|
||||
|
Loading…
Reference in New Issue
Block a user