[Python-checkins] CVS: python/dist/src/Modules cPickle.c,2.80,2.81
Guido van Rossum
gvanrossum@users.sourceforge.net
Fri, 05 Apr 2002 11:30:10 -0800
- Previous message: [Python-checkins] CVS: python/dist/src/Lib/test test_bool.py,1.1,1.2
- Next message: [Python-checkins] CVS: python/nondist/peps pep-0001.txt,1.30,1.31 pep-0200.txt,1.48,1.49 pep-0269.txt,1.1,1.2 pep-0276.txt,1.3,1.4 pep-0279.txt,1.9,1.10 pep-0288.txt,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv8192/Modules
Modified Files:
cPickle.c
Log Message:
Implement an idea by Paul Rubin:
Change pickling format for bools to use a backwards compatible
encoding. This means you can pickle True or False on Python 2.3
and Python 2.2 or before will read it back as 1 or 0. The code
used for pickling bools before would create pickles that could
not be read in previous Python versions.
Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.80
retrieving revision 2.81
diff -C2 -d -r2.80 -r2.81
*** cPickle.c 4 Apr 2002 17:52:50 -0000 2.80
--- cPickle.c 5 Apr 2002 19:30:08 -0000 2.81
***************
*** 78,83 ****
#define EMPTY_TUPLE ')'
#define SETITEMS 'u'
! #define TRUE 'Z'
! #define FALSE 'z'
--- 78,83 ----
#define EMPTY_TUPLE ')'
#define SETITEMS 'u'
! #define TRUE "I01\n"
! #define FALSE "I00\n"
***************
*** 937,944 ****
save_bool(Picklerobject *self, PyObject *args)
{
! static char buf[2] = {FALSE, TRUE};
long l = PyInt_AS_LONG((PyIntObject *)args);
! if ((*self->write_func)(self, buf + l, 1) < 0)
return -1;
--- 937,945 ----
save_bool(Picklerobject *self, PyObject *args)
{
! static char *buf[2] = {FALSE, TRUE};
! static char len[2] = {sizeof(FALSE)-1, sizeof(TRUE)-1};
long l = PyInt_AS_LONG((PyIntObject *)args);
! if ((*self->write_func)(self, buf[l], len[l]) < 0)
return -1;
***************
*** 2656,2660 ****
}
else {
! if (!( py_int = PyInt_FromLong(l))) goto finally;
}
--- 2657,2666 ----
}
else {
! if (len == 3 && (l == 0 || l == 1)) {
! if (!( py_int = PyBool_FromLong(l))) goto finally;
! }
! else {
! if (!( py_int = PyInt_FromLong(l))) goto finally;
! }
}
***************
*** 3761,3774 ****
case NONE:
if (load_none(self) < 0)
- break;
- continue;
-
- case FALSE:
- if (load_false(self) < 0)
- break;
- continue;
-
- case TRUE:
- if (load_true(self) < 0)
break;
continue;
--- 3767,3770 ----
- Previous message: [Python-checkins] CVS: python/dist/src/Lib/test test_bool.py,1.1,1.2
- Next message: [Python-checkins] CVS: python/nondist/peps pep-0001.txt,1.30,1.31 pep-0200.txt,1.48,1.49 pep-0269.txt,1.1,1.2 pep-0276.txt,1.3,1.4 pep-0279.txt,1.9,1.10 pep-0288.txt,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]