mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-30 23:02:37 +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) {
|
||||
ssize_t result = PyObject_Length(h.ptr());
|
||||
if (result < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user