[pypy-svn] r40419 - pypy/dist/pypy/objspace/cpy

arigo at codespeak.net arigo at codespeak.net
Tue Mar 13 11:03:29 CET 2007


Author: arigo
Date: Tue Mar 13 11:03:28 2007
New Revision: 40419

Modified:
   pypy/dist/pypy/objspace/cpy/objspace.py
Log:
A hack to fix compilemodule for extension modules using 'index' in unwrap_spec.


Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py	Tue Mar 13 11:03:28 2007
@@ -1,4 +1,4 @@
-import types
+import types, sys
 from pypy.objspace.cpy.capi import *
 from pypy.objspace.cpy.capi import _PyType_Lookup
 from pypy.objspace.cpy.capi import _PyLong_Sign, _PyLong_NumBits, _PyLong_AsByteArray
@@ -153,6 +153,28 @@
         # hack here to have index working
         return self.wrap(self.int_w(w_obj))
 
+    def getindex_w(self, w_obj, w_exception, objdescr=None):
+        # XXX mess with type(w_obj).getname() in the baseobjspace,
+        # XXX give a simplified naive version
+        w_index = w_obj
+        try:
+            index = self.int_w(w_index)
+        except OperationError, err:
+            if not err.match(self, self.w_OverflowError):
+                raise
+            if not w_exception:
+                # w_index should be a long object, but can't be sure of that
+                if self.is_true(self.lt(w_index, self.wrap(0))):
+                    return -sys.maxint-1
+                else:
+                    return sys.maxint
+            else:
+                raise OperationError(
+                    w_exception, self.wrap(
+                    "cannot fit number into an index-sized integer"))
+        else:
+            return index
+
     def bigint_w(self, w_obj):
         if self.is_true(self.isinstance(w_obj, self.w_long)):
             sign = _PyLong_Sign(w_obj)



More information about the Pypy-commit mailing list