[Python-checkins] CVS: python/dist/src/Modules cPickle.c,2.56,2.57

Tim Peters tim_one@users.sourceforge.net
Mon, 09 Apr 2001 18:54:45 -0700


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

Modified Files:
	cPickle.c 
Log Message:
Critical fix:  if cPickle on a sizeof(long)==8 box is used to read a
binary pickle, and the latter contains a pickle of a negative Python
int i written on a sizeof(long)==4 box (and whether by cPickle or
pickle.py), it's read incorrectly as i + 2**32.  The patch repairs that,
and allows test_cpickle.py (to which I added a relevant test case earlier
today) to work again on sizeof(long)==8 boxes.
There's another (at least one) sizeof(long)==8 binary pickle bug, but in
pickle.py instead.  That bug is still there, and test_pickle.py doesn't
catch it yet (try pickling and unpickling, e.g., 1 << 46).


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.56
retrieving revision 2.57
diff -C2 -r2.56 -r2.57
*** cPickle.c	2001/03/22 17:52:17	2.56
--- cPickle.c	2001/04/10 01:54:42	2.57
***************
*** 2529,2533 ****
          l |= (long)c << (i * 8);
      }
! 
      return l;
  }
--- 2529,2540 ----
          l |= (long)c << (i * 8);
      }
! #if SIZEOF_LONG > 4
!     /* Unlike BININT1 and BININT2, BININT (more accurately BININT4)
!      * is signed, so on a box with longs bigger than 4 bytes we need
!      * to extend a BININT's sign bit to the full width.
!      */
!     if (x == 4 && l & (1L << 31))
!         l |= (~0L) << 32;
! #endif
      return l;
  }