Compare commits

..

1 Commits

Author SHA1 Message Date
Deepanjali Pathak
8237a3da69
Merge 4578d64a9b5db9132c6368449bbab1024ebfd54b into a2f16e5f1f5fcc3b3d2cc1bdacfc3a027dfe2d76 2026-03-19 14:50:04 +05:30
2 changed files with 1 additions and 23 deletions

View File

@ -70,7 +70,6 @@ args_proxy interface<Derived>::operator* () const {
template <typename Derived>
template <return_value_policy policy, typename... Args>
object interface<Derived>::operator() (Args&&... args) const {
py_StackRef p0 = py_peek(0); // checkpoint before pushing so py_clearexc can safely rewind
py_push(ptr());
py_pushnil();
@ -109,13 +108,7 @@ object interface<Derived>::operator() (Args&&... args) const {
(foreach(std::forward<Args>(args)), ...);
if(!py_vectorcall(argc, kwargsc)) {
py_matchexc(tp_Exception);
object e = object::from_ret();
auto what = py_formatexc();
py_clearexc(p0);
throw python_error(what, std::move(e));
}
raise_call<py_vectorcall>(argc, kwargsc);
return object::from_ret();
}

View File

@ -79,18 +79,3 @@ TEST_F(PYBIND11_TEST, exception_cpp_to_python) {
TEST_EXCEPTION(attribute_error, AttributeError);
TEST_EXCEPTION(runtime_error, RuntimeError);
}
// Regression test: operator() must throw python_error instead of crashing when Python raises (#469)
TEST_F(PYBIND11_TEST, operator_call_propagates_python_error) {
py::exec("def f(x):\n raise ValueError('intentional error')");
py::object fn = py::eval("f");
bool caught = false;
try {
fn(py::int_(1));
} catch(py::python_error& e) {
caught = true;
EXPECT_TRUE(e.match(tp_ValueError));
}
EXPECT_TRUE(caught);
}