The python documentation on array clearly states that the array conforms to the buffer interface. It even suggest not using the buffer_info() method. But when I try to get a Py_Buffer from C/C++ code with PyObject_GetBuffer() or use python's memoryview, I get a failure.
For example, in python (I use version 2.7):
>>> a = array.array('c')
>>> memoryview(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot make memory view because object does not have the buffer interface
In fact, when I search python's code base, only bytearrayobject (bytearray), memoryobject (memoryview), and stringobject (str) have the required Py_TPFLAGS_HAVE_NEWBUFFER flag set on them. To my understanding, the documentation is wrong; array does not support the buffer interface.
I could use bytearray which supports the buffer interface, the problem is that I need the array's practical fromfile() method to read in a buffer that I can use in my C/C++ code.
Is there an alternative that would allow me to read a file into a buffer and use this buffer from C code, and not involve memory copies ? (I want to treat big binary files and copying is a less desirable option).