From 2e1565e414bbc34e72a67bfdbf44c2706546d355 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Sun, 19 Jun 2016 16:05:23 +0100 Subject: [PATCH] Add empty recarray test, check for calloc fail --- example/example20.py | 5 +++++ include/pybind11/numpy.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/example/example20.py b/example/example20.py index ed3454860..d1bc94238 100644 --- a/example/example20.py +++ b/example/example20.py @@ -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) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 92ab11670..6e9a629db 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -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();