Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

Claudio Grondi claudio.grondi at freenet.de
Wed Apr 6 19:43:40 EDT 2005


Thomas Heller,
  it seems, that your email address
  theller at python.net doesn't work
  or at least don't accept attachments,
  so maybe you can provide me with
  another one?

> ptr = cast(pBuf, POINTER(Buffer))
> print ptr # should print <ctypes.LP_Buffer object at ...>
> struct = ptr[0]

results in breakdown of Python
(Windows exception, can't read from memory
at 0x0...07)
due to existance of
> ptr = cast(pBuf, POINTER(Buffer))
but the print
> print ptr # should print <ctypes.LP_Buffer object at ...>
does its output to the console...

Strange...

Claudio

"Thomas Heller" <theller at python.net> schrieb im Newsbeitrag
news:y8bvy7vd.fsf at python.net...
> "Claudio Grondi" <claudio.grondi at freenet.de> writes:
>
> >> For the mistake you made see below, hope that helps.
> > It doesn't.
> >
> >> >     pBuf_buf = cast(pBuf, Buffer)
> >> Here's the problem.  pBuf is a pointer to a Buffer structure, not the
> >> buffer structure itself.
> >> Something like
> >>     pBuf_buf = Buffer.from_address(pBuf)
> >> may work.
> > If I currently understand it right, cast() should
> > do exactly this, i.e. should write the content
> > pointed to by pBuf to a Python variable
> > pBuf_buf which is an object of the Buffer
> > class, where I can access the single
> > components like any other Python
> > variables - am I right or wrong?
>
> You are right - my bad.
> pBuf is a pointer to your structure, so:
>
> ptr = cast(pBuf, POINTER(Buffer))
> print ptr # should print <ctypes.LP_Buffer object at ...>
> struct = ptr[0]
>
> and now 'struct' should contain the data that you need.
>
> >> For the general way to solve this problem you should know that you can
> >> access a shared memory area with a certain name also with Python's mmap
> >> module, although that is probably not documented very good.  There was
a
> >> recipe posted a few days ago which showed different ways to acces
shared
> >> memory, with or without ctypes.
> >
> >> > The code I use is provided also here:
> >> >  http://www.codecomments.com/Python/message430495.html
> >> >  http://mail.python.org/pipermail/python-list/2005-March/271853.html
> >> > (the mmap part of it doesn't work at all)
> >
> > So I am already using the recipe, right?
> > But it doesn't work as expected.
> > mmap doesn't work at all failing in
> > shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
> > with WindowsError: [Errno 87] wrong parameter
>
> I get this error when I try to open a non-existing shared memory block.
> From the mmap docs:
>
>   If length is 0, the maximum length of the map is the current size of
>   the file, except that if the file is empty Windows raises an exception
>   (you cannot create an empty mapping on Windows).
>
> If I run it with non-zero length it does not raise an exception
>
>   shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
>
> although it *creates* the shared memory block, IIUC.  Are you sure your
> speedfan app is running when you get the WindowsError?
>
> Thomas





More information about the Python-list mailing list