Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ee4b94

Browse files
committed
Add a safeguard against setting the class to something with a
different free or alloc slot.
1 parent 4b46c0a commit 9ee4b94

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Objects/typeobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,16 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
16221622
return -1;
16231623
}
16241624
new = (PyTypeObject *)value;
1625+
if (new->tp_dealloc != old->tp_dealloc ||
1626+
new->tp_free != old->tp_free)
1627+
{
1628+
PyErr_Format(PyExc_TypeError,
1629+
"__class__ assignment: "
1630+
"'%s' deallocator differs from '%s'",
1631+
new->tp_name,
1632+
old->tp_name);
1633+
return -1;
1634+
}
16251635
newbase = new;
16261636
oldbase = old;
16271637
while (equiv_structs(newbase, newbase->tp_base))

0 commit comments

Comments
 (0)