[Pyrex] Total newbie needs code review

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Sep 9 04:54:32 CEST 2005


Chris Stromberger wrote:

>   def pyfunc(self, pyinputs):
>     cdef inputs* cinputs
>     cinputs.s = pyinputs.s

You haven't allocated any memory for the input and
output structs. In this case it looks like you could
allocate them on the stack, i.e.

   def pyfunc(self, pyinputs):
     cdef inputs i
     cdef outputs o
     i.s = pyinputs.s
     # etc

That's assuming cfunc() doesn't retain any pointers
to those structs.

 >    o = cfunc(i, o)

Does cfunc() really take the output struct as a
parameter *and* return it as well? That looks
redundant to me.

By the way, it looks like the nature of the library
you're wrapping means you can't have more than one
instance of Analyzer active at once. In that case,
I probably wouldn't bother making it a class, and
just expose a pair of functions that call init()
and cfunc(). This would make it clearer to the user
that multiple instances aren't possible.

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



More information about the Pyrex mailing list