Commit 10c66927 authored by Neil Schemenauer's avatar Neil Schemenauer

GC for method objects.

parent 7eac9b72
...@@ -24,6 +24,7 @@ PyCFunction_New(PyMethodDef *ml, PyObject *self) ...@@ -24,6 +24,7 @@ PyCFunction_New(PyMethodDef *ml, PyObject *self)
op->m_ml = ml; op->m_ml = ml;
Py_XINCREF(self); Py_XINCREF(self);
op->m_self = self; op->m_self = self;
PyObject_GC_Init(op);
return (PyObject *)op; return (PyObject *)op;
} }
...@@ -62,11 +63,21 @@ PyCFunction_GetFlags(PyObject *op) ...@@ -62,11 +63,21 @@ PyCFunction_GetFlags(PyObject *op)
static void static void
meth_dealloc(PyCFunctionObject *m) meth_dealloc(PyCFunctionObject *m)
{ {
PyObject_GC_Fini(m);
Py_XDECREF(m->m_self); Py_XDECREF(m->m_self);
m->m_self = (PyObject *)free_list; m->m_self = (PyObject *)free_list;
free_list = m; 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 * static PyObject *
meth_getattr(PyCFunctionObject *m, char *name) meth_getattr(PyCFunctionObject *m, char *name)
{ {
...@@ -152,18 +163,26 @@ PyTypeObject PyCFunction_Type = { ...@@ -152,18 +163,26 @@ PyTypeObject PyCFunction_Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, 0,
"builtin_function_or_method", "builtin_function_or_method",
sizeof(PyCFunctionObject), sizeof(PyCFunctionObject) + PyGC_HEAD_SIZE,
0, 0,
(destructor)meth_dealloc, /*tp_dealloc*/ (destructor)meth_dealloc, /* tp_dealloc */
0, /*tp_print*/ 0, /* tp_print */
(getattrfunc)meth_getattr, /*tp_getattr*/ (getattrfunc)meth_getattr, /* tp_getattr */
0, /*tp_setattr*/ 0, /* tp_setattr */
(cmpfunc)meth_compare, /*tp_compare*/ (cmpfunc)meth_compare, /* tp_compare */
(reprfunc)meth_repr, /*tp_repr*/ (reprfunc)meth_repr, /* tp_repr */
0, /*tp_as_number*/ 0, /* tp_as_number */
0, /*tp_as_sequence*/ 0, /* tp_as_sequence */
0, /*tp_as_mapping*/ 0, /* tp_as_mapping */
(hashfunc)meth_hash, /*tp_hash*/ (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 */ /* List all methods in a chain -- helper for findmethodinchain */
...@@ -245,6 +264,7 @@ PyCFunction_Fini(void) ...@@ -245,6 +264,7 @@ PyCFunction_Fini(void)
while (free_list) { while (free_list) {
PyCFunctionObject *v = free_list; PyCFunctionObject *v = free_list;
free_list = (PyCFunctionObject *)(v->m_self); free_list = (PyCFunctionObject *)(v->m_self);
v = (PyCFunctionObject *) PyObject_AS_GC(v);
PyObject_DEL(v); PyObject_DEL(v);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment