[Pyrex] Total newbie needs code review

Chris Stromberger chris.stromberger at gmail.com
Fri Sep 9 14:53:40 CEST 2005


> >   def pyfunc(self, pyinputs):
> >     cdef inputs* cinputs
> >     cinputs.s = pyinputs.s
> 
> You haven't allocated any memory for the input and
> output structs. 

But it seems to work as I wrote it...?  What's going on then?

> 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
> 

Makes sense.  Will try that.

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

Yes, that's how the C lib function is written.  It's 3rd party code. 
I found it odd as well.

> 
> 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.

That makes good sense.  Thanks, will implement that.

-Chris



More information about the Pyrex mailing list