[Python-checkins] python/dist/src/Lib pickle.py,1.94,1.95

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Mon, 27 Jan 2003 18:09:58 -0800


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

Modified Files:
	pickle.py 
Log Message:
save_tuple():  Minor rewriting, and added a comment about the subtlety
created by recursive tuples.


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.94
retrieving revision 1.95
diff -C2 -d -r1.94 -r1.95
*** pickle.py	28 Jan 2003 01:44:45 -0000	1.94
--- pickle.py	28 Jan 2003 02:09:55 -0000	1.95
***************
*** 455,473 ****
          memo  = self.memo
  
-         d = id(object)
- 
          write(MARK)
- 
          for element in object:
              save(element)
  
!         if len(object) and d in memo:
              if self.bin:
!                 write(POP_MARK + self.get(memo[d][0]))
!                 return
! 
!             write(POP * (len(object) + 1) + self.get(memo[d][0]))
              return
  
          self.write(TUPLE)
          self.memoize(object)
--- 455,478 ----
          memo  = self.memo
  
          write(MARK)
          for element in object:
              save(element)
  
!         if object and id(object) in memo:
!             # Subtle.  d was not in memo when we entered save_tuple(), so
!             # the process of saving the tuple's elements must have saved
!             # the tuple itself:  the tuple is recursive.  The proper action
!             # now is to throw away everything we put on the stack, and
!             # simply GET the tuple (it's already constructed).  This check
!             # could have been done in the "for element" loop instead, but
!             # recursive tuples are a rare thing.
!             get = self.get(memo[id(object)][0])
              if self.bin:
!                 write(POP_MARK + get)
!             else:   # proto 0 -- POP_MARK not available
!                 write(POP * (len(object) + 1) + get)
              return
  
+         # No recursion (including the empty-tuple case).
          self.write(TUPLE)
          self.memoize(object)