mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
chore: Improve PyCapsule exception handling (#4232)
* Improve pycapsule error handling corner cases * Handle another corner case * Simplify err handling code
This commit is contained in:
parent
ff7b69714d
commit
0927c4d19e
@ -1829,7 +1829,7 @@ public:
|
||||
// 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);
|
||||
@ -1843,7 +1843,7 @@ public:
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user