[pypy-commit] pypy default: fix fromstring for non-native types
bdkearns
noreply at buildbot.pypy.org
Fri Feb 21 01:20:11 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r69228:b2ec9d79e30c
Date: 2014-02-20 19:11 -0500
http://bitbucket.org/pypy/pypy/changeset/b2ec9d79e30c/
Log: fix fromstring for non-native types
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -3006,6 +3006,10 @@
assert (m == [1.0, -1.0, 2.0, 3.0]).all()
n = fromstring("3.4 2.0 3.8 2.2", dtype='int32', sep=" ")
assert (n == [3]).all()
+ n = fromstring('\x00\x00\x00{', dtype='>i4')
+ assert n == 123
+ n = fromstring('W\xb0', dtype='>f2')
+ assert n == 123.
o = fromstring("1.0 2f.0f 3.8 2.2", dtype='float32', sep=" ")
assert len(o) == 2
assert o[0] == 1.0
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -198,7 +198,9 @@
self._write(storage, i, offset, value)
def runpack_str(self, space, s):
- v = runpack(self.format_code, s)
+ v = rffi.cast(self.T, runpack(self.format_code, s))
+ if not self.native:
+ v = byteswap(v)
return self.box(v)
@simple_binary_op
@@ -972,8 +974,10 @@
def runpack_str(self, space, s):
assert len(s) == 2
- fval = unpack_float(s, native_is_bigendian)
- return self.box(fval)
+ fval = self.box(unpack_float(s, native_is_bigendian))
+ if not self.native:
+ fval = self.byteswap(fval)
+ return fval
def default_fromstring(self, space):
return self.box(-1.0)
@@ -1599,8 +1603,10 @@
def runpack_str(self, space, s):
assert len(s) == interp_boxes.long_double_size
- fval = unpack_float80(s, native_is_bigendian)
- return self.box(fval)
+ fval = self.box(unpack_float80(s, native_is_bigendian))
+ if not self.native:
+ fval = self.byteswap(fval)
+ return fval
def byteswap(self, w_v):
value = self.unbox(w_v)
More information about the pypy-commit
mailing list