@@ -615,6 +615,19 @@ def visitModule(self, mod):
615615 Py_TYPE(self)->tp_free(self);
616616}
617617
618+ static int
619+ ast_traverse(AST_object *self, visitproc visit, void *arg)
620+ {
621+ Py_VISIT(self->dict);
622+ return 0;
623+ }
624+
625+ static void
626+ ast_clear(AST_object *self)
627+ {
628+ Py_CLEAR(self->dict);
629+ }
630+
618631static int
619632ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
620633{
@@ -718,10 +731,10 @@ def visitModule(self, mod):
718731 PyObject_GenericGetAttr, /* tp_getattro */
719732 PyObject_GenericSetAttr, /* tp_setattro */
720733 0, /* tp_as_buffer */
721- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
734+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC , /* tp_flags */
722735 0, /* tp_doc */
723- 0, /* tp_traverse */
724- 0, /* tp_clear */
736+ (traverseproc)ast_traverse, /* tp_traverse */
737+ (inquiry)ast_clear, /* tp_clear */
725738 0, /* tp_richcompare */
726739 0, /* tp_weaklistoffset */
727740 0, /* tp_iter */
@@ -737,7 +750,7 @@ def visitModule(self, mod):
737750 (initproc)ast_type_init, /* tp_init */
738751 PyType_GenericAlloc, /* tp_alloc */
739752 PyType_GenericNew, /* tp_new */
740- PyObject_Del, /* tp_free */
753+ PyObject_GC_Del, /* tp_free */
741754};
742755
743756
0 commit comments