469,271 Members | 1,431 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

mmap and ctypes

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=...s/mmapmodule.c

Aug 16 '08 #1
5 3828
Hi!

I use mmap for interchange data between Python & Autoit. For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.

@-salutations
--
Michel Claveau

Aug 16 '08 #2
On Aug 16, 4:42*pm, "Michel Claveau - NoSpam SVP ; merci"
<noZ.sp...@ZZ.ZsvpZ.comwrote:
Hi!

I use mmap for interchange data between Python & Autoit. *For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.

@-salutations
--
Michel Claveau
Say more-- what DLL? @-greetings
Aug 16 '08 #3
On Aug 16, 5:20*pm, castironpi <castiro...@gmail.comwrote:
On Aug 16, 4:42*pm, "Michel Claveau - NoSpam SVP ; merci"

<noZ.sp...@ZZ.ZsvpZ.comwrote:
Hi!
I use mmap for interchange data between Python & Autoit. *For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.
@-salutations
--
Michel Claveau

Say more-- what DLL? *@-greetings
This worked to 'cast' the mmap memory block to an integer:

a= ctypesbuf.get( m, 0, ctypes.POINTER( ctypes.c_uint32 ) )

where ctypesbuf is a C extension module, and 'get' contains:

...
char* seg= map->data+ index;
PyObject* char_buf= PyObject_CallFunction( ctypesmod_cast, "IO",
seg, tp );
return char_buf;

However I find no equivalent to 'map->data' in Python.
Aug 17 '08 #4
Hi!

See here:
http://www.ponx.org/download/CD/COMdll/autoitmmap.dll

@-salutations
--
Michel Claveau

Aug 18 '08 #5
On Aug 18, 1:09*am, "Méta-MCI \(MVP\)"
<enleverlesX.X...@XmclaveauX.comwrote:
Hi!

See here:
*http://www.ponx.org/download/CD/COMdll/autoitmmap.dll

@-salutations
--
Michel Claveau
I don't see how it fits in.
Aug 21 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hao Xu | last post: by
4 posts views Thread by Fabiano Sidler | last post: by
1 post views Thread by sjdevnull | last post: by
1 post views Thread by James T. Dennis | last post: by
1 post views Thread by koara | last post: by
2 posts views Thread by Neal Becker | last post: by
reply views Thread by Kris Kennaway | last post: by
reply views Thread by Gabriel Genellina | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.