[Python-checkins] cpython: add gc support to the AST base type (closes #15293)
benjamin.peterson
python-checkins at python.org
Sun Jul 8 20:03:54 CEST 2012
http://hg.python.org/cpython/rev/85cccc38d01c
changeset: 78006:85cccc38d01c
user: Benjamin Peterson <benjamin at python.org>
date: Sun Jul 08 11:03:46 2012 -0700
summary:
add gc support to the AST base type (closes #15293)
files:
Parser/asdl_c.py | 21 +++++++++++++++++----
Python/Python-ast.c | 21 +++++++++++++++++----
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -616,6 +616,19 @@
}
static int
+ast_traverse(AST_object *self, visitproc visit, void *arg)
+{
+ Py_VISIT(self->dict);
+ return 0;
+}
+
+static void
+ast_clear(AST_object *self)
+{
+ Py_CLEAR(self->dict);
+}
+
+static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
_Py_IDENTIFIER(_fields);
@@ -718,10 +731,10 @@
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
+ (traverseproc)ast_traverse, /* tp_traverse */
+ (inquiry)ast_clear, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
@@ -737,7 +750,7 @@
(initproc)ast_type_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
- PyObject_Del, /* tp_free */
+ PyObject_GC_Del, /* tp_free */
};
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -468,6 +468,19 @@
}
static int
+ast_traverse(AST_object *self, visitproc visit, void *arg)
+{
+ Py_VISIT(self->dict);
+ return 0;
+}
+
+static void
+ast_clear(AST_object *self)
+{
+ Py_CLEAR(self->dict);
+}
+
+static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
_Py_IDENTIFIER(_fields);
@@ -570,10 +583,10 @@
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
+ (traverseproc)ast_traverse, /* tp_traverse */
+ (inquiry)ast_clear, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
@@ -589,7 +602,7 @@
(initproc)ast_type_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
- PyObject_Del, /* tp_free */
+ PyObject_GC_Del, /* tp_free */
};
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list