Add empty recarray test, check for calloc fail

This commit is contained in:
Ivan Smirnov 2016-06-19 16:05:23 +01:00
parent f10c84eb9b
commit 2e1565e414
2 changed files with 7 additions and 0 deletions

View File

@ -17,3 +17,8 @@ arr = create_rec_simple(3)
assert arr.dtype == dtype
check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], dtype)
check_eq(arr, [(False, 0, 0.0), (True, 1, 1.5), (False, 2, 3.0)], base_dtype)
arr = create_rec_simple(0)
assert arr.dtype == dtype
check_eq(arr, [], dtype)
check_eq(arr, [], base_dtype)

View File

@ -116,6 +116,8 @@ public:
auto buf_info = info;
if (!buf_info.ptr)
buf_info.ptr = std::calloc(info.size, info.itemsize);
if (!buf_info.ptr)
pybind11_fail("NumPy: failed to allocate memory for buffer");
auto view = py::memoryview(buf_info);
API& api = lookup_api();