[pypy-svn] r73343 - pypy/trunk/pypy/rpython/lltypesystem

benjamin at codespeak.net benjamin at codespeak.net
Sun Apr 4 01:01:05 CEST 2010


Author: benjamin
Date: Sun Apr  4 01:01:03 2010
New Revision: 73343

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
Log:
(pitrou) python 2.5 can raise an OverflowError computing MAX_SIZE

Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	Sun Apr  4 01:01:03 2010
@@ -114,8 +114,17 @@
     assert max_n >= 0
     ITEM = A.OF
     ctypes_item = get_ctypes_type(ITEM, delayed_builders)
-    MAX_SIZE = sys.maxint/64
-    PtrType = ctypes.POINTER(MAX_SIZE * ctypes_item)
+    # Python 2.5 ctypes can raise OverflowError on 64-bit builds
+    for n in [sys.maxint, 2**31]:
+        MAX_SIZE = n/64
+        try:
+            PtrType = ctypes.POINTER(MAX_SIZE * ctypes_item)
+        except OverflowError, e:
+            pass
+        else:
+            break
+    else:
+        raise e
 
     class CArray(ctypes.Structure):
         if not A._hints.get('nolength'):



More information about the Pypy-commit mailing list