[pypy-commit] pypy py3.3: array: Correctly convert bigint object to longlong numbers.

amauryfa noreply at buildbot.pypy.org
Thu Jan 1 19:13:46 CET 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.3
Changeset: r75200:235ef201d238
Date: 2015-01-01 18:58 +0100
http://bitbucket.org/pypy/pypy/changeset/235ef201d238/

Log:	array: Correctly convert bigint object to longlong numbers.

diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -585,7 +585,7 @@
         self.itemtype = itemtype
         self.bytes = rffi.sizeof(itemtype)
         self.arraytype = lltype.Array(itemtype, hints={'nolength': True})
-        self.unwrap = unwrap
+        self.unwrap, _, self.convert = unwrap.partition('.')
         self.signed = signed
         self.canoverflow = canoverflow
         self.w_class = None
@@ -616,12 +616,9 @@
     'i': TypeCode(rffi.INT,           'int_w', True, True),
     'I': TypeCode(rffi.UINT,          'int_w', True),
     'l': TypeCode(rffi.LONG,          'int_w', True, True),
-    'L': TypeCode(rffi.ULONG,         'bigint_w'),  # Overflow handled by
-                                                    # rbigint.touint() which
-                                                    # corresponds to the
-                                                    # C-type unsigned long
-    'q': TypeCode(rffi.LONGLONG,      'bigint_w', True, True),
-    'Q': TypeCode(rffi.ULONGLONG,     'bigint_w', True),
+    'L': TypeCode(rffi.ULONG,         'bigint_w.touint'),
+    'q': TypeCode(rffi.LONGLONG,      'bigint_w.tolonglong', True, True),
+    'Q': TypeCode(rffi.ULONGLONG,     'bigint_w.toulonglong', True),
     'f': TypeCode(lltype.SingleFloat, 'float_w', method='__float__'),
     'd': TypeCode(lltype.Float,       'float_w', method='__float__'),
     }
@@ -701,9 +698,9 @@
                                     "array item must be " + mytype.unwrap[:-2])
                 else:
                     raise
-            if mytype.unwrap == 'bigint_w':
+            if mytype.convert:
                 try:
-                    item = item.touint()
+                    item = getattr(item, mytype.convert)()
                 except (ValueError, OverflowError):
                     msg = 'unsigned %d-byte integer out of range' % \
                           mytype.bytes
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -413,7 +413,7 @@
     def test_buffer(self):
         a = self.array('h', b'Hi')
         buf = memoryview(a)
-        assert buf[1] == b'i'
+        assert buf[1] == ord('i')
 
     def test_buffer_write(self):
         a = self.array('b', b'hello')
@@ -426,7 +426,7 @@
 
     def test_buffer_keepalive(self):
         buf = memoryview(self.array('b', b'text'))
-        assert buf[2] == b'x'
+        assert buf[2] == ord('x')
         #
         a = self.array('b', b'foobarbaz')
         buf = memoryview(a)


More information about the pypy-commit mailing list