6
コード使用している場合、セグメンテーションフォールトを取得:はCPythonとPyPyの両方でPythonは:/ evalのコンパイル
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"]
を、私はセグメンテーションフォールトを取得しています。どうして?
関数の本体に 'pass'を入れずに空の関数を定義すると、Pythonは構文エラーを返します。 – JAB
です。それはセグメンテーションしません。 –
これは、現在のところASTは検証されていないため、このような問題を避けるためにコンパイルしようとすると、ASTにバリデーターを追加するオープンチケットがCPythonにあります。 –