mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 09:17:42 +00:00
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:
@@ -702,8 +702,10 @@ protected:
|
||||
|
||||
/// Create array from any object -- always returns a new reference
|
||||
static PyObject *raw_array(PyObject *ptr, int ExtraFlags = 0) {
|
||||
if (ptr == nullptr)
|
||||
if (ptr == nullptr) {
|
||||
PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array from a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return detail::npy_api::get().PyArray_FromAny_(
|
||||
ptr, nullptr, 0, 0, detail::npy_api::NPY_ARRAY_ENSUREARRAY_ | ExtraFlags, nullptr);
|
||||
}
|
||||
@@ -808,8 +810,10 @@ public:
|
||||
protected:
|
||||
/// Create array from any object -- always returns a new reference
|
||||
static PyObject *raw_array_t(PyObject *ptr) {
|
||||
if (ptr == nullptr)
|
||||
if (ptr == nullptr) {
|
||||
PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array_t from a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return detail::npy_api::get().PyArray_FromAny_(
|
||||
ptr, dtype::of<T>().release().ptr(), 0, 0,
|
||||
detail::npy_api::NPY_ARRAY_ENSUREARRAY_ | ExtraFlags, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user