From: <pj...@us...> - 2008-07-17 21:25:49
|
Revision: 4966 http://jython.svn.sourceforge.net/jython/?rev=4966&view=rev Author: pjenvey Date: 2008-07-17 21:25:44 +0000 (Thu, 17 Jul 2008) Log Message: ----------- fix loading of 0L in cPickle proto 2 and match cPickle's dumps(0L, 2) to pickle's Modified Paths: -------------- trunk/jython/src/org/python/modules/cPickle.java Added Paths: ----------- trunk/jython/Lib/test/test_cpickle_jy.py Added: trunk/jython/Lib/test/test_cpickle_jy.py =================================================================== --- trunk/jython/Lib/test/test_cpickle_jy.py (rev 0) +++ trunk/jython/Lib/test/test_cpickle_jy.py 2008-07-17 21:25:44 UTC (rev 4966) @@ -0,0 +1,22 @@ +"""Misc cPickle tests. + +Made for Jython. +""" +import cPickle +import pickle +import unittest +from test import test_support + +class CPickleTestCase(unittest.TestCase): + + def test_zero_long(self): + self.assertEqual(cPickle.loads(cPickle.dumps(0L, 2)), 0L) + self.assertEqual(cPickle.dumps(0L, 2), pickle.dumps(0L, 2)) + + +def test_main(): + test_support.run_unittest(CPickleTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2008-07-17 21:19:56 UTC (rev 4965) +++ trunk/jython/src/org/python/modules/cPickle.java 2008-07-17 21:25:44 UTC (rev 4966) @@ -1163,9 +1163,17 @@ private void save_long(PyObject object) { if(protocol >= 2) { BigInteger integer = ((PyLong)object).getValue(); + + if (integer.compareTo(BigInteger.ZERO) == 0) { + // It's 0 -- an empty bytestring. + file.write(LONG1); + file.write((char)0); + return; + } + byte[] bytes = integer.toByteArray(); int l = bytes.length; - if(l < 256) { + if (l < 256) { file.write(LONG1); file.write((char)l); } else { @@ -1938,6 +1946,10 @@ private void load_bin_long(int length) { int longLength = read_binint(length); + if (longLength == 0) { + push(new PyLong(BigInteger.ZERO)); + return; + } String s = file.read(longLength); byte[] bytes = new byte[s.length()]; // Write to the byte array in reverse order: pickle orders This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |