* 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.
This commit is contained in:
Neal Norwitz 2006-04-03 04:50:58 +00:00
parent 92e212f7d9
commit 19379f18a6
2 changed files with 153 additions and 149 deletions

View File

@ -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')

View File

@ -381,10 +381,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);
@ -392,7 +392,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*))
@ -432,9 +434,9 @@ static PyObject* ast2obj_int(bool b)
return PyInt_FromLong(b);
}
static int initialized;
static int init_types(void)
{
static int initialized;
if (initialized) return 1;
AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
mod_type = make_type("mod", AST_type, NULL, 0);
@ -3033,146 +3035,146 @@ init_ast(void)
return;
if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
return;
if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
return;
if(PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
< 0) return;
if(PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
0) return;
if(PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
if(PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
if(PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
< 0) return;
if(PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
return;
if(PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
return;
if(PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
return;
if(PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
return;
if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
return;
if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
if(PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
return;
if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
0) return;
if(PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
return;
if(PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
return;
if(PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
0) return;
if(PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
if(PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
return;
if(PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
if(PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
if(PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
if(PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
return;
if(PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
if(PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
return;
if(PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
if(PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
return;
if(PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
return;
if(PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
if(PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
if(PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
return;
if(PyDict_SetItemString(d, "GeneratorExp",
(PyObject*)GeneratorExp_type) < 0) return;
if(PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
if(PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
return;
if(PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
if(PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
if(PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
if(PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
return;
if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
return;
if(PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
if(PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
if(PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
if(PyDict_SetItemString(d, "expr_context",
(PyObject*)expr_context_type) < 0) return;
if(PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
if(PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
if(PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
if(PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
return;
if(PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
return;
if(PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
if(PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
if(PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
return;
if(PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
if(PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
return;
if(PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
if(PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
return;
if(PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
if(PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
if(PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
return;
if(PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
if(PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
if(PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
if(PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
if(PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
if(PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
if(PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
return;
if(PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
return;
if(PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
if(PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
return;
if(PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
return;
if(PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
return;
if(PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
return;
if(PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
return;
if(PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
if(PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
if(PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
if(PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
if(PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
if(PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
if(PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
if(PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
if(PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
if(PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
if(PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
if(PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
if(PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
if(PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
if(PyDict_SetItemString(d, "comprehension",
(PyObject*)comprehension_type) < 0) return;
if(PyDict_SetItemString(d, "excepthandler",
(PyObject*)excepthandler_type) < 0) return;
if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
return;
if(PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
return;
if(PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
return;
if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
< 0) return;
if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
0) return;
if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
< 0) return;
if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
return;
if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
return;
if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
return;
if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
return;
if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
0) return;
if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
0) return;
if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
0) return;
if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
return;
if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
return;
if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
0) return;
if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
return;
if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
return;
if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
return;
if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
return;
if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
return;
if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
return;
if (PyDict_SetItemString(d, "GeneratorExp",
(PyObject*)GeneratorExp_type) < 0) return;
if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
return;
if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
0) return;
if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
0) return;
if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
if (PyDict_SetItemString(d, "expr_context",
(PyObject*)expr_context_type) < 0) return;
if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
return;
if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
return;
if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
return;
if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
return;
if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
return;
if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
return;
if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
return;
if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
return;
if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
return;
if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
return;
if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
return;
if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
return;
if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
return;
if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
if (PyDict_SetItemString(d, "comprehension",
(PyObject*)comprehension_type) < 0) return;
if (PyDict_SetItemString(d, "excepthandler",
(PyObject*)excepthandler_type) < 0) return;
if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
0) return;
if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
return;
if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
}