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

Guido van Rossum gvanrossum@users.sourceforge.net
Sat, 12 May 2001 13:58:26 -0700


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

Modified Files:
      Tag: descr-branch
	typeobject.c 
Log Message:
Avoid endless recursion in subtype_construct() and subtype_dealloc()
when a dynamic type is subtyped.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.16.8.20
retrieving revision 2.16.8.21
diff -C2 -r2.16.8.20 -r2.16.8.21
*** typeobject.c	2001/05/12 20:41:30	2.16.8.20
--- typeobject.c	2001/05/12 20:58:24	2.16.8.21
***************
*** 96,99 ****
--- 96,101 ----
  {
  	PyObject *res;
+ 	PyTypeObject *base;
+ 	ternaryfunc f;
  
  	if (self == NULL) {
***************
*** 102,106 ****
  		return NULL;
  	}
! 	res = self->ob_type->tp_base->tp_construct(self, args, kwds);
  	if (res == self)
  		Py_INCREF(self->ob_type);
--- 104,111 ----
  		return NULL;
  	}
! 	base = self->ob_type->tp_base;
! 	while ((f = base->tp_construct) == subtype_construct)
! 		base = base->tp_base;
! 	res = f(self, args, kwds);
  	if (res == self)
  		Py_INCREF(self->ob_type);
***************
*** 112,116 ****
  {
  	int dictoffset = self->ob_type->tp_dictoffset;
! 	if (dictoffset && !self->ob_type->tp_base->tp_dictoffset) {
  		PyObject **dictptr = (PyObject **) ((char *)self + dictoffset);
  		PyObject *dict = *dictptr;
--- 117,127 ----
  {
  	int dictoffset = self->ob_type->tp_dictoffset;
! 	PyTypeObject *base;
! 	destructor f;
! 
! 	base = self->ob_type->tp_base;
! 	while ((f = base->tp_dealloc) == subtype_dealloc)
! 		base = base->tp_base;
! 	if (dictoffset && !base->tp_dictoffset) {
  		PyObject **dictptr = (PyObject **) ((char *)self + dictoffset);
  		PyObject *dict = *dictptr;
***************
*** 120,124 ****
  		}
  	}
! 	self->ob_type->tp_base->tp_dealloc(self);
  	Py_DECREF(self->ob_type);
  }
--- 131,135 ----
  		}
  	}
! 	base->tp_dealloc(self);
  	Py_DECREF(self->ob_type);
  }