I'd like to get a pointer to raw binary data of bytes, bytearray, or memoryview instance via ctypes and Python API.
For reading, (c_char * len(b)).from_buffer(b) works in Python 3. For writing, I used the following:
buffer = c_void_p()
length = c_ssize_t()
pythonapi.PyObject_AsReadBuffer(py_object(b), byref(buffer), byref(length))
However I found out that the code doesn't work in Python 2.7 with memoryview.