summaryrefslogtreecommitdiffstats
path: root/Parser/asdl_c.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-04-03 04:50:58 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-04-03 04:50:58 (GMT)
commit19379f18a6ba7f8baf695f9340eb1ab21a85771e (patch)
treebe61b8559ed74aeac7163f929ded4b64a2f42eb0 /Parser/asdl_c.py
parent92e212f7d95f4c1071f6e2ea0b85cfb36a562814 (diff)
downloadcpython-19379f18a6ba7f8baf695f9340eb1ab21a85771e.zip
cpython-19379f18a6ba7f8baf695f9340eb1ab21a85771e.tar.gz
cpython-19379f18a6ba7f8baf695f9340eb1ab21a85771e.tar.bz2
* Fix a refleak of *_attributes.
* Cleanup formatting a bit (add spaces). * Move static var initialized inside init_types() since that's the only place it's used.
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-xParser/asdl_c.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index ad2209d..bc59c38 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -413,10 +413,10 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
{
- int i;
+ int i, result;
PyObject *s, *l = PyList_New(num_fields);
if (!l) return 0;
- for(i=0; i < num_fields; i++) {
+ for(i = 0; i < num_fields; i++) {
s = PyString_FromString(attrs[i]);
if (!s) {
Py_DECREF(l);
@@ -424,7 +424,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
}
PyList_SET_ITEM(l, i, s);
}
- return PyObject_SetAttrString((PyObject*)type, "_attributes", l) >=0;
+ result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
+ Py_DECREF(l);
+ return result;
}
static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
@@ -465,9 +467,9 @@ static PyObject* ast2obj_int(bool b)
}
""", 0, reflow=False)
- self.emit("static int initialized;", 0)
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('AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);', 1)
for dfn in mod.dfns:
@@ -543,7 +545,7 @@ class ASTModuleVisitor(PickleVisitor):
self.addObj(cons.name)
def addObj(self, name):
- self.emit('if(PyDict_SetItemString(d, "%s", (PyObject*)%s_type) < 0) return;' % (name, name), 1)
+ self.emit('if (PyDict_SetItemString(d, "%s", (PyObject*)%s_type) < 0) return;' % (name, name), 1)
_SPECIALIZED_SEQUENCES = ('stmt', 'expr')