Commit 626d664f authored by Guido van Rossum's avatar Guido van Rossum

Add a safeguard against setting the class to something with a

different free or alloc slot.
parent 88772cb0
...@@ -1622,6 +1622,16 @@ object_set_class(PyObject *self, PyObject *value, void *closure) ...@@ -1622,6 +1622,16 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
return -1; return -1;
} }
new = (PyTypeObject *)value; new = (PyTypeObject *)value;
if (new->tp_dealloc != old->tp_dealloc ||
new->tp_free != old->tp_free)
{
PyErr_Format(PyExc_TypeError,
"__class__ assignment: "
"'%s' deallocator differs from '%s'",
new->tp_name,
old->tp_name);
return -1;
}
newbase = new; newbase = new;
oldbase = old; oldbase = old;
while (equiv_structs(newbase, newbase->tp_base)) while (equiv_structs(newbase, newbase->tp_base))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment