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

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 10 Aug 2001 10:39:51 -0700


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

Modified Files:
	typeobject.c 
Log Message:
Change PyType_Ready() to use the READY and READYING flags.  This makes
it possible to detect recursive calls early (as opposed to when the
stack overflows :-).


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.27
retrieving revision 2.28
diff -C2 -d -r2.27 -r2.28
*** typeobject.c	2001/08/09 19:43:37	2.27
--- typeobject.c	2001/08/10 17:39:49	2.28
***************
*** 1170,1175 ****
  	int i, n;
  
! 	if (type->tp_dict != NULL)
! 		return 0; /* Already initialized */
  
  	/* Initialize tp_base (defaults to BaseObject unless that's us) */
--- 1170,1181 ----
  	int i, n;
  
! 	if (type->tp_flags & Py_TPFLAGS_READY) {
! 		assert(type->tp_dict != NULL);
! 		return 0;
! 	}
! 	assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);
! 	assert(type->tp_dict == NULL);
! 
! 	type->tp_flags |= Py_TPFLAGS_READYING;
  
  	/* Initialize tp_base (defaults to BaseObject unless that's us) */
***************
*** 1186,1190 ****
  			bases = Py_BuildValue("(O)", base);
  		if (bases == NULL)
! 			return -1;
  		type->tp_bases = bases;
  	}
--- 1192,1196 ----
  			bases = Py_BuildValue("(O)", base);
  		if (bases == NULL)
! 			goto error;
  		type->tp_bases = bases;
  	}
***************
*** 1193,1197 ****
  	if (base && base->tp_dict == NULL) {
  		if (PyType_Ready(base) < 0)
! 			return -1;
  	}
  
--- 1199,1203 ----
  	if (base && base->tp_dict == NULL) {
  		if (PyType_Ready(base) < 0)
! 			goto error;
  	}
  
***************
*** 1201,1205 ****
  		dict = PyDict_New();
  		if (dict == NULL)
! 			return -1;
  		type->tp_defined = dict;
  	}
--- 1207,1211 ----
  		dict = PyDict_New();
  		if (dict == NULL)
! 			goto error;
  		type->tp_defined = dict;
  	}
***************
*** 1207,1222 ****
  	/* Add type-specific descriptors to tp_defined */
  	if (add_operators(type) < 0)
! 		return -1;
  	if (type->tp_methods != NULL) {
  		if (add_methods(type, type->tp_methods) < 0)
! 			return -1;
  	}
  	if (type->tp_members != NULL) {
  		if (add_members(type, type->tp_members) < 0)
! 			return -1;
  	}
  	if (type->tp_getset != NULL) {
  		if (add_getset(type, type->tp_getset) < 0)
! 			return -1;
  	}
  
--- 1213,1228 ----
  	/* Add type-specific descriptors to tp_defined */
  	if (add_operators(type) < 0)
! 		goto error;
  	if (type->tp_methods != NULL) {
  		if (add_methods(type, type->tp_methods) < 0)
! 			goto error;
  	}
  	if (type->tp_members != NULL) {
  		if (add_members(type, type->tp_members) < 0)
! 			goto error;
  	}
  	if (type->tp_getset != NULL) {
  		if (add_getset(type, type->tp_getset) < 0)
! 			goto error;
  	}
  
***************
*** 1229,1233 ****
  	/* Calculate method resolution order */
  	if (mro_internal(type) < 0) {
! 		return -1;
  	}
  
--- 1235,1239 ----
  	/* Calculate method resolution order */
  	if (mro_internal(type) < 0) {
! 		goto error;
  	}
  
***************
*** 1241,1245 ****
  		type->tp_dict = PyDict_New();
  		if (type->tp_dict == NULL)
! 			return -1;
  		bases = type->tp_mro;
  		assert(bases != NULL);
--- 1247,1251 ----
  		type->tp_dict = PyDict_New();
  		if (type->tp_dict == NULL)
! 			goto error;
  		bases = type->tp_mro;
  		assert(bases != NULL);
***************
*** 1251,1255 ****
  			x = base->tp_defined;
  			if (x != NULL && PyDict_Update(type->tp_dict, x) < 0)
! 				return -1;
  		}
  	}
--- 1257,1261 ----
  			x = base->tp_defined;
  			if (x != NULL && PyDict_Update(type->tp_dict, x) < 0)
! 				goto error;
  		}
  	}
***************
*** 1258,1264 ****
  	if (type->tp_base != NULL)
  		if (inherit_slots(type, type->tp_base) < 0)
! 			return -1;
  
  	return 0;
  }
  
--- 1264,1277 ----
  	if (type->tp_base != NULL)
  		if (inherit_slots(type, type->tp_base) < 0)
! 			goto error;
  
+ 	assert(type->tp_dict != NULL);
+ 	type->tp_flags =
+ 		(type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
  	return 0;
+ 
+   error:
+ 	type->tp_flags &= ~Py_TPFLAGS_READYING;
+ 	return -1;
  }