[Python-checkins] r66973 - in python/trunk: Parser/asdl_c.py Python/Python-ast.c
armin.ronacher
python-checkins at python.org
Sun Oct 19 10:27:44 CEST 2008
Author: armin.ronacher
Date: Sun Oct 19 10:27:43 2008
New Revision: 66973
Log:
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Modified:
python/trunk/Parser/asdl_c.py
python/trunk/Python/Python-ast.c
Modified: python/trunk/Parser/asdl_c.py
==============================================================================
--- python/trunk/Parser/asdl_c.py (original)
+++ python/trunk/Parser/asdl_c.py Sun Oct 19 10:27:43 2008
@@ -824,12 +824,30 @@
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)
Modified: python/trunk/Python/Python-ast.c
==============================================================================
--- python/trunk/Python/Python-ast.c (original)
+++ python/trunk/Python/Python-ast.c Sun Oct 19 10:27:43 2008
@@ -615,11 +615,29 @@
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;
+}
+
static int init_types(void)
{
static int initialized;
if (initialized) return 1;
+ if (add_ast_fields() < 0) return 0;
mod_type = make_type("mod", &AST_type, NULL, 0);
if (!mod_type) return 0;
if (!add_attributes(mod_type, NULL, 0)) return 0;
More information about the Python-checkins
mailing list