extracting null pointer address from PyCObject with ctypes

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


On Oct 11, 1:59 pm, Gordon Allott <gordall... at gmail.com> wrote:
> Aaron "Castironpi" Brady wrote:
>
> > What does print pythonapi.PyCObject_AsVoidPtr(display) give you?
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> 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 65, in _createWindow
>     print pythonapi.PyCObject_AsVoidPtr(display)
> ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't
> know how to convert parameter 1
>
> --
> Gord Allott (gordall... at gmail.com)
>
>  signature.asc
> < 1KViewDownload

If anyone knows this better, feel free to step in.

Put this before the call:

ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ ctypes.py_object ]

The reason is that this is the default signature, which is wrong:

>>> ctypes.pythonapi.PyCObject_AsVoidPtr.restype
<class 'ctypes.c_long'>
>>> ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes
>>>

There are other ways to prototype it if you like, too.



More information about the Python-list mailing list