diff --git a/include/pybind11/internal/function.h b/include/pybind11/internal/function.h index 2c84e756..c1c69dff 100644 --- a/include/pybind11/internal/function.h +++ b/include/pybind11/internal/function.h @@ -70,6 +70,7 @@ args_proxy interface::operator* () const { template template object interface::operator() (Args&&... args) const { + py_StackRef p0 = py_peek(0); // checkpoint before pushing so py_clearexc can safely rewind py_push(ptr()); py_pushnil(); @@ -108,7 +109,13 @@ object interface::operator() (Args&&... args) const { (foreach(std::forward(args)), ...); - raise_call(argc, kwargsc); + 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)); + } return object::from_ret(); }