array: set exception message on failure

When attempting to get a raw array pointer we return nullptr if given a
nullptr, which triggers an error_already_set(), but we haven't set an
exception message, which results in "Unknown internal error".

Callers that want explicit allowing of a nullptr here already handle it
(by clearing the exception after the call).
This commit is contained in:
Jason Rhinelander
2017-04-10 11:05:26 -04:00
parent 257df10ffe
commit 5749b50239
3 changed files with 22 additions and 2 deletions

View File

@@ -264,4 +264,8 @@ test_initializer numpy_array([](py::module &m) {
sm.def("array_auxiliaries2", [](py::array_t<double> a) {
return auxiliaries(a, a);
});
// Issue #785: Uninformative "Unknown internal error" exception when constructing array from empty object:
sm.def("array_fail_test", []() { return py::array(py::object()); });
sm.def("array_t_fail_test", []() { return py::array_t<double>(py::object()); });
});