Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
51140159
Commit
51140159
authored
Jul 02, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use malloc insterad of calloc for numpy arrays
parent
5412a05c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
include/pybind11/numpy.h
+5
-4
No files found.
include/pybind11/numpy.h
View file @
51140159
...
...
@@ -126,16 +126,17 @@ public:
Py_ssize_t
dims
[
32
];
API
&
api
=
lookup_api
();
// Allocate zeroed memory if it hasn't been provided by the caller.
// Allocate
non-
zeroed memory if it hasn't been provided by the caller.
// Normally, we could leave this null for NumPy to allocate memory for us, but
// since we need a memoryview, the data pointer has to be non-null. NumPy uses
// malloc if NPY_NEEDS_INIT is not set (in which case it uses calloc); however,
// we don't have a descriptor yet (only a buffer format string), so we can't
// access the flags. The safest thing to do is thus to use calloc.
// we don't have a desriptor yet (only a buffer format string), so we can't
// access the flags. As long as we're not dealing with object dtypes/fields
// though, the memory doesn't have to be zeroed so we use malloc.
auto
buf_info
=
info
;
if
(
!
buf_info
.
ptr
)
// always allocate at least 1 element, same way as NumPy does it
buf_info
.
ptr
=
std
::
calloc
(
std
::
max
(
info
.
size
,
(
size_t
)
1
),
info
.
itemsize
);
buf_info
.
ptr
=
std
::
malloc
(
std
::
max
(
info
.
size
,
(
size_t
)
1
)
*
info
.
itemsize
);
if
(
!
buf_info
.
ptr
)
pybind11_fail
(
"NumPy: failed to allocate memory for buffer"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment