byterun icon indicating copy to clipboard operation
byterun copied to clipboard

closure Frame initialization uses wrong outer frame

Open matthiaskramm opened this issue 10 years ago • 2 comments

The current version of byterun accesses cellvars through the frame the closure is executing under, instead of the frame it was defined in. The following code illustrates the problem:

def f(): x = ["foo"] def inner(): x[0] = "bar" return inner

def g(funcptr): x = 5 def inner(): return x y = funcptr()

g(f())

AssertionError: "'int' object does not support item assignment" != 'None'

matthiaskramm avatar Feb 24 '15 19:02 matthiaskramm

I thought I fixed this in my branch. Could you check against https://github.com/google/byterun ? I know I did some work on closure capture.

It never got merged because I never had the time to clean the code to get it accepted by nedbat.

arthurp avatar Mar 02 '15 18:03 arthurp

Arthur: I'm afraid it's broken in your branch as well - both use f_back to link cells to their function, instead of using the closure parameter of pyobj.Function. The f_back trick is a surprisingly good approximation, though, and all of the existing test cases work with it. But the above is still broken.

matthiaskramm avatar Mar 02 '15 21:03 matthiaskramm