[Python-checkins] python/dist/src/Modules gcmodule.c,2.59,2.60

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 05 Apr 2003 09:15:47 -0800


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

Modified Files:
	gcmodule.c 
Log Message:
Fixed new seemingly random segfaults, by moving the initialization of
delstr from initgc() into collect().  initgc() isn't called unless the
user explicitly imports gc, so can be used only for initialization of
user-visible module features; delstr needs to be initialized for proper
internal operation, whether or not gc is explicitly imported.

Bugfix candidate?  I don't know whether the new bug was backported to
2.2 already.


Index: gcmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v
retrieving revision 2.59
retrieving revision 2.60
diff -C2 -d -r2.59 -r2.60
*** gcmodule.c	4 Apr 2003 19:59:06 -0000	2.59
--- gcmodule.c	5 Apr 2003 17:15:44 -0000	2.60
***************
*** 60,65 ****
  static PyObject *gc_str;
  
! /* Python string used to looked for __del__ attribute. */
! static PyObject *delstr;
  
  /* set for debugging information */
--- 60,65 ----
  static PyObject *gc_str;
  
! /* Python string used to look for __del__ attribute. */
! static PyObject *delstr = NULL;
  
  /* set for debugging information */
***************
*** 370,374 ****
  			finalizer = PyObject_HasAttr(op, delstr);
  			if (op->ob_refcnt == 1) {
! 				/* The object will be deallocated. 
  				   Nothing left to do.
  				 */
--- 370,374 ----
  			finalizer = PyObject_HasAttr(op, delstr);
  			if (op->ob_refcnt == 1) {
! 				/* The object will be deallocated.
  				   Nothing left to do.
  				 */
***************
*** 526,529 ****
--- 526,535 ----
  	PyGC_Head *gc;
  
+ 	if (delstr == NULL) {
+ 		delstr = PyString_InternFromString("__del__");
+ 		if (delstr == NULL)
+ 			Py_FatalError("gc couldn't allocate \"__del__\"");
+ 	}
+ 
  	if (debug & DEBUG_STATS) {
  		PySys_WriteStderr("gc: collecting generation %d...\n",
***************
*** 579,583 ****
  	 * care not to create such things.  For Python, finalizers means
  	 * instance objects with __del__ methods.
! 	 * 
  	 * Move each object into the collectable set or the finalizers set.
  	 * It's possible that a classic class with a getattr() hook will
--- 585,589 ----
  	 * care not to create such things.  For Python, finalizers means
  	 * instance objects with __del__ methods.
! 	 *
  	 * Move each object into the collectable set or the finalizers set.
  	 * It's possible that a classic class with a getattr() hook will
***************
*** 878,882 ****
  	PyObject *result = PyList_New(0);
  	for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
! 		PyObject *obj = PyTuple_GET_ITEM(args, i); 
  		traverseproc traverse = obj->ob_type->tp_traverse;
  		if (!traverse)
--- 884,888 ----
  	PyObject *result = PyList_New(0);
  	for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
! 		PyObject *obj = PyTuple_GET_ITEM(args, i);
  		traverseproc traverse = obj->ob_type->tp_traverse;
  		if (!traverse)
***************
*** 970,976 ****
  	PyObject *d;
  
- 	delstr = PyString_InternFromString("__del__");
- 	if (!delstr)
- 		return;
  	m = Py_InitModule4("gc",
  			      GcMethods,
--- 976,979 ----