[Pyrex] How to deal with a void *

Travis Caldwell travis_caldwell2000 at yahoo.com
Thu May 11 05:49:58 CEST 2006


 I am trying to wrap a C API which uses void * as the type of an opaque
token that gets passed around.

 Basically you have things like:

 void *initResource(....)

 int doSomething( void *resourceID,...) 

 where you get a void * at resource creation and then do nothing with
it excpet to pass it back into other API functions to identify the
resource you wish the function to operate on.

 Looking around I found this thread from three years ago from someone
who seems to have had the exact same problem: 

  http://lists.copyleft.no/pipermail/pyrex/2003-June/000156.html 

 From reading the thread I wasn't quite sure if a conclusion was
reached.

 Just like him, when I try to return the void * directly I get and
error that it can't be turned into a PyObject. 

 I can get the error message to go away by defining a C long varriable
and casting the void * to that. ex:

  cdef void *foo
  cdef unsigned long bar

  foo = initResource()
  bar = <unsigned long> foo


 However I'not really sure if this is safe or if there is a chance of
the value getting mangled in the casting to long and back.


 Any ideas or help would be appreciated.

                   _Travis_Caldwell_



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Pyrex mailing list