Mercurial > cpython-lru_cache-weakref
diff Objects/methodobject.c @ 18512:b2bf88e06fc5 legacy-trunk
GC for method objects.
| author | Neil Schemenauer <nascheme@enme.ucalgary.ca> |
|---|---|
| date | Thu, 12 Jul 2001 13:27:35 +0000 |
| parents | 6f6f965c5e2d |
| children | 09df3254b49d |
line wrap: on
line diff
--- a/Objects/methodobject.c Thu Jul 12 13:27:25 2001 +0000 +++ b/Objects/methodobject.c Thu Jul 12 13:27:35 2001 +0000 @@ -24,6 +24,7 @@ op->m_ml = ml; Py_XINCREF(self); op->m_self = self; + PyObject_GC_Init(op); return (PyObject *)op; } @@ -62,11 +63,21 @@ 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 @@ 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 @@ while (free_list) { PyCFunctionObject *v = free_list; free_list = (PyCFunctionObject *)(v->m_self); + v = (PyCFunctionObject *) PyObject_AS_GC(v); PyObject_DEL(v); } }
