[pypy-svn] r39881 - pypy/branch/pypy-2.5/pypy/objspace/std
gbrandl at codespeak.net
gbrandl at codespeak.net
Sun Mar 4 14:30:57 CET 2007
Author: gbrandl
Date: Sun Mar 4 14:30:48 2007
New Revision: 39881
Modified:
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/listtype.py
pypy/branch/pypy-2.5/pypy/objspace/std/slicetype.py
Log:
A few more int_w -> getindex_w changes.
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 14:30:48 2007
@@ -892,7 +892,7 @@
return wrapint(space, result)
def getitem__ListMulti_ANY(space, w_list, w_index):
- idx = space.int_w(w_index)
+ idx = get_list_index(space, w_index)
idx = _adjust_index(space, idx, w_list.implementation.length(),
"list index out of range")
return w_list.implementation.getitem(idx)
@@ -1025,7 +1025,7 @@
w_list2.implementation)
def delitem__ListMulti_ANY(space, w_list, w_idx):
- idx = space.int_w(w_idx)
+ idx = get_list_index(space, w_idx)
length = w_list.implementation.length()
idx = _adjust_index(space, idx, length, "list deletion index out of range")
if length == 1:
@@ -1059,7 +1059,7 @@
return space.w_None
def setitem__ListMulti_ANY_ANY(space, w_list, w_index, w_any):
- idx = space.int_w(w_index)
+ idx = get_list_index(space, w_index)
idx = _adjust_index(space, idx, w_list.implementation.length(),
"list index out of range")
w_list.implementation = w_list.implementation.i_setitem(idx, w_any)
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 14:30:48 2007
@@ -1,5 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.inttype import wrapint
+from pypy.objspace.std.listtype import get_list_index
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std.tupleobject import W_TupleObject
@@ -26,15 +27,6 @@
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__):
@@ -179,7 +171,7 @@
w_list2.wrappeditems)
def delitem__List_ANY(space, w_list, w_idx):
- idx = get_list_index(space, w_list)
+ idx = get_list_index(space, w_idx)
try:
del w_list.wrappeditems[idx]
except IndexError:
Modified: pypy/branch/pypy-2.5/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/listtype.py (original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/listtype.py Sun Mar 4 14:30:48 2007
@@ -61,3 +61,13 @@
__hash__ = no_hash_descr,
)
list_typedef.registermethods(globals())
+
+# ____________________________________________________________
+
+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)
Modified: pypy/branch/pypy-2.5/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/objspace/std/slicetype.py (original)
+++ pypy/branch/pypy-2.5/pypy/objspace/std/slicetype.py Sun Mar 4 14:30:48 2007
@@ -16,7 +16,7 @@
# utility functions
def _Eval_SliceIndex(space, w_int):
try:
- x = space.int_w(w_int)
+ x = space.getindex_w(w_int) # clamp if long integer is too large
except OperationError, e:
if not e.match(space, space.w_OverflowError):
raise
More information about the Pypy-commit
mailing list