Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
6bb71c48
Commit
6bb71c48
authored
Oct 15, 2020
by
Henry Schreiner
Committed by
Henry Schreiner
Oct 15, 2020
Browse files
fix: more intp asserts, reinterpret_cast
parent
9ac604a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
include/pybind11/numpy.h
include/pybind11/numpy.h
+10
-3
No files found.
include/pybind11/numpy.h
View file @
6bb71c48
...
...
@@ -34,7 +34,9 @@
whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size
and dimension types (e.g. shape, strides, indexing), instead of inflicting this
upon the library user. */
static_assert
(
sizeof
(
ssize_t
)
==
sizeof
(
Py_intptr_t
),
"ssize_t != Py_intptr_t"
);
static_assert
(
sizeof
(
::
pybind11
::
ssize_t
)
==
sizeof
(
Py_intptr_t
),
"ssize_t != Py_intptr_t"
);
static_assert
(
std
::
is_signed
<
Py_intptr_t
>::
value
,
"Py_intptr_t must be signed"
);
// We now can reinterpret_cast between py::ssize_t and Py_intptr_t (MSVC + PyPy cares)
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
...
...
@@ -590,7 +592,10 @@ public:
auto
&
api
=
detail
::
npy_api
::
get
();
auto
tmp
=
reinterpret_steal
<
object
>
(
api
.
PyArray_NewFromDescr_
(
api
.
PyArray_Type_
,
descr
.
release
().
ptr
(),
(
int
)
ndim
,
shape
->
data
(),
strides
->
data
(),
api
.
PyArray_Type_
,
descr
.
release
().
ptr
(),
(
int
)
ndim
,
// Use reinterpret_cast for PyPy on Windows (remove if fixed, checked on 7.3.1)
reinterpret_cast
<
Py_intptr_t
*>
(
shape
->
data
()),
reinterpret_cast
<
Py_intptr_t
*>
(
strides
->
data
()),
const_cast
<
void
*>
(
ptr
),
flags
,
nullptr
));
if
(
!
tmp
)
throw
error_already_set
();
...
...
@@ -762,7 +767,9 @@ public:
/// then resize will succeed only if it makes a reshape, i.e. original size doesn't change
void
resize
(
ShapeContainer
new_shape
,
bool
refcheck
=
true
)
{
detail
::
npy_api
::
PyArray_Dims
d
=
{
new_shape
->
data
(),
int
(
new_shape
->
size
())
// Use reinterpret_cast for PyPy on Windows (remove if fixed, checked on 7.3.1)
reinterpret_cast
<
Py_intptr_t
*>
(
new_shape
->
data
()),
int
(
new_shape
->
size
())
};
// try to resize, set ordering param to -1 cause it's not used anyway
object
new_array
=
reinterpret_steal
<
object
>
(
...
...
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