Skip to content

Commit da1762e

Browse files
committed
Properly protect py2c conversion of returntype in py2c converted function objects
1 parent cd34df2 commit da1762e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

c++/cpp2py/converters/function.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <functional>
3+
#include "./../misc.hpp"
34

45
namespace cpp2py {
56

@@ -185,6 +186,9 @@ namespace cpp2py {
185186
pyref py_fnt = borrowed(ob);
186187
auto l = [py_fnt](T... x) mutable -> R { // py_fnt is a pyref, it will keep the ref and manage the ref counting...
187188
pyref ret = PyObject_CallFunctionObjArgs(py_fnt, (PyObject *)pyref(convert_to_python(x))..., NULL);
189+
if (not py_converter<R>::is_convertible(ret, false)) {
190+
CPP2PY_RUNTIME_ERROR << "\n Cannot convert function result " << to_string(ret) << " from python to C++";
191+
}
188192
return py_converter<R>::py2c(ret);
189193
};
190194
return l;

0 commit comments

Comments
 (0)