[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.125,2.126

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 17 Dec 2001 09:14:24 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv6729

Modified Files:
	typeobject.c 
Log Message:
- 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.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.125
retrieving revision 2.126
diff -C2 -d -r2.125 -r2.126
*** typeobject.c	2001/12/14 04:19:22	2.125
--- typeobject.c	2001/12/17 17:14:22	2.126
***************
*** 1748,1751 ****
--- 1748,1761 ----
  	}
  	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)) {
***************
*** 1940,1943 ****
--- 1950,1959 ----
  
  	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) */