mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 23:30:30 +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
|
.. code-block:: cpp
|
||||||
|
|
||||||
PyObject *result = PySequence_GetItem(obj, index);
|
PyObject *p = PyList_GetItem(obj, index);
|
||||||
py::object o = reinterpret_borrow<py::object>(p);
|
py::object o = reinterpret_borrow<py::object>(p);
|
||||||
// or
|
// or
|
||||||
py::tuple t = reinterpret_borrow<py::tuple>(p); // <-- `p` must be already be a `tuple`
|
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) {
|
static object get(handle obj, size_t index) {
|
||||||
PyObject *result = PySequence_GetItem(obj.ptr(), static_cast<ssize_t>(index));
|
PyObject *result = PySequence_GetItem(obj.ptr(), static_cast<ssize_t>(index));
|
||||||
if (!result) { throw error_already_set(); }
|
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) {
|
static void set(handle obj, size_t index, handle val) {
|
||||||
|
Loading…
Reference in New Issue
Block a user