[Cython] local variable handling in generators

Stefan Behnel stefan_ml at behnel.de
Mon May 23 10:29:10 CEST 2011


Vitja Makarov, 23.05.2011 10:13:
> With live variable analysis that should be easy to save/restore only
> active variables at the yield point.

"Active" in the sense of "modified", I suppose? That's what I was expecting.


> Btw now only reaching definitions analysis is implemented. I'm going
> to optimize by replacing sets with bitsets. And then try to implement
> live varaiables.
>
> I'm going to delete variable reference using active variable info, but
> that could introduce small incompatiblity with CPython:
> a = X
> print a #<- a will be decrefed here
> print 'the end'

That incompatibility is not small at all. It breaks this code:

     x = b'abc'
     cdef char* c = x

Even if 'x' is no longer used after this point, it *must not* get freed 
before 'c' is going away as well. That's basically impossible to decide, as 
users may pass 'c' into a function that stores it away for alter use.

I'm fine with deallocating variables that are no longer used after the user 
explicitly assigned None to them (i.e. replace the None assignment by a 
simple "DECREF + set to NULL" in that case). I don't think we should be 
doing more than that.

Stefan


More information about the cython-devel mailing list