On 20/09/2012 5:53pm, David Beazley wrote:
How? I must be missing something very obvious.
I would not call it obvious, but you can do
>>> m = memoryview(bytearray(5))
>>> ctypes.addressof(ctypes.c_char.from_buffer(m))
149979304
However, this only works for writable memoryviews. For
read-only memoryviews you could do
>>> obj = ctypes.py_object(m)
>>> address = ctypes.c_void_p()
>>> length = ctypes.c_ssize_t()
>>> ctypes.pythonapi.PyObject_AsReadBuffer(obj,
ctypes.byref(address), ctypes.byref(length))
0
>>> address, length
(c_void_p(149979304), c_long(5))
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com