From: <zy...@us...> - 2009-02-06 03:50:14
|
Revision: 6015 http://jython.svn.sourceforge.net/jython/?rev=6015&view=rev Author: zyasoft Date: 2009-02-06 03:50:10 +0000 (Fri, 06 Feb 2009) Log Message: ----------- Changed read/write binary_float so that it doesn't go through struct but instead j.l.Double's support for converting to/from bits. This also resolves endian ordering issues so that it follows the native endian ordering. Modified Paths: -------------- branches/pbcvm/src/org/python/modules/_marshal.java Modified: branches/pbcvm/src/org/python/modules/_marshal.java =================================================================== --- branches/pbcvm/src/org/python/modules/_marshal.java 2009-02-05 18:08:10 UTC (rev 6014) +++ branches/pbcvm/src/org/python/modules/_marshal.java 2009-02-06 03:50:10 UTC (rev 6015) @@ -105,8 +105,8 @@ } private void write_long64(long x) { - write_int((int) (x & 0xff)); - write_int((int) ((x >> 32) & 0xff)); + write_int((int) (x & 0xffffffff)); + write_int((int) ((x >> 32) & 0xffffffff)); } // writes output in 15 bit "digits" @@ -129,10 +129,8 @@ write_string(f.__repr__().toString()); } - // XXX - cache this struct object - // XXX - also fix reversed struct stuff! private void write_binary_float(PyFloat f) { - write_string(struct.pack(new PyObject[]{Py.newString("d"), f}).toString()); + write_long64(Double.doubleToLongBits(f.getValue())); } private void write_object(PyObject v, int depth) { @@ -339,9 +337,7 @@ } private double read_binary_float() { - String buffer = read_string(8); - PyFloat num = (PyFloat) ((struct.unpack("d", buffer)).__getitem__(0)); - return num.asDouble(); + return Double.longBitsToDouble(read_long64()); } private PyObject read_object_notnull(int depth) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |