mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
fix: more intp asserts, reinterpret_cast
This commit is contained in:
parent
9ac604a3e8
commit
6bb71c48d5
@ -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>(
|
||||
|
Loading…
Reference in New Issue
Block a user