Skip to content

Commit d2da33a

Browse files
committed
static_assert should be testing ssize_t not size_t
The numpy strides/sizes/etc. are signed now, but the static_assert didn't get updated to match.
1 parent a4d0d95 commit d2da33a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/pybind11/numpy.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#endif
3030

3131
/* This will be true on all flat address space platforms and allows us to reduce the
32-
whole npy_intp / size_t / Py_intptr_t business down to just size_t for all size
32+
whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size
3333
and dimension types (e.g. shape, strides, indexing), instead of inflicting this
3434
upon the library user. */
35-
static_assert(sizeof(size_t) == sizeof(Py_intptr_t), "size_t != Py_intptr_t");
35+
static_assert(sizeof(ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t");
3636

3737
NAMESPACE_BEGIN(pybind11)
3838

@@ -518,8 +518,8 @@ class array : public buffer {
518518

519519
array() : array({{0}}, static_cast<const double *>(nullptr)) {}
520520

521-
using ShapeContainer = detail::any_container<Py_intptr_t>;
522-
using StridesContainer = detail::any_container<Py_intptr_t>;
521+
using ShapeContainer = detail::any_container<ssize_t>;
522+
using StridesContainer = detail::any_container<ssize_t>;
523523

524524
// Constructs an array taking shape/strides from arbitrary container types
525525
array(const pybind11::dtype &dt, ShapeContainer shape, StridesContainer strides,
@@ -752,7 +752,7 @@ class array : public buffer {
752752
throw std::domain_error("array is not writeable");
753753
}
754754

755-
static std::vector<Py_intptr_t> default_strides(const std::vector<Py_intptr_t>& shape, ssize_t itemsize) {
755+
static std::vector<ssize_t> default_strides(const std::vector<ssize_t>& shape, ssize_t itemsize) {
756756
auto ndim = shape.size();
757757
std::vector<ssize_t> strides(ndim);
758758
if (ndim) {

0 commit comments

Comments
 (0)