[Python-checkins] python/dist/src/Modules gcmodule.c,2.33.6.6,2.33.6.7

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 08 Apr 2003 12:13:20 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv10581/Modules

Modified Files:
      Tag: release22-maint
	gcmodule.c 
Log Message:
More backporting of gc-vs-__del__ fixes.  It should be fixed for instances
of classic classes now.  Alas, new-style classes are still a problem, and
didn't need to be fixed in 2.3 (they were already immune in 2.3 due to the
new-in-2.3 tp_del slot).


Index: gcmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v
retrieving revision 2.33.6.6
retrieving revision 2.33.6.7
diff -C2 -d -r2.33.6.6 -r2.33.6.7
*** gcmodule.c	3 Apr 2003 23:02:29 -0000	2.33.6.6
--- gcmodule.c	8 Apr 2003 19:13:14 -0000	2.33.6.7
***************
*** 254,258 ****
  }
  
! /* return true if object has a finalization method */
  static int
  has_finalizer(PyObject *op)
--- 254,265 ----
  }
  
! /* Return true if object has a finalization method.
!  * CAUTION:  class instances have to be checked for a __del__ method, and
!  * earlier versions of this used to call PyObject_HasAttr, which in turn
!  * could call the class's __getattr__ hook (if any).  That could invoke
!  * arbitrary Python code, mutating the object graph in arbitrary ways, and
!  * that was the source of some excruciatingly subtle bugs.
!  * XXX This is still broken for new-style classes.
!  */
  static int
  has_finalizer(PyObject *op)
***************
*** 264,270 ****
  			Py_FatalError("PyGC: can't initialize __del__ string");
  	}
! 	return (PyInstance_Check(op) ||
! 	        PyType_HasFeature(op->ob_type, Py_TPFLAGS_HEAPTYPE))
! 	       && PyObject_HasAttr(op, delstr);
  }
  
--- 271,282 ----
  			Py_FatalError("PyGC: can't initialize __del__ string");
  	}
! 
! 	if (PyInstance_Check(op))
! 		return _PyInstance_Lookup(op, delstr) != NULL;
! 	else if (PyType_HasFeature(op->ob_type, Py_TPFLAGS_HEAPTYPE))
! 		/* XXX This path is still Evil. */
! 		return PyObject_HasAttr(op, delstr);
! 	else
! 		return 0;
  }
  
***************
*** 277,281 ****
  	for (; gc != unreachable; gc=next) {
  		PyObject *op = FROM_GC(gc);
! 		/* has_finalizer() may result in arbitrary Python
  		   code being run. */
  		if (has_finalizer(op)) {
--- 289,293 ----
  	for (; gc != unreachable; gc=next) {
  		PyObject *op = FROM_GC(gc);
! 		/* XXX has_finalizer() may result in arbitrary Python
  		   code being run. */
  		if (has_finalizer(op)) {