mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-21 16:09:22 +00:00
Bug fix: Remove what();
from restore()
.
It sure would need to be guarded by `if (m_type)`, otherwise `what()` fails and masks that no error was set (see update unit test). But since `error_already_set` is copyable, there is no point in releasing m_type, m_value, m_trace, therefore we can just as well avoid the runtime overhead of force-building `m_lazy_what`, it may never be used.
This commit is contained in:
parent
c7a7146875
commit
de84a27fd4
@ -455,13 +455,13 @@ public:
|
||||
}
|
||||
|
||||
/// Restores the currently-held Python error, if any (which will clear the Python error
|
||||
/// indicator first if already set). After this call, the current object no longer stores the
|
||||
/// error variables (but the `.what()` string is still available).
|
||||
/// indicator first if already set).
|
||||
void restore() {
|
||||
what(); // Force-build m_lazy_what.
|
||||
if (m_type) {
|
||||
// As long as this type is copyable, there is no point in releasing m_type, m_value,
|
||||
// m_trace.
|
||||
PyErr_Restore(
|
||||
m_type.release().ptr(), m_value.release().ptr(), m_trace.release().ptr());
|
||||
m_type.inc_ref().ptr(), m_value.inc_ref().ptr(), m_trace.inc_ref().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,9 @@ def test_std_exception(msg):
|
||||
|
||||
|
||||
def test_error_already_set(msg):
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
with pytest.raises(SystemError) as excinfo:
|
||||
m.throw_already_set(False)
|
||||
assert msg(excinfo.value) == "Unknown internal error occurred"
|
||||
assert "without setting an error" in str(excinfo.value)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
m.throw_already_set(True)
|
||||
|
Loading…
Reference in New Issue
Block a user