extracting null pointer address from PyCObject with ctypes

Aaron "Castironpi" Brady castironpi at gmail.com
Sat Oct 11 01:06:46 EDT 2008


On Oct 10, 10:54 pm, Gordon Allott <gordall... at gmail.com> wrote:
> Aaron "Castironpi" Brady wrote:
> snip
> > Last, you
> > haven't mentioned an attempt with PyCObject_AsVoidPtr yet:
>
> > void* PyCObject_AsVoidPtr(PyObject* self)
> >     Return the object void * that the PyCObject self was created with.
>
> > Where does that get you?
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> sorry yes you were right, I was reading PyCObject_AsVoidPtr as
> PyCObject_FromVoidPtr :)
>
> using AsVoidPtr is a little confusing, this is the code I am using:
>         display = pygame.display.get_wm_info()['display']
>         pyobj = py_object(display)
>         ref = pointer(pyobj)
>
>         print pythonapi.PyCObject_AsVoidPtr(ref)
>
> it produces the following traceback:
> Traceback (most recent call last):
>   File "pygametest.py", line 125, in <module>
>     app = PyGameOGREApp()
>   File "pygametest.py", line 33, in __init__
>     self._createWindow(width, height, fullscreen)
>   File "pygametest.py", line 64, in _createWindow
>     print pythonapi.PyCObject_AsVoidPtr(ref)
> TypeError: PyCObject_AsVoidPtr with non-C-object
>
> - I think that's because its a pointer to the ctypes py_object() rather
> than the PyCObject we are dealing with but I have no idea how to create
> a pointer to that.
>

My pygame install just returns an integer in get_wm_info.  Take a
look:

>>> pygame.display.get_wm_info()
{'window': 1180066, 'hglrc': 0}
>>> pygame.display.get_wm_info()['window']
1180066
>>> ctypes.c_void_p( _ )
c_void_p(1180066)

You're suggesting yours looks like this:

>>> pygame.display.get_wm_info()
{ ... 'display': ctypes.py_object( 1180066 ), ... }

What does type( display ) give you?



More information about the Python-list mailing list