mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
* 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:
parent
92e212f7d9
commit
19379f18a6
2 changed files with 153 additions and 149 deletions
|
@ -413,7 +413,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
|
||||||
|
|
||||||
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
||||||
{
|
{
|
||||||
int i;
|
int i, result;
|
||||||
PyObject *s, *l = PyList_New(num_fields);
|
PyObject *s, *l = PyList_New(num_fields);
|
||||||
if (!l) return 0;
|
if (!l) return 0;
|
||||||
for(i = 0; i < num_fields; i++) {
|
for(i = 0; i < num_fields; i++) {
|
||||||
|
@ -424,7 +424,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
||||||
}
|
}
|
||||||
PyList_SET_ITEM(l, i, s);
|
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*))
|
static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
|
||||||
|
@ -465,9 +467,9 @@ static PyObject* ast2obj_int(bool b)
|
||||||
}
|
}
|
||||||
""", 0, reflow=False)
|
""", 0, reflow=False)
|
||||||
|
|
||||||
self.emit("static int initialized;", 0)
|
|
||||||
self.emit("static int init_types(void)",0)
|
self.emit("static int init_types(void)",0)
|
||||||
self.emit("{", 0)
|
self.emit("{", 0)
|
||||||
|
self.emit("static int initialized;", 1)
|
||||||
self.emit("if (initialized) return 1;", 1)
|
self.emit("if (initialized) return 1;", 1)
|
||||||
self.emit('AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);', 1)
|
self.emit('AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);', 1)
|
||||||
for dfn in mod.dfns:
|
for dfn in mod.dfns:
|
||||||
|
|
|
@ -381,7 +381,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
|
||||||
|
|
||||||
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
||||||
{
|
{
|
||||||
int i;
|
int i, result;
|
||||||
PyObject *s, *l = PyList_New(num_fields);
|
PyObject *s, *l = PyList_New(num_fields);
|
||||||
if (!l) return 0;
|
if (!l) return 0;
|
||||||
for(i = 0; i < num_fields; i++) {
|
for(i = 0; i < num_fields; i++) {
|
||||||
|
@ -392,7 +392,9 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
|
||||||
}
|
}
|
||||||
PyList_SET_ITEM(l, i, s);
|
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*))
|
static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
|
||||||
|
@ -432,9 +434,9 @@ static PyObject* ast2obj_int(bool b)
|
||||||
return PyInt_FromLong(b);
|
return PyInt_FromLong(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int initialized;
|
|
||||||
static int init_types(void)
|
static int init_types(void)
|
||||||
{
|
{
|
||||||
|
static int initialized;
|
||||||
if (initialized) return 1;
|
if (initialized) return 1;
|
||||||
AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
|
AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
|
||||||
mod_type = make_type("mod", AST_type, NULL, 0);
|
mod_type = make_type("mod", AST_type, NULL, 0);
|
||||||
|
@ -3052,16 +3054,16 @@ init_ast(void)
|
||||||
return;
|
return;
|
||||||
if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
|
if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
|
||||||
return;
|
return;
|
||||||
if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
|
if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
|
||||||
return;
|
0) return;
|
||||||
if (PyDict_SetItemString(d, "Print", (PyObject*)Print_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, "For", (PyObject*)For_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "While", (PyObject*)While_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, "If", (PyObject*)If_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "With", (PyObject*)With_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, "Raise", (PyObject*)Raise_type) < 0) return;
|
||||||
if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
|
if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
|
||||||
return;
|
0) return;
|
||||||
if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
|
if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
|
||||||
0) return;
|
0) return;
|
||||||
if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
|
if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
|
||||||
|
@ -3099,10 +3101,10 @@ init_ast(void)
|
||||||
if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_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, "Num", (PyObject*)Num_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
|
if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
|
||||||
if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
|
if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
|
||||||
return;
|
0) return;
|
||||||
if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
|
if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
|
||||||
return;
|
0) return;
|
||||||
if (PyDict_SetItemString(d, "Name", (PyObject*)Name_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, "List", (PyObject*)List_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
|
if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
|
||||||
|
@ -3168,8 +3170,8 @@ init_ast(void)
|
||||||
(PyObject*)comprehension_type) < 0) return;
|
(PyObject*)comprehension_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "excepthandler",
|
if (PyDict_SetItemString(d, "excepthandler",
|
||||||
(PyObject*)excepthandler_type) < 0) return;
|
(PyObject*)excepthandler_type) < 0) return;
|
||||||
if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
|
if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
|
||||||
return;
|
0) return;
|
||||||
if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
|
if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
|
||||||
return;
|
return;
|
||||||
if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
|
if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue