[Python-checkins] python/dist/src/Modules cPickle.c,2.101,2.102

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Fri, 31 Jan 2003 22:22:39 -0800


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

Modified Files:
	cPickle.c 
Log Message:
Added #defines for proto 2 opcodes; gave the Pickler a proto member;
removed woefully inadequate opcode docs and pointed to pickletools.py
instead.


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.101
retrieving revision 2.102
diff -C2 -d -r2.101 -r2.102
*** cPickle.c	1 Feb 2003 02:16:37 -0000	2.101
--- cPickle.c	1 Feb 2003 06:22:36 -0000	2.102
***************
*** 21,39 ****
  #define WRITE_BUF_SIZE 256
  
! /* --------------------------------------------------------------------------
! NOTES on format codes.
! XXX much more is needed here
! 
! Integer types
! BININT1         8-bit unsigned integer; followed by 1 byte.
! BININT2         16-bit unsigned integer; followed by 2 bytes, little-endian.
! BININT          32-bit signed integer; followed by 4 bytes, little-endian.
! INT             Integer; natural decimal string conversion, then newline.
!                 CAUTION:  INT-reading code can't assume that what follows
!                 fits in a Python int, because the size of Python ints varies
!                 across platforms.
! LONG            Long (unbounded) integer; repr(i), then newline.
! -------------------------------------------------------------------------- */
! 
  #define MARK        '('
  #define STOP        '.'
--- 21,28 ----
  #define WRITE_BUF_SIZE 256
  
! /*
!  * Pickle opcodes.  These must be kept in synch with pickle.py.  Extensive
!  * docs are in pickletools.py.
!  */
  #define MARK        '('
  #define STOP        '.'
***************
*** 77,80 ****
--- 66,89 ----
  #define EMPTY_TUPLE ')'
  #define SETITEMS    'u'
+ 
+ /* Protocol 2. */
+ #define PROTO	 '\x80' /* identify pickle protocol */
+ #define NEWOBJ   '\x81' /* build object by applying cls.__new__ to argtuple */
+ #define EXT1     '\x82' /* push object from extension registry; 1-byte index */
+ #define EXT2     '\x83' /* ditto, but 2-byte index */
+ #define EXT4     '\x84' /* ditto, but 4-byte index */
+ #define TUPLE1   '\x85' /* build 1-tuple from stack top */
+ #define TUPLE2   '\x86' /* build 2-tuple from two topmost stack items */
+ #define TUPLE3   '\x87' /* build 3-tuple from three topmost stack items */
+ #define NEWTRUE  '\x88' /* push True */
+ #define NEWFALSE '\x89' /* push False */
+ #define LONG1    '\x8a' /* push long from < 256 bytes */
+ #define LONG4    '\x8b' /* push really big long */
+ 
+ /* There aren't opcodes -- they're ways to pickle bools before protocol 2,
+  * so that unpicklers written before bools were introduced unpickle them
+  * as ints, but unpicklers after can recognize that bools were intended.
+  * Note that protocol 2 added direct ways to pickle bools.
+  */
  #undef TRUE
  #define TRUE        "I01\n"
***************
*** 82,86 ****
  #define FALSE       "I00\n"
  
- 
  static char MARKv = MARK;
  
--- 91,94 ----
***************
*** 270,274 ****
--- 278,288 ----
  	PyObject *pers_func;
  	PyObject *inst_pers_func;
+ 
+ 	/* pickle protocol number, >= 0 */
+ 	int proto;
+ 
+ 	/* bool, true if proto > 0 */
  	int bin;
+ 
  	int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
          int nesting;