mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Fix buffer_info for ctypes buffers (pybind#2502) (#2503)
* tests: New test for ctypes buffers (pybind#2502) * fix: fix buffer_info segfault on views with no stride (pybind11#2502) * Explicit conversions in buffer_info to make clang happy (pybind#2502) * Another explicit cast in buffer_info constructor for clang (pybind#2502) * Simpler implementation of buffer_info constructor from Py_buffer. * Move test_ctypes_buffer into test_buffers * Comment on why view->strides may be NULL (and fix some whitespace) * Use c_strides() instead of zero when view->strides is NULL. c_strides and f_strides are moved from numpy.h (py::array) to buffer_info.h (py::detail) so they can be used from the buffer_info Py_buffer constructor. * Increase ctypes buffer test coverage in test_buffers. * Split ctypes tests and skip one which is broken in PyPy2.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "pybind11_tests.h"
|
||||
#include "constructor_stats.h"
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
TEST_SUBMODULE(buffers, m) {
|
||||
// test_from_python / test_to_python:
|
||||
@@ -192,4 +193,22 @@ TEST_SUBMODULE(buffers, m) {
|
||||
.def_readwrite("readonly", &BufferReadOnlySelect::readonly)
|
||||
.def_buffer(&BufferReadOnlySelect::get_buffer_info);
|
||||
|
||||
// Expose buffer_info for testing.
|
||||
py::class_<py::buffer_info>(m, "buffer_info")
|
||||
.def(py::init<>())
|
||||
.def_readonly("itemsize", &py::buffer_info::itemsize)
|
||||
.def_readonly("size", &py::buffer_info::size)
|
||||
.def_readonly("format", &py::buffer_info::format)
|
||||
.def_readonly("ndim", &py::buffer_info::ndim)
|
||||
.def_readonly("shape", &py::buffer_info::shape)
|
||||
.def_readonly("strides", &py::buffer_info::strides)
|
||||
.def_readonly("readonly", &py::buffer_info::readonly)
|
||||
.def("__repr__", [](py::handle self) {
|
||||
return py::str("itemsize={0.itemsize!r}, size={0.size!r}, format={0.format!r}, ndim={0.ndim!r}, shape={0.shape!r}, strides={0.strides!r}, readonly={0.readonly!r}").format(self);
|
||||
})
|
||||
;
|
||||
|
||||
m.def("get_buffer_info", [](py::buffer buffer) {
|
||||
return buffer.request();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user