[Python-checkins] CVS: python/dist/src/Python exceptions.c,1.17,1.17.2.1

Moshe Zadka moshez@users.sourceforge.net
Fri, 30 Mar 2001 13:01:11 -0800


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

Modified Files:
      Tag: release20-maint
	exceptions.c 
Log Message:
- exceptions.c  - make_class() Added a "goto finally" so that if
  populate_methods() fails, the return status will be -1 (failure)
  instead of 0 (success).

  fini_exceptions(): When decref'ing the static pointers to the
  exception classes, clear out their dictionaries too.  This breaks a
  cycle from class->dict->method->class and allows the classes with
  unbound methods to be reclaimed.  This plugs a large memory leak in a
  common Py_Initialize()/dosomething/Py_Finalize() loop.


Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -C2 -r1.17 -r1.17.2.1
*** exceptions.c	2000/08/18 19:53:25	1.17
--- exceptions.c	2001/03/30 21:01:09	1.17.2.1
***************
*** 169,172 ****
--- 169,173 ----
  	Py_DECREF(*klass);
  	*klass = NULL;
+ 	goto finally;
      }
  
***************
*** 1097,1100 ****
--- 1098,1109 ----
  
      for (i=0; exctable[i].name; i++) {
+ 	/* clear the class's dictionary, freeing up circular references
+ 	 * between the class and its methods.
+ 	 */
+ 	PyObject* cdict = PyObject_GetAttrString(*exctable[i].exc, "__dict__");
+ 	PyDict_Clear(cdict);
+ 	Py_DECREF(cdict);
+ 
+ 	/* Now decref the exception class */
  	Py_XDECREF(*exctable[i].exc);
  	*exctable[i].exc = NULL;