mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-01 12:40:57 +08:00
Always allocate at least one element
This commit is contained in:
parent
b38ca22e94
commit
2f01f01866
@ -127,7 +127,8 @@ public:
|
|||||||
// allocate zeroed memory if it hasn't been provided
|
// allocate zeroed memory if it hasn't been provided
|
||||||
auto buf_info = info;
|
auto buf_info = info;
|
||||||
if (!buf_info.ptr)
|
if (!buf_info.ptr)
|
||||||
buf_info.ptr = std::calloc(info.size, info.itemsize);
|
// always allocate at least 1 element, same way as NumPy does it
|
||||||
|
buf_info.ptr = std::calloc(std::max(info.size, 1ul), info.itemsize);
|
||||||
if (!buf_info.ptr)
|
if (!buf_info.ptr)
|
||||||
pybind11_fail("NumPy: failed to allocate memory for buffer");
|
pybind11_fail("NumPy: failed to allocate memory for buffer");
|
||||||
auto view = memoryview(buf_info);
|
auto view = memoryview(buf_info);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user