mmap and ctypes

castironpi castironpi at gmail.com
Sat Aug 16 14:34:21 EDT 2008


Hi all,

I have a mmap and a data structure in it.  I know the structure's
location in the mmap and what structure it is.  It has a ctypes
definition.

I want to initialize a ctypes object to point to a part of the mmap.

Here is my attempt:

>>> b
<mmap.mmap object at 0x009FEDB8>
>>> c= ctypes.pointer( b )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\programs\Python25\lib\ctypes\__init__.py", line 318, in
pointer
    return POINTER(type(inst))(inst)
  File "C:\programs\Python25\lib\ctypes\__init__.py", line 262, in
POINTER
    {'_type_': cls})
TypeError: _type_ must have storage info

and then use 'cast', but it fails here.

Is there some way to combine ctypes with struct.pack_into and
struct.unpack_from?  Can I access the mmap's buffer directly?  Could
be very handy and I'm willing to talk about the C function involved.
What kind of modification to mmapmodule would we be looking at?  Does
someone want to do it with me?

I am looking at mmapmodule.c, line 75, access to the char * data
member of mmap_object.  Link is here:

http://www.google.com/codesearch?hl=en&q=mmapmodule.c+show:C2urmIRSr9c:7uYx_idG-6A:xyEMaz16V1Y&sa=N&cd=11&ct=ri&cs_p=http://svn.python.org/snapshots/python25.tar.bz2&cs_f=python/Modules/mmapmodule.c




More information about the Python-list mailing list