[pypy-svn] r39875 - in pypy/branch/pypy-2.5/pypy: module/mmap objspace objspace/std

gbrandl at codespeak.net gbrandl at codespeak.net
Sun Mar 4 13:53:08 CET 2007


Author: gbrandl
Date: Sun Mar  4 13:53:05 2007
New Revision: 39875

Modified:
   pypy/branch/pypy-2.5/pypy/module/mmap/interp_mmap.py
   pypy/branch/pypy-2.5/pypy/objspace/descroperation.py
   pypy/branch/pypy-2.5/pypy/objspace/std/listmultiobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/listobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/rangeobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/sliceobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/stringobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/strsliceobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/tupleobject.py
   pypy/branch/pypy-2.5/pypy/objspace/std/unicodeobject.py
Log:
(gbrandl, xoraxax) use space.getindex_w for sequence indices, more to follow.


Modified: pypy/branch/pypy-2.5/pypy/module/mmap/interp_mmap.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/mmap/interp_mmap.py	(original)
+++ pypy/branch/pypy-2.5/pypy/module/mmap/interp_mmap.py	Sun Mar  4 13:53:05 2007
@@ -350,7 +350,7 @@
                 self.space.wrap("seek out of range"))
         
         self.pos = where
-    seek.unwrap_spec = ['self', int, int]
+    seek.unwrap_spec = ['self', 'index', int]
     
     def tell(self):
         self.check_valid()
@@ -679,7 +679,7 @@
         m.setdata(res, map_size)
 
         return space.wrap(m)
-    mmap.unwrap_spec = [ObjSpace, int, int, int, int, int]
+    mmap.unwrap_spec = [ObjSpace, int, 'index', int, int, int]
 elif _MS_WINDOWS:
     def mmap(space, fileno, length, tagname="", access=_ACCESS_DEFAULT):
         # check size boundaries
@@ -771,4 +771,4 @@
 
         raise OperationError(space.w_EnvironmentError,
                              space.wrap(os.strerror(dwErr)))
-    mmap.unwrap_spec = [ObjSpace, int, int, str, int]
+    mmap.unwrap_spec = [ObjSpace, int, 'index', str, int]

Modified: pypy/branch/pypy-2.5/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/descroperation.py	Sun Mar  4 13:53:05 2007
@@ -580,7 +580,7 @@
 for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
     if not hasattr(DescrOperation, _name):
         _impl_maker = None
-        if _arity ==2 and _name in ['lt', 'le', 'gt', 'ge', 'ne', 'eq']:
+        if _arity == 2 and _name in ['lt', 'le', 'gt', 'ge', 'ne', 'eq']:
             #print "comparison", _specialnames
             _impl_maker = _make_comparison_impl
         elif _arity == 2 and _name.startswith('inplace_'):

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/listmultiobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/listmultiobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/listmultiobject.py	Sun Mar  4 13:53:05 2007
@@ -940,7 +940,7 @@
 
 def mul_list_times(space, w_list, w_times):
     try:
-        times = space.int_w(w_times)
+        times = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement
@@ -957,7 +957,7 @@
 
 def inplace_mul__ListMulti_ANY(space, w_list, w_times):
     try:
-        times = space.int_w(w_times)
+        times = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/listobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/listobject.py	Sun Mar  4 13:53:05 2007
@@ -26,6 +26,15 @@
 registerimplementation(W_ListObject)
 
 
+def get_list_index(space, w_index):
+    if not space.lookup(w_index, '__index__'):
+        raise OperationError(
+            space.w_TypeError,
+            space.wrap("list indices must be integers, not %s" %
+                       space.type(w_index).getname(space, '?')))
+    return space.getindex_w(w_index, space.w_IndexError)
+
+
 EMPTY_LIST = W_ListObject([])
 
 def init__List(space, w_list, __args__):
@@ -42,9 +51,8 @@
     return wrapint(space, result)
 
 def getitem__List_ANY(space, w_list, w_index):
-    idx = space.int_w(w_index)
     try:
-        return w_list.wrappeditems[idx]
+        return w_list.wrappeditems[get_list_index(space, w_index)]
     except IndexError:
         raise OperationError(space.w_IndexError,
                              space.wrap("list index out of range"))
@@ -92,7 +100,7 @@
 
 def mul_list_times(space, w_list, w_times):
     try:
-        times = space.int_w(w_times)
+        times = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement
@@ -107,7 +115,7 @@
 
 def inplace_mul__List_ANY(space, w_list, w_times):
     try:
-        times = space.int_w(w_times)
+        times = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement
@@ -171,7 +179,7 @@
         w_list2.wrappeditems)
 
 def delitem__List_ANY(space, w_list, w_idx):
-    idx = space.int_w(w_idx)
+    idx = get_list_index(space, w_list)
     try:
         del w_list.wrappeditems[idx]
     except IndexError:
@@ -227,7 +235,7 @@
     return space.w_None
 
 def setitem__List_ANY_ANY(space, w_list, w_index, w_any):
-    idx = space.int_w(w_index)
+    idx = get_list_index(space, w_index)
     try:
         w_list.wrappeditems[idx] = w_any
     except IndexError:

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/rangeobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/rangeobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/rangeobject.py	Sun Mar  4 13:53:05 2007
@@ -78,7 +78,7 @@
 def getitem__RangeList_ANY(space, w_rangelist, w_index):
     if w_rangelist.w_list is not None:
         return space.getitem(w_rangelist.w_list, w_index)
-    idx = space.int_w(w_index)
+    idx = space.getindex_w(w_index, space.w_IndexError)
     try:
         return wrapint(space, w_rangelist.getitem(idx))
     except IndexError:

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/sliceobject.py	Sun Mar  4 13:53:05 2007
@@ -111,7 +111,7 @@
 # indices impl
 
 def slice_indices__Slice_ANY(space, w_slice, w_length):
-    length = space.int_w(w_length)
+    length = space.getindex_w(w_length, space.w_OverflowError)
     start, stop, step = w_slice.indices3(space, length)
     return space.newtuple([space.wrap(start), space.wrap(stop),
                            space.wrap(step)])

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/stringobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/stringobject.py	Sun Mar  4 13:53:05 2007
@@ -1,4 +1,4 @@
-# -*- Coding: Latin-1 -*-
+# -*- coding: latin-1 -*-
 
 from pypy.objspace.std.objspace import *
 from pypy.interpreter import gateway
@@ -730,7 +730,12 @@
         return space.w_False
 
 def getitem__String_ANY(space, w_str, w_index):
-    ival = space.int_w(w_index)
+    if not space.lookup(w_index, '__index__'):
+        raise OperationError(
+            space.w_TypeError,
+            space.wrap("string indices must be integers, not %s" %
+                       space.type(w_index).getname(space, '?')))
+    ival = space.getindex_w(w_index, space.w_IndexError)
     str = w_str._value
     slen = len(str)
     if ival < 0:
@@ -757,7 +762,7 @@
 
 def mul_string_times(space, w_str, w_times):
     try:
-        mul = space.int_w(w_times)
+        mul = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement
@@ -810,9 +815,6 @@
 def getnewargs__String(space, w_str):
     return space.newtuple([wrapstr(space, w_str._value)])
 
-def index__String(space, w_str):
-    return space.wrap(42)
-
 def repr__String(space, w_str):
     s = w_str._value
 

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/strsliceobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/strsliceobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/strsliceobject.py	Sun Mar  4 13:53:05 2007
@@ -112,7 +112,12 @@
 
 
 def getitem__StringSlice_ANY(space, w_str, w_index):
-    ival = space.int_w(w_index)
+    if not space.lookup(w_index, '__index__'):
+        raise OperationError(
+            space.w_TypeError,
+            space.wrap("string indices must be integers, not %s" %
+                       space.type(w_index).getname(space, '?')))
+    ival = space.getindex_w(w_index, space.w_IndexError)
     slen = w_str.stop - w_str.start
     if ival < 0:
         ival += slen

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/tupleobject.py	Sun Mar  4 13:53:05 2007
@@ -28,13 +28,18 @@
     return wrapint(space, result)
 
 def getitem__Tuple_ANY(space, w_tuple, w_index):
-    items = w_tuple.wrappeditems
+    if not space.lookup(w_index, '__index__'):
+        raise OperationError(
+            space.w_TypeError,
+            space.wrap("tuple indices must be integers, not %s" %
+                       space.type(w_index).getname(space, '?')))
     try:
-        w_item = items[space.int_w(w_index)]
+        # XXX: getindex_w should get a second argument space.w_IndexError,
+        #      but that doesn't exist the first time this is called.
+        return w_tuple.wrappeditems[space.getindex_w(w_index)]
     except IndexError:
         raise OperationError(space.w_IndexError,
                              space.wrap("tuple index out of range"))
-    return w_item
 
 def getitem__Tuple_Slice(space, w_tuple, w_slice):
     items = w_tuple.wrappeditems
@@ -64,7 +69,7 @@
 
 def mul_tuple_times(space, w_tuple, w_times):
     try:
-        times = space.int_w(w_times)
+        times = space.getindex_w(w_times, space.w_OverflowError)
     except OperationError, e:
         if e.match(space, space.w_TypeError):
             raise FailedToImplement

Modified: pypy/branch/pypy-2.5/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/unicodeobject.py	Sun Mar  4 13:53:05 2007
@@ -203,7 +203,12 @@
     return space.wrap(len(w_uni._value))
 
 def getitem__Unicode_ANY(space, w_uni, w_index):
-    ival = space.int_w(w_index)
+    if not space.lookup(w_index, '__index__'):
+        raise OperationError(
+            space.w_TypeError,
+            space.wrap("string indices must be integers, not %s" %
+                       space.type(w_index).getname(space, '?')))
+    ival = space.getindex_w(w_index, space.w_IndexError)
     uni = w_uni._value
     ulen = len(uni)
     if ival < 0:
@@ -230,7 +235,7 @@
 def mul__Unicode_ANY(space, w_uni, w_times):
     chars = w_uni._value
     charlen = len(chars)
-    times = space.int_w(w_times)
+    times = space.getindex_w(w_times, space.w_OverflowError)
     if times <= 0 or charlen == 0:
         return W_UnicodeObject([])
     if times == 1:



More information about the Pypy-commit mailing list