[Pyrex] Wrapping a (void *) cookie

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Apr 29 07:38:36 CEST 2003


Matthias Baas <baas at ira.uka.de>:

> Instead you 
> can use Python integers to store the pointers:
> 
>      def __new__(self, long c):
>          self.c = <cookie*>c

I don't recommend that, because it's dangerous -- the
user can pass any old integer in, have it blindly converted
to a pointer, and crash the interpreter.

SWIG uses this kind of trick extensively, which is one of
the reasons I don't like it. I specifically designed Pyrex 
to provide much safer ways. Please use them! :-)

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list