]> granicus.if.org Git - python/commitdiff
Make sure that tp_free frees the int the same way as tp_dealloc would.
authorGuido van Rossum <guido@python.org>
Fri, 26 Apr 2002 00:53:34 +0000 (00:53 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 26 Apr 2002 00:53:34 +0000 (00:53 +0000)
This fixes the problem that Barry reported on python-dev:
   >>> 23000 .__class__ = bool
crashes in the deallocator.  This was because int inherited tp_free
from object, which uses the default allocator.

2.2. Bugfix candidate.

Objects/intobject.c

index 58862092406086b1466f209f0003aeaac8302a26..58a6beb46ee5820c82b4cc1dca6ca8f59e0eb4f3 100644 (file)
@@ -130,6 +130,13 @@ int_dealloc(PyIntObject *v)
                v->ob_type->tp_free((PyObject *)v);
 }
 
+static void
+int_free(PyIntObject *v)
+{
+       v->ob_type = (struct _typeobject *)free_list;
+       free_list = v;
+}
+
 long
 PyInt_AsLong(register PyObject *op)
 {
@@ -905,6 +912,7 @@ PyTypeObject PyInt_Type = {
        0,                                      /* tp_init */
        0,                                      /* tp_alloc */
        int_new,                                /* tp_new */
+       (freefunc)int_free,                     /* tp_free */
 };
 
 void