mirror of
https://github.com/python/cpython.git
synced 2025-07-15 15:25:29 +00:00
bpo-39573: Add Py_SET_TYPE() function (GH-18394)
Add Py_SET_TYPE() function to set the type of an object.
This commit is contained in:
parent
daa9756cb6
commit
d2ec81a8c9
24 changed files with 77 additions and 48 deletions
|
@ -4097,9 +4097,10 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
|
|||
}
|
||||
|
||||
if (compatible_for_assignment(oldto, newto, "__class__")) {
|
||||
if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE)
|
||||
if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
||||
Py_INCREF(newto);
|
||||
Py_TYPE(self) = newto;
|
||||
}
|
||||
Py_SET_TYPE(self, newto);
|
||||
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)
|
||||
Py_DECREF(oldto);
|
||||
return 0;
|
||||
|
@ -5334,8 +5335,9 @@ PyType_Ready(PyTypeObject *type)
|
|||
NULL when type is &PyBaseObject_Type, and we know its ob_type is
|
||||
not NULL (it's initialized to &PyType_Type). But coverity doesn't
|
||||
know that. */
|
||||
if (Py_TYPE(type) == NULL && base != NULL)
|
||||
Py_TYPE(type) = Py_TYPE(base);
|
||||
if (Py_TYPE(type) == NULL && base != NULL) {
|
||||
Py_SET_TYPE(type, Py_TYPE(base));
|
||||
}
|
||||
|
||||
/* Initialize tp_bases */
|
||||
bases = type->tp_bases;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue