Skip to content

Commit

Permalink
chore: Improve PyCapsule exception handling (#4232)
Browse files Browse the repository at this point in the history
* Improve pycapsule error handling corner cases

* Handle another corner case

* Simplify err handling code
  • Loading branch information
Skylion007 authored Oct 11, 2022
1 parent ff7b697 commit 0927c4d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ class capsule : public object {
// guard if destructor called while err indicator is set
error_scope error_guard;
auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
if (PyErr_Occurred()) {
if (destructor == nullptr && PyErr_Occurred()) {
throw error_already_set();
}
const char *name = get_name_in_error_scope(o);
Expand All @@ -1843,7 +1843,7 @@ class capsule : public object {
}
});

if (!m_ptr || PyCapsule_SetContext(m_ptr, (void *) destructor) != 0) {
if (!m_ptr || PyCapsule_SetContext(m_ptr, reinterpret_cast<void *>(destructor)) != 0) {
throw error_already_set();
}
}
Expand Down

0 comments on commit 0927c4d

Please sign in to comment.