From: <cg...@us...> - 2007-08-12 06:15:09
|
Revision: 3409 http://jython.svn.sourceforge.net/jython/?rev=3409&view=rev Author: cgroves Date: 2007-08-11 23:15:07 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Applying patch #1770407 from yole to fix bug #1758317, bool objects fail to pickle Modified Paths: -------------- trunk/jython/Lib/test/test_bool.py trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/Lib/test/test_bool.py =================================================================== --- trunk/jython/Lib/test/test_bool.py 2007-08-12 05:57:22 UTC (rev 3408) +++ trunk/jython/Lib/test/test_bool.py 2007-08-12 06:15:07 UTC (rev 3409) @@ -341,11 +341,6 @@ check(Baz()) # Jython transition 2.3 -# pickle doesn't work on bool -# http://jython.org/bugs/1758317 -del BoolTest.test_picklevalues -del BoolTest.test_mixedpickle -del BoolTest.test_cpickle #operator missing is function # http://jython.org/bugs/1758315 del BoolTest.test_operator Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2007-08-12 05:57:22 UTC (rev 3408) +++ trunk/jython/src/org/python/modules/cPickle.java 2007-08-12 06:15:07 UTC (rev 3409) @@ -439,6 +439,8 @@ PyType.fromClass(PyTuple.class); private static PyType FileType = PyType.fromClass(PyFile.class); + private static PyType BoolType = + PyType.fromClass(PyBoolean.class); private static PyObject dict; @@ -1030,6 +1032,8 @@ save_global(object); else if (type == BuiltinFunctionType) save_global(object); + else if (type == BoolType) + save_bool(object); else return false; return true; @@ -1072,7 +1076,14 @@ } } + private void save_bool(PyObject object) { + int value = ((PyBoolean) object).getValue(); + file.write(INT); + file.write(value != 0 ? "01" : "00"); + file.write("\n"); + } + final private void save_long(PyObject object) { file.write(LONG); file.write(object.toString()); @@ -1654,13 +1665,21 @@ PyObject value; // The following could be abstracted into a common string // -> int/long method. - try { - value = Py.newInteger(Integer.parseInt(line)); - } catch(NumberFormatException e) { + if (line.equals("01")) { + value = Py.newBoolean(true); + } + else if (line.equals("00")) { + value = Py.newBoolean(false); + } + else { try { - value = Py.newLong(line); - } catch(NumberFormatException e2) { - throw Py.ValueError("could not convert string to int"); + value = Py.newInteger(Integer.parseInt(line)); + } catch(NumberFormatException e) { + try { + value = Py.newLong(line); + } catch(NumberFormatException e2) { + throw Py.ValueError("could not convert string to int"); + } } } push(value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |