summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-12-17 17:14:22 (GMT)
committerGuido van Rossum <guido@python.org>2001-12-17 17:14:22 (GMT)
commitf884b749103bad0724e2e4878cd5fe49a41bd7df (patch)
tree08198b5552876fd2f950dfa3678423763e883139 /Objects
parentfacf24bdc7b292029b3e611d241feee157cda4c4 (diff)
downloadcpython-f884b749103bad0724e2e4878cd5fe49a41bd7df.zip
cpython-f884b749103bad0724e2e4878cd5fe49a41bd7df.tar.gz
cpython-f884b749103bad0724e2e4878cd5fe49a41bd7df.tar.bz2
- PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
NULL, so that you can call PyType_Ready() to initialize a type that is to be separately compiled with C on Windows. inherit_special(): Add a long comment explaining that you have to set tp_new if your base class is PyBaseObject_Type.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ba30063..b8a33c8 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1747,6 +1747,16 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
type->tp_clear = base->tp_clear;
}
if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+ /* The condition below could use some explanation.
+ It appears that tp_new is not inherited for static types
+ whose base class is 'object'; this seems to be a precaution
+ so that old extension types don't suddenly become
+ callable (object.__new__ wouldn't insure the invariants
+ that the extension type's own factory function ensures).
+ Heap types, of course, are under our control, so they do
+ inherit tp_new; static extension types that specify some
+ other built-in type as the default are considered
+ new-style-aware so they also inherit object.__new__. */
if (base != &PyBaseObject_Type ||
(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
if (type->tp_new == NULL)
@@ -1940,6 +1950,12 @@ PyType_Ready(PyTypeObject *type)
type->tp_flags |= Py_TPFLAGS_READYING;
+ /* Initialize ob_type if NULL. This means extensions that want to be
+ compilable separately on Windows can call PyType_Ready() instead of
+ initializing the ob_type field of their type objects. */
+ if (type->ob_type == NULL)
+ type->ob_type = &PyType_Type;
+
/* Initialize tp_base (defaults to BaseObject unless that's us) */
base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type)