[Python-checkins] python/dist/src/Python bltinmodule.c,2.282,2.283

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sun, 23 Mar 2003 09:52:30 -0800


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

Modified Files:
	bltinmodule.c 
Log Message:
Improved new Py_TRACE_REFS gimmicks.
Arranged that all the objects exposed by __builtin__ appear in the list
of all objects.  I basically peed away two days tracking down a mystery
leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because
the object leaking the references didn't appear in the sys.getobjects(0)
list.  The object happened to be False.  Now False is in the list, along
with other popular & previously missing leak candidates (like None).
Alas, we still don't have a choke point covering *all* Python objects,
so the list of all objects may still be incomplete.


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.282
retrieving revision 2.283
diff -C2 -d -r2.282 -r2.283
*** bltinmodule.c	23 Feb 2003 21:45:43 -0000	2.282
--- bltinmodule.c	23 Mar 2003 17:52:28 -0000	2.283
***************
*** 1819,1825 ****
  	dict = PyModule_GetDict(mod);
  
  #define SETBUILTIN(NAME, OBJECT) \
! 	if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \
! 		return NULL
  
  	SETBUILTIN("None",		Py_None);
--- 1819,1838 ----
  	dict = PyModule_GetDict(mod);
  
+ #ifdef Py_TRACE_REFS
+ 	/* __builtin__ exposes a number of statically allocated objects
+ 	 * that, before this code was added in 2.3, never showed up in
+ 	 * the list of "all objects" maintained by Py_TRACE_REFS.  As a
+ 	 * result, programs leaking references to None and False (etc)
+ 	 * couldn't be diagnosed by examining sys.getobjects(0).
+ 	 */
+ #define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0)
+ #else
+ #define ADD_TO_ALL(OBJECT) (void)0
+ #endif
+ 
  #define SETBUILTIN(NAME, OBJECT) \
! 	if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0)	\
! 		return NULL;						\
! 	ADD_TO_ALL(OBJECT)
  
  	SETBUILTIN("None",		Py_None);
***************
*** 1865,1868 ****
--- 1878,1882 ----
  
  	return mod;
+ #undef ADD_TO_ALL
  #undef SETBUILTIN
  }