Author: Antonio Cuni <[email protected]>
Branch: int_w-refactor
Changeset: r69430:ea3291c41c47
Date: 2014-02-25 17:30 +0100
http://bitbucket.org/pypy/pypy/changeset/ea3291c41c47/
Log: start reviewing all usages of int_w(): we cannot use fake ints as
indexes
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -92,7 +92,7 @@
i = 2 * HUGEVAL_BYTES
addrstring = [' '] * i
while True:
- n = space.int_w(space.and_(w_id, w_0x0F))
+ n = space.int_w(space.and_(w_id, w_0x0F), allow_conversion=False)
n += ord('0')
if n > ord('9'):
n += (ord('a') - ord('9') - 1)
@@ -1238,7 +1238,7 @@
start, stop, step, length = w_index_or_slice.indices4(self,
seqlength)
else:
- start = self.int_w(w_index_or_slice)
+ start = self.int_w(w_index_or_slice, allow_conversion=False)
if start < 0:
start += seqlength
if not (0 <= start < seqlength):
diff --git a/pypy/module/__builtin__/test/test_buffer.py
b/pypy/module/__builtin__/test/test_buffer.py
--- a/pypy/module/__builtin__/test/test_buffer.py
+++ b/pypy/module/__builtin__/test/test_buffer.py
@@ -170,6 +170,18 @@
for step in indices[1:]:
assert b[start:stop:step] == s[start:stop:step]
+ def test_getitem_only_ints(self):
+ class MyInt(object):
+ def __init__(self, x):
+ self.x = x
+
+ def __int__(self):
+ return self.x
+
+ buf = buffer('hello world')
+ raises(TypeError, "buf[MyInt(0)]")
+ raises(TypeError, "buf[MyInt(0):MyInt(5)]")
+
class AppTestMemoryView:
def test_basic(self):
v = memoryview("abc")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit