PyObject *im_class; /* The class that defined the method */
} PyMethodObject;
+
+static PyMethodObject *free_list;
+
PyObject *
PyMethod_New(func, self, class)
PyObject *func;
PyErr_BadInternalCall();
return NULL;
}
- im = PyObject_NEW(PyMethodObject, &PyMethod_Type);
- if (im == NULL)
- return NULL;
+ im = free_list;
+ if (im != NULL) {
+ free_list = (PyMethodObject *)(im->im_self);
+ im->ob_type = &PyMethod_Type;
+ _Py_NewReference(im);
+ }
+ else {
+ im = PyObject_NEW(PyMethodObject, &PyMethod_Type);
+ if (im == NULL)
+ return NULL;
+ }
Py_INCREF(func);
im->im_func = func;
Py_XINCREF(self);
Py_DECREF(im->im_func);
Py_XDECREF(im->im_self);
Py_DECREF(im->im_class);
- free((ANY *)im);
+ im->im_self = (PyObject *)free_list;
+ free_list = im;
}
static int
(getattrofunc)instancemethod_getattr, /*tp_getattro*/
0, /*tp_setattro*/
};
+
+/* Clear out the free list */
+
+void
+PyMethod_Fini()
+{
+ while (free_list) {
+ PyMethodObject *v = free_list;
+ free_list = (PyMethodObject *)(v->im_self);
+ PyMem_DEL(v);
+ }
+}