[pypy-svn] r18683 - in pypy/dist/pypy: objspace/flow rpython rpython/test translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Sun Oct 16 14:11:27 CEST 2005
Author: arigo
Date: Sun Oct 16 14:11:25 2005
New Revision: 18683
Modified:
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
pypy/dist/pypy/translator/c/test/test_annotated.py
Log:
* flow space now supports raising IndexError in setitem
* minor changes in rlist.delitem's bound checking.
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Sun Oct 16 14:11:25 2005
@@ -353,7 +353,8 @@
return self.w_None
except UnwrapException:
pass
- return self.do_operation('setitem', w_obj, w_key, w_val)
+ return self.do_operation_with_implicit_exceptions('setitem', w_obj,
+ w_key, w_val)
def call_args(self, w_callable, args):
try:
@@ -456,9 +457,7 @@
implicit_exceptions[name+"_ovf"] = lis
for _err in IndexError, KeyError:
- _add_exceptions("""getitem""", _err)
- _add_exceptions("""delitem""", _err)
- # no implicit exceptions for setitem
+ _add_exceptions("""getitem setitem delitem""", _err)
for _name in 'getattr', 'delattr':
_add_exceptions(_name, AttributeError)
for _name in 'iter', 'coerce':
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Sun Oct 16 14:11:25 2005
@@ -535,7 +535,7 @@
def ll_delitem_nonneg(func, l, index):
length = l.length
- if func is dum_checkidx and (index < 0 or index >= length):
+ if func is dum_checkidx and (index >= length):
raise IndexError
newlength = length - 1
j = index
@@ -551,9 +551,12 @@
_ll_list_resize_le(l, newlength)
def ll_delitem(func, l, i):
+ length = l.length
if i < 0:
- i += l.length
- ll_delitem_nonneg(func, l, i)
+ i += length
+ if func is dum_checkidx and (i < 0 or i >= length):
+ raise IndexError
+ ll_delitem_nonneg(dum_nocheck, l, i)
def ll_concat(l1, l2):
len1 = l1.length
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Sun Oct 16 14:11:25 2005
@@ -429,6 +429,10 @@
def fn(i):
l = [5, 8, 3]
try:
+ l[i] = 99
+ except IndexError:
+ pass
+ try:
del l[i]
except IndexError:
pass
Modified: pypy/dist/pypy/translator/c/test/test_annotated.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_annotated.py (original)
+++ pypy/dist/pypy/translator/c/test/test_annotated.py Sun Oct 16 14:11:25 2005
@@ -199,3 +199,17 @@
assert fn(65) == 65
assert fn(-12) == -42
assert fn(sys.maxint) == -42
+
+ def test_list_indexerror(self):
+ def f(i=int):
+ lst = [123, 456]
+ try:
+ lst[i] = 789
+ except IndexError:
+ return 42
+ return lst[0]
+ fn = self.getcompiled(f)
+ assert fn(1) == 123
+ assert fn(2) == 42
+ assert fn(-2) == 789
+ assert fn(-3) == 42
More information about the Pypy-commit
mailing list