[pypy-svn] r32470 - in pypy/dist/pypy/module/_random: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Sep 19 00:32:59 CEST 2006


Author: cfbolz
Date: Tue Sep 19 00:32:57 2006
New Revision: 32470

Modified:
   pypy/dist/pypy/module/_random/interp_random.py
   pypy/dist/pypy/module/_random/test/test_random.py
Log:
very ugly way to get an unsigned int out of a long :-(


Modified: pypy/dist/pypy/module/_random/interp_random.py
==============================================================================
--- pypy/dist/pypy/module/_random/interp_random.py	(original)
+++ pypy/dist/pypy/module/_random/interp_random.py	Tue Sep 19 00:32:57 2006
@@ -42,7 +42,14 @@
                                 w_one)
         while space.is_true(w_n):
             w_chunk = space.and_(w_n, w_masklower)
-            chunk = r_uint(space.int_w(w_chunk))
+            try:
+                chunk = r_uint(space.int_w(w_chunk))
+            except OperationError, e:
+                # XXX just assuming that it is an OverflowError
+                # should only happen on 32 bit machines, so the following is
+                # correct
+                w_neg = space.sub(space.sub(w_chunk, w_masklower), w_one)
+                chunk = r_uint(space.int_w(w_neg))
             key.append(chunk)
             w_n = space.rshift(w_n, w_thirtytwo)
         if not key:

Modified: pypy/dist/pypy/module/_random/test/test_random.py
==============================================================================
--- pypy/dist/pypy/module/_random/test/test_random.py	(original)
+++ pypy/dist/pypy/module/_random/test/test_random.py	Tue Sep 19 00:32:57 2006
@@ -57,7 +57,7 @@
         import _random
         rnd = _random.Random()
         for arg in [None, 0, 0L, 1, 1L, -1, -1L, 10**20, -(10**20),
-                    3.14, 1+2j, 'a', tuple('abc')]:
+                    3.14, 1+2j, 'a', tuple('abc'), 0xffffffffffL]:
             rnd.seed(arg)
         for arg in [range(3), dict(one=1)]:
             raises(TypeError, rnd.seed, arg)



More information about the Pypy-commit mailing list