mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Enable GC for new-style instances. This touches lots of files, since
many types were subclassable but had a xxx_dealloc function that called PyObject_DEL(self) directly instead of deferring to self->ob_type->tp_free(self). It is permissible to set tp_free in the type object directly to _PyObject_Del, for non-GC types, or to _PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster, so I'm fearing that our pystone rating is going down again. I'm not sure if doing something like void xxx_dealloc(PyObject *self) { if (PyXxxCheckExact(self)) PyObject_DEL(self); else self->ob_type->tp_free(self); } is any faster than always calling the else branch, so I haven't attempted that -- however those types whose own dealloc is fancier (int, float, unicode) do use this pattern.
This commit is contained in:
parent
be63884d50
commit
9475a2310d
13 changed files with 90 additions and 26 deletions
|
@ -461,7 +461,7 @@ static void
|
|||
cm_dealloc(classmethod *cm)
|
||||
{
|
||||
Py_XDECREF(cm->cm_callable);
|
||||
PyObject_DEL(cm);
|
||||
cm->ob_type->tp_free((PyObject *)cm);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -531,6 +531,7 @@ PyTypeObject PyClassMethod_Type = {
|
|||
cm_init, /* tp_init */
|
||||
PyType_GenericAlloc, /* tp_alloc */
|
||||
PyType_GenericNew, /* tp_new */
|
||||
_PyObject_Del, /* tp_free */
|
||||
};
|
||||
|
||||
PyObject *
|
||||
|
@ -571,7 +572,7 @@ static void
|
|||
sm_dealloc(staticmethod *sm)
|
||||
{
|
||||
Py_XDECREF(sm->sm_callable);
|
||||
PyObject_DEL(sm);
|
||||
sm->ob_type->tp_free((PyObject *)sm);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -641,6 +642,7 @@ PyTypeObject PyStaticMethod_Type = {
|
|||
sm_init, /* tp_init */
|
||||
PyType_GenericAlloc, /* tp_alloc */
|
||||
PyType_GenericNew, /* tp_new */
|
||||
_PyObject_Del, /* tp_free */
|
||||
};
|
||||
|
||||
PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue