[Python-checkins] python/dist/src/Lib pickle.py,1.126,1.127

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 29 Jan 2003 22:37:44 -0800


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

Modified Files:
	pickle.py 
Log Message:
There was a subtle big in save_newobj(): it used self.save_global(t)
on the type instead of self.save(t).  This defeated the purpose of
NEWOBJ, because it didn't generate a BINGET opcode when t was already
memoized; but moreover, it would generate multiple BINPUT opcodes for
the same type!  pickletools.dis() doesn't like this.

How I found this?  I was playing with picklesize.py in the datetime
sandbox, and noticed that protocol 2 pickles for multiple objects were
in fact larger than protocol 1 pickles!  That was suspicious, so I
decided to disassemble one of the pickles.

This really needs a unit test, but I'm exhausted.  I'll be late for
work as it is. :-(


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.126
retrieving revision 1.127
diff -C2 -d -r1.126 -r1.127
*** pickle.py	30 Jan 2003 05:41:19 -0000	1.126
--- pickle.py	30 Jan 2003 06:37:41 -0000	1.127
***************
*** 234,237 ****
--- 234,238 ----
          if self.fast:
              return
+         assert id(obj) not in self.memo
          memo_len = len(self.memo)
          self.write(self.put(memo_len))
***************
*** 387,391 ****
          write = self.write
  
!         self.save_global(t)
          save(args)
          write(NEWOBJ)
--- 388,392 ----
          write = self.write
  
!         self.save(t)
          save(args)
          write(NEWOBJ)