mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 06:35:12 +00:00
Add const to buffer:request() (#1890)
This commit is contained in:
parent
8f5a8ab4ac
commit
5b4751af26
@ -1312,7 +1312,7 @@ class buffer : public object {
|
|||||||
public:
|
public:
|
||||||
PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
|
PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
|
||||||
|
|
||||||
buffer_info request(bool writable = false) {
|
buffer_info request(bool writable = false) const {
|
||||||
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
|
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
|
||||||
if (writable) flags |= PyBUF_WRITABLE;
|
if (writable) flags |= PyBUF_WRITABLE;
|
||||||
Py_buffer *view = new Py_buffer();
|
Py_buffer *view = new Py_buffer();
|
||||||
|
@ -78,7 +78,7 @@ TEST_SUBMODULE(buffers, m) {
|
|||||||
py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
|
py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
|
||||||
.def(py::init<ssize_t, ssize_t>())
|
.def(py::init<ssize_t, ssize_t>())
|
||||||
/// Construct from a buffer
|
/// Construct from a buffer
|
||||||
.def(py::init([](py::buffer b) {
|
.def(py::init([](py::buffer const b) {
|
||||||
py::buffer_info info = b.request();
|
py::buffer_info info = b.request();
|
||||||
if (info.format != py::format_descriptor<float>::format() || info.ndim != 2)
|
if (info.format != py::format_descriptor<float>::format() || info.ndim != 2)
|
||||||
throw std::runtime_error("Incompatible buffer format!");
|
throw std::runtime_error("Incompatible buffer format!");
|
||||||
|
Loading…
Reference in New Issue
Block a user