Converting void * to PyObject * in Pyrex
Ganesan R
rganesan at myrealbox.com
Thu Mar 13 23:25:15 EST 2003
Hi,
Is there a mailing list for Pyrex? Since Greg appears to be active in this
newsgroup I hope he will notice this posting. Hey Greg, thanks for an
amazing tool :-).
I am experimenting with Pyrex to write a Python wrapper for OpenSLP
(http://www.openslp.org). I have now run into a road block. Most
of the APIs return results using a callback. In addition to exposing
the callback API to Python, I want to provide a convenience function to
return the results in a Python list.
Since the callback APIs take a cookie, the easiest way to do this is to pass
a Python list to the cookie. For eg, take this callback function in Pyrex
---------
ctypedef SLPBoolean SLPSrvTypeCallback(SLPHandle hSLP,
char* pcSrvTypes,
SLPError errCode,
void *pvCookie)
cdef SLPBoolean MySLPSrvTypeCallback(SLPHandle slph, char *srvtype,
SLPError errcode, void *cookie):
srvtypelist = <PyObject *>cookie
if errcode == SLP_OK:
srvtypelist.append(srvtype)
elif errcode == SLP_LAST_CALL:
pass
else:
raise SLPException(errcode)
return SLP_TRUE
-------
cookie is really a python list cast to void *. Pyrex complains:
/home/rganesan/sf/openslp/pyrex/slp.pyx:40:28: Declarator should be empty
/home/rganesan/sf/openslp/pyrex/slp.pyx:40:28: Expected '>'
How do I fix this?
Thanks.
Ganesan
--
Ganesan R
More information about the Python-list
mailing list