diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2008-10-19 08:27:43 (GMT) |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2008-10-19 08:27:43 (GMT) |
commit | 35e01fbeaab6a1d7ce63b974677b823a7e3228ff (patch) | |
tree | 760a527d869ee9821d66b68f3ba403b088cab041 /Parser | |
parent | 92b70bcc6e469e001616fadc5f7be125a90b6c63 (diff) | |
download | cpython-35e01fbeaab6a1d7ce63b974677b823a7e3228ff.zip cpython-35e01fbeaab6a1d7ce63b974677b823a7e3228ff.tar.gz cpython-35e01fbeaab6a1d7ce63b974677b823a7e3228ff.tar.bz2 |
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 4613500..46688a3 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -824,12 +824,30 @@ static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena) return 0; } +static int add_ast_fields() +{ + PyObject *empty_tuple, *d; + if (PyType_Ready(&AST_type) < 0) + return -1; + d = AST_type.tp_dict; + empty_tuple = PyTuple_New(0); + if (!empty_tuple || + PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || + PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { + Py_XDECREF(empty_tuple); + return -1; + } + Py_DECREF(empty_tuple); + return 0; +} + """, 0, reflow=False) self.emit("static int init_types(void)",0) self.emit("{", 0) self.emit("static int initialized;", 1) self.emit("if (initialized) return 1;", 1) + self.emit("if (add_ast_fields() < 0) return 0;", 1) for dfn in mod.dfns: self.visit(dfn) self.emit("initialized = 1;", 1) |