]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport gvanrossum's patch:
authorAnthony Baxter <anthonybaxter@gmail.com>
Fri, 26 Apr 2002 06:31:22 +0000 (06:31 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Fri, 26 Apr 2002 06:31:22 +0000 (06:31 +0000)
Make sure that tp_free frees the int the same way as tp_dealloc would.
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.

(trivial change in backport: "freefunc" -> "destructor")

Original patch(es):
python/dist/src/Objects/intobject.c:2.82

Objects/intobject.c

index 6c8bdbeb2abf030595ff6c60846407f698353f88..8d4aa2cbb0231a352943e044530d2393910e40b1 100644 (file)
@@ -142,6 +142,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)
 {
@@ -917,6 +924,7 @@ PyTypeObject PyInt_Type = {
        0,                                      /* tp_init */
        0,                                      /* tp_alloc */
        int_new,                                /* tp_new */
+       (destructor)int_free,                   /* tp_free */
 };
 
 void