mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 07:10:30 +00:00
Add memoryview type
This commit is contained in:
parent
8b5fc8b5e1
commit
7709d6b77d
@ -570,6 +570,19 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class memoryview : public object {
|
||||||
|
public:
|
||||||
|
memoryview(const buffer_info& info) : memoryview(&info.as_pybuffer()) { }
|
||||||
|
|
||||||
|
memoryview(Py_buffer* view)
|
||||||
|
: object(PyMemoryView_FromBuffer(view), false) {
|
||||||
|
if (!m_ptr)
|
||||||
|
pybind11_fail("Unable to create memoryview from buffer descriptor");
|
||||||
|
}
|
||||||
|
|
||||||
|
PYBIND11_OBJECT_DEFAULT(memoryview, object, PyMemoryView_Check)
|
||||||
|
};
|
||||||
|
|
||||||
inline size_t len(handle h) {
|
inline size_t len(handle h) {
|
||||||
ssize_t result = PyObject_Length(h.ptr());
|
ssize_t result = PyObject_Length(h.ptr());
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user