]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GC for method objects.
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Thu, 12 Jul 2001 13:27:35 +0000 (13:27 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Thu, 12 Jul 2001 13:27:35 +0000 (13:27 +0000)
Objects/methodobject.c

index f0bbeeacc990f1c47e8c73e7fb9530a2c4b62f8e..bff79ed042df4076b90eac10855039f4b19ad005 100644 (file)
@@ -24,6 +24,7 @@ PyCFunction_New(PyMethodDef *ml, PyObject *self)
        op->m_ml = ml;
        Py_XINCREF(self);
        op->m_self = self;
+       PyObject_GC_Init(op);
        return (PyObject *)op;
 }
 
@@ -62,11 +63,21 @@ PyCFunction_GetFlags(PyObject *op)
 static void
 meth_dealloc(PyCFunctionObject *m)
 {
+       PyObject_GC_Fini(m);
        Py_XDECREF(m->m_self);
        m->m_self = (PyObject *)free_list;
        free_list = m;
 }
 
+static int
+meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg)
+{
+       if (m->m_self != NULL)
+               return visit(m->m_self, arg);
+       else
+               return 0;
+}
+
 static PyObject *
 meth_getattr(PyCFunctionObject *m, char *name)
 {
@@ -152,18 +163,26 @@ PyTypeObject PyCFunction_Type = {
        PyObject_HEAD_INIT(&PyType_Type)
        0,
        "builtin_function_or_method",
-       sizeof(PyCFunctionObject),
+       sizeof(PyCFunctionObject) + PyGC_HEAD_SIZE,
        0,
-       (destructor)meth_dealloc, /*tp_dealloc*/
-       0,              /*tp_print*/
-       (getattrfunc)meth_getattr, /*tp_getattr*/
-       0,              /*tp_setattr*/
-       (cmpfunc)meth_compare, /*tp_compare*/
-       (reprfunc)meth_repr, /*tp_repr*/
-       0,              /*tp_as_number*/
-       0,              /*tp_as_sequence*/
-       0,              /*tp_as_mapping*/
-       (hashfunc)meth_hash, /*tp_hash*/
+       (destructor)meth_dealloc,               /* tp_dealloc */
+       0,                                      /* tp_print */
+       (getattrfunc)meth_getattr,              /* tp_getattr */
+       0,                                      /* tp_setattr */
+       (cmpfunc)meth_compare,                  /* tp_compare */
+       (reprfunc)meth_repr,                    /* tp_repr */
+       0,                                      /* tp_as_number */
+       0,                                      /* tp_as_sequence */
+       0,                                      /* tp_as_mapping */
+       (hashfunc)meth_hash,                    /* tp_hash */
+       0,                                      /* tp_call */
+       0,                                      /* tp_str */
+       0,                                      /* tp_getattro */
+       0,                                      /* tp_setattro */
+       0,                                      /* tp_as_buffer */
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC,     /* tp_flags */
+       0,                                      /* tp_doc */
+       (traverseproc)meth_traverse,            /* tp_traverse */
 };
 
 /* List all methods in a chain -- helper for findmethodinchain */
@@ -245,6 +264,7 @@ PyCFunction_Fini(void)
        while (free_list) {
                PyCFunctionObject *v = free_list;
                free_list = (PyCFunctionObject *)(v->m_self);
+               v = (PyCFunctionObject *) PyObject_AS_GC(v);
                PyObject_DEL(v);
        }
 }