#232 added support for Python functions, but it doesn't properly capture objects within the closure.
from starlark_go import *
def global_foo(*args):
print(args)
# works
Starlark(globals={"foo": global_foo}).exec("foo()")
Starlark(globals={"foo": global_foo}).exec("foo(1)")
Starlark(globals={"foo": global_foo}).exec("foo(1,2)")
def mk_foo():
def foo(*args):
print(args)
return foo
# segfaults
Starlark(globals={"foo": mk_foo()}).exec("foo()")
Starlark(globals={"foo": mk_foo()}).exec("foo(1)")
Starlark(globals={"foo": mk_foo()}).exec("foo(1,2)")
Probably not easy to fix, but at least we can track the issue here.
Workaround is to add the objects to some global state, e.g.
_FOOS=[]
def mk_foo():
def foo(*args):
print(args)
_FOOS.append(foo)
return foo
#232 added support for Python functions, but it doesn't properly capture objects within the closure.
Probably not easy to fix, but at least we can track the issue here.
Workaround is to add the objects to some global state, e.g.