compilation - Python: getting segmentation fault when using compile/eval -
code:
import ast  globalsdict = {}  fast = ast.functiondef(     name="foo",     args=ast.arguments(args=[], vararg=none, kwarg=none, defaults=[]),     body=[], decorator_list=[])  exprast = ast.interactive(body=[fast]) ast.fix_missing_locations(exprast) compiled = compile(exprast, "<foo>", "single") eval(compiled, globalsdict, globalsdict)  print globalsdict["foo"]   with both cpython , pypy, getting segmentation fault. why?
i guess function definition must not have empty body. tested code adding no-op statement function body:
fast = ast.functiondef(     # ...     body=[ast.pass()],     # ...   and segmentation fault gone; output is:
<function foo @ 0x022db3f0>
if correct, bug in ast module, since should check empty body.
Comments
Post a Comment