[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.97,2.98

Tim Peters tim_one@users.sourceforge.net
Fri, 01 Jun 2001 22:42:31 -0700


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

Modified Files:
	dictobject.c 
Log Message:
dict_popitem():  Repaired last-second 2.1 comment, which misidentified the
true reason for allocating the tuple before checking the dict size.


Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.97
retrieving revision 2.98
diff -C2 -r2.97 -r2.98
*** dictobject.c	2001/06/02 05:27:19	2.97
--- dictobject.c	2001/06/02 05:42:29	2.98
***************
*** 1363,1371 ****
  	if (!PyArg_NoArgs(args))
  		return NULL;
! 	/* Allocate the result tuple first.  Believe it or not,
! 	 * this allocation could trigger a garbage collection which
! 	 * could resize the dict, which would invalidate the pointer
! 	 * (ep) into the dict calculated below.
! 	 * So we have to do this first.
  	 */
  	res = PyTuple_New(2);
--- 1363,1374 ----
  	if (!PyArg_NoArgs(args))
  		return NULL;
! 	/* Allocate the result tuple before checking the size.  Believe it
! 	 * or not, this allocation could trigger a garbage collection which
! 	 * could empty the dict, so if we checked the size first and that
! 	 * happened, the result would be an infinite loop (searching for an
! 	 * entry that no longer exists).  Note that the usual popitem()
! 	 * idiom is "while d: k, v = d.popitem()". so needing to throw the
! 	 * tuple away  if the dict *is* empty isn't a significant
! 	 * inefficiency -- possible, but unlikely in practice.
  	 */
  	res = PyTuple_New(2);