[pypy-svn] r18220 - in pypy/dist/pypy: module/marshal module/marshal/test objspace/std
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 6 19:53:48 CEST 2005
Author: arigo
Date: Thu Oct 6 19:53:48 2005
New Revision: 18220
Modified:
pypy/dist/pypy/module/marshal/interp_marshal.py
pypy/dist/pypy/module/marshal/test/make_test_marshal.py
pypy/dist/pypy/module/marshal/test/test_marshal.py
pypy/dist/pypy/module/marshal/test/test_marshalimpl.py
pypy/dist/pypy/objspace/std/marshal_impl.py
Log:
(pedronis, arigo)
Fixes for marshal on 64-bit platforms.
Silent a warning on 32-bit platforms with Python 2.3.
Modified: pypy/dist/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/dist/pypy/module/marshal/interp_marshal.py Thu Oct 6 19:53:48 2005
@@ -362,6 +362,8 @@
b = ord(s[1])
c = ord(s[2])
d = ord(s[3])
+ if d & 0x80:
+ d -= 0x100
x = a | (b<<8) | (c<<16) | (d<<24)
return intmask(x)
@@ -481,6 +483,8 @@
b = ord(self.bufstr[pos+1])
c = ord(self.bufstr[pos+2])
d = ord(self.bufstr[pos+3])
+ if d & 0x80:
+ d -= 0x100
x = a | (b<<8) | (c<<16) | (d<<24)
return intmask(x)
Modified: pypy/dist/pypy/module/marshal/test/make_test_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/test/make_test_marshal.py (original)
+++ pypy/dist/pypy/module/marshal/test/make_test_marshal.py Thu Oct 6 19:53:48 2005
@@ -6,6 +6,7 @@
StopIteration
Ellipsis
42
+ -17
sys.maxint
-1.25
-1.25 #2
Modified: pypy/dist/pypy/module/marshal/test/test_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/test/test_marshal.py (original)
+++ pypy/dist/pypy/module/marshal/test/test_marshal.py Thu Oct 6 19:53:48 2005
@@ -114,6 +114,25 @@
x = marshal.load(f)
assert x == case
+ def test__minus_17(self):
+ import sys
+ hello = "he"
+ hello += "llo"
+ def func(x):
+ return lambda y: x+y
+ scopefunc = func(42)
+ import marshal, StringIO
+ case = -17
+ print "case: %-30s func=_minus_17" % (case, )
+ s = marshal.dumps(case)
+ x = marshal.loads(s)
+ assert x == case
+ f = StringIO.StringIO()
+ marshal.dump(case, f)
+ f.seek(0)
+ x = marshal.load(f)
+ assert x == case
+
def test_sys_dot_maxint(self):
import sys
hello = "he"
Modified: pypy/dist/pypy/module/marshal/test/test_marshalimpl.py
==============================================================================
--- pypy/dist/pypy/module/marshal/test/test_marshalimpl.py (original)
+++ pypy/dist/pypy/module/marshal/test/test_marshalimpl.py Thu Oct 6 19:53:48 2005
@@ -10,3 +10,13 @@
z = 0L
z1 = marshal.loads(marshal.dumps(z))
assert z == z1
+
+ def test_unmarshal_int64(self):
+ # test that we can unmarshal 64-bit ints on 32-bit platforms
+ # (of course we only test that if we're running on such a
+ # platform :-)
+ import marshal
+ z = marshal.loads('I\x00\xe4\x0bT\x02\x00\x00\x00')
+ assert z == 10000000000
+ z = marshal.loads('I\x00\x1c\xf4\xab\xfd\xff\xff\xff')
+ assert z == -10000000000
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Thu Oct 6 19:53:48 2005
@@ -146,9 +146,9 @@
def unmarshal_Int64(space, u, tc):
if LONG_BIT >= 64:
- lo = u.get_int() & 0xffff
+ lo = u.get_int() & (2**32-1)
hi = u.get_int()
- return W_IntObject(space, (hi << 32) or lo)
+ return W_IntObject(space, (hi << 32) | lo)
else:
# fall back to a long
# XXX at some point, we need to extend longobject
More information about the Pypy-commit
mailing list