[Pyrex] defining extern variables in pyrex
Thys Meintjes
thys at sentechsa.com
Thu Apr 14 01:30:27 CEST 2005
On Wed, 2005-04-13 at 11:57 +1200, Michael JasonSmith wrote:
> On Tue, 2005-04-12 at 18:58 -0400, David M. Cooke wrote:
> > 2) (Better, more intrusive) Modify the library. Remove the global
> > variables, and pass the state variables to each library routine.
> > This becomes easy if you make a struct whose members are the old
> > global variables, and pass that struct to each routine (instead of
> > passing each variable individually). Again, keep that state in your
> > wrapped class.
> This is indeed a nice solution. I really should add a page to my Pyrex
> Guide on global variables. However, I am afraid that I would end up
> advocating violence against all those that write modules that use them!
And with good reason.
Thanks David, Michael. I went with 2), and while it's a good few hours
of irksome spadework, it's getting there. I believe the first option
would not have been thread-save without a lot of footwork. As a added
benefit it's also more convenient/compact to expose a few structs to
Python than a lot of variables.
Michael, I think a "Converting old libs to modules" or "Annoying Library
Gotchas" section in your excellent Quick guide would be a worthwhile
addition.
Thanks again
Thys
More information about the Pyrex
mailing list