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

Skip to content

Commit 0986d82

Browse files
committed
- A type can now inherit its metatype from its base type. Previously,
when PyType_Ready() was called, if ob_type was found to be NULL, it was always set to &PyType_Type; now it is set to base->ob_type, where base is tp_base, defaulting to &PyObject_Type. - PyType_Ready() accidentally did not inherit tp_is_gc; now it does. Bugfix candidate.
1 parent d1a3c81 commit 0986d82

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ Build
123123

124124
C API
125125

126+
- A type can now inherit its metatype from its base type. Previously,
127+
when PyType_Ready() was called, if ob_type was found to be NULL, it
128+
was always set to &PyType_Type; now it is set to base->ob_type,
129+
where base is tp_base, defaulting to &PyObject_Type.
130+
131+
- PyType_Ready() accidentally did not inherit tp_is_gc; now it does.
132+
126133
- Objects allocated using the new PyMalloc_New and PyMalloc_NewVar
127134
functions will be allocated using pymalloc if it is enabled. These
128135
objects should be deallocated using PyMalloc_Del. The PyObject_{New,

Objects/typeobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,17 +2050,17 @@ PyType_Ready(PyTypeObject *type)
20502050

20512051
type->tp_flags |= Py_TPFLAGS_READYING;
20522052

2053-
/* Initialize ob_type if NULL. This means extensions that want to be
2054-
compilable separately on Windows can call PyType_Ready() instead of
2055-
initializing the ob_type field of their type objects. */
2056-
if (type->ob_type == NULL)
2057-
type->ob_type = &PyType_Type;
2058-
20592053
/* Initialize tp_base (defaults to BaseObject unless that's us) */
20602054
base = type->tp_base;
20612055
if (base == NULL && type != &PyBaseObject_Type)
20622056
base = type->tp_base = &PyBaseObject_Type;
20632057

2058+
/* Initialize ob_type if NULL. This means extensions that want to be
2059+
compilable separately on Windows can call PyType_Ready() instead of
2060+
initializing the ob_type field of their type objects. */
2061+
if (type->ob_type == NULL)
2062+
type->ob_type = base->ob_type;
2063+
20642064
/* Initialize tp_bases */
20652065
bases = type->tp_bases;
20662066
if (bases == NULL) {

0 commit comments

Comments
 (0)