Hi,
While I get the the nonlocal keyword implemented, now the inner
function is able to write to the closure. This cause refnanny lost
tracking on the closure variables when following the refcounting rules
described at http://wiki.cython.org/refcounting . For example:
def foo():
x=0 # INCREF(0), 0 get traced by refnanny
def bar():
# DECREF(x) refnanny complains since x is not got tracked yet
# INCREF(1)
x=1
# refnanny complains since there is no giveref for 1
bar()
# refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead
For the inner function bar() it is easy to fix. But for the outer
function, since the thing x referenced to can be changed at every
point now, it will not work correctly to giveref at the end of
function.
Since the rule is that closure variables are owned by scope object and
not managed by refnanny. So my idea to fix this is to wrap every
assignment to closure object by a pair of GOTREF and GIVEREF. So when
you do x=1, these will happen:
GOTREF(x)
DECREF(x)
INCREF(1)
x=1
GIVEREF(x)
Then refnanny will be happy.
I implemented this, and got all the closure related tests passed
without refnanny complaining.
This generate a bit more codes but I think should be ok. Since
refnanny is for debug so performance at here would not be a concern.
Any comments?
--
Haoyu BAI
School of Computing,
National University of Singapore.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev