]> granicus.if.org Git - python/commitdiff
add gc support to the AST base type (closes #15293)
authorBenjamin Peterson <benjamin@python.org>
Sun, 8 Jul 2012 18:03:46 +0000 (11:03 -0700)
committerBenjamin Peterson <benjamin@python.org>
Sun, 8 Jul 2012 18:03:46 +0000 (11:03 -0700)
Parser/asdl_c.py
Python/Python-ast.c

index e4165b09ad1dfb92634353e5b95ddc0606bfb628..698afacf890985c013ff79fee4441232bb377676 100755 (executable)
@@ -615,6 +615,19 @@ ast_dealloc(AST_object *self)
     Py_TYPE(self)->tp_free(self);
 }
 
+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)
 {
@@ -718,10 +731,10 @@ static PyTypeObject AST_type = {
     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 @@ static PyTypeObject AST_type = {
     (initproc)ast_type_init, /* tp_init */
     PyType_GenericAlloc,     /* tp_alloc */
     PyType_GenericNew,       /* tp_new */
-    PyObject_Del,            /* tp_free */
+    PyObject_GC_Del,         /* tp_free */
 };
 
 
index 60147fa15b4a592567e3703f0bafd6d9fbabc355..805f2b8af118d93f44e1f1cabd3bdec0960a1413 100644 (file)
@@ -467,6 +467,19 @@ ast_dealloc(AST_object *self)
     Py_TYPE(self)->tp_free(self);
 }
 
+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)
 {
@@ -570,10 +583,10 @@ static PyTypeObject AST_type = {
     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 @@ static PyTypeObject AST_type = {
     (initproc)ast_type_init, /* tp_init */
     PyType_GenericAlloc,     /* tp_alloc */
     PyType_GenericNew,       /* tp_new */
-    PyObject_Del,            /* tp_free */
+    PyObject_GC_Del,         /* tp_free */
 };