mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
bugfix: Add error checking to list append and insert (#4208)
This commit is contained in:
parent
da8c730a62
commit
c78dfe6964
@ -2022,14 +2022,20 @@ public:
|
|||||||
detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
|
detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void append(T &&val) /* py-non-const */ {
|
void append(T &&val) /* py-non-const */ {
|
||||||
PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
|
if (PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) != 0) {
|
||||||
|
throw error_already_set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <typename IdxType,
|
template <typename IdxType,
|
||||||
typename ValType,
|
typename ValType,
|
||||||
detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
|
detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
|
||||||
void insert(const IdxType &index, ValType &&val) /* py-non-const */ {
|
void insert(const IdxType &index, ValType &&val) /* py-non-const */ {
|
||||||
PyList_Insert(
|
if (PyList_Insert(m_ptr,
|
||||||
m_ptr, ssize_t_cast(index), detail::object_or_cast(std::forward<ValType>(val)).ptr());
|
ssize_t_cast(index),
|
||||||
|
detail::object_or_cast(std::forward<ValType>(val)).ptr())
|
||||||
|
!= 0) {
|
||||||
|
throw error_already_set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user