[pypy-svn] r25732 - in pypy/dist/pypy: rpython/lltypesystem rpython/lltypesystem/test translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Wed Apr 12 20:15:27 CEST 2006
Author: arigo
Date: Wed Apr 12 20:15:25 2006
New Revision: 25732
Modified:
pypy/dist/pypy/rpython/lltypesystem/lltype.py
pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
Actually, cast_subarray_pointer() works for slicing from FixedSizeArray
to FixedSizeArray too.
Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Wed Apr 12 20:15:25 2006
@@ -618,9 +618,9 @@
if not isinstance(CURPTRTYPE, Ptr) or not isinstance(ARRAYPTRTYPE, Ptr):
raise TypeError, "can only cast pointers to other pointers"
ARRAYTYPE = ARRAYPTRTYPE.TO
- if (not isinstance(CURPTRTYPE.TO, Array) or
+ if (not isinstance(CURPTRTYPE.TO, (Array, FixedSizeArray)) or
not isinstance(ARRAYTYPE, FixedSizeArray)):
- raise TypeError, "for now, can only cast Array to FixedSizeArray"
+ raise TypeError, "can only cast from arrays to FixedSizeArray"
if CURPTRTYPE.TO.OF != ARRAYTYPE.OF:
raise TypeError, "mismatching array item types"
if not arrayptr:
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py Wed Apr 12 20:15:25 2006
@@ -579,34 +579,34 @@
py.test.raises(TypeError, "s.a = a")
def test_cast_subarray_pointer():
- A = GcArray(Signed)
- a = malloc(A, 5)
- a[0] = 0
- a[1] = 10
- a[2] = 20
- a[3] = 30
- a[4] = 40
- BOX = Ptr(FixedSizeArray(Signed, 2))
- b01 = cast_subarray_pointer(BOX, a, 0)
- b12 = cast_subarray_pointer(BOX, a, 1)
- b23 = cast_subarray_pointer(BOX, a, 2)
- b34 = cast_subarray_pointer(BOX, a, 3)
- assert b01[0] == 0
- assert b01[1] == 10
- assert b12[0] == 10
- assert b12[1] == 20
- assert b23[0] == 20
- assert b23[1] == 30
- assert b34[0] == 30
- assert b34[1] == 40
- b23[0] = 23
- assert a[2] == 23
- b12[1] += 1
- assert a[2] == 24
- # out-of-bound access is allowed, if it's within the parent's bounds
- assert len(b23) == 2
- assert b23[-1] == 10
- assert b12[3] == 40
- py.test.raises(IndexError, "b01[-1]")
- py.test.raises(IndexError, "b34[2]")
- py.test.raises(IndexError, "b12[4]")
+ for a in [malloc(GcArray(Signed), 5),
+ malloc(FixedSizeArray(Signed, 5), immortal=True)]:
+ a[0] = 0
+ a[1] = 10
+ a[2] = 20
+ a[3] = 30
+ a[4] = 40
+ BOX = Ptr(FixedSizeArray(Signed, 2))
+ b01 = cast_subarray_pointer(BOX, a, 0)
+ b12 = cast_subarray_pointer(BOX, a, 1)
+ b23 = cast_subarray_pointer(BOX, a, 2)
+ b34 = cast_subarray_pointer(BOX, a, 3)
+ assert b01[0] == 0
+ assert b01[1] == 10
+ assert b12[0] == 10
+ assert b12[1] == 20
+ assert b23[0] == 20
+ assert b23[1] == 30
+ assert b34[0] == 30
+ assert b34[1] == 40
+ b23[0] = 23
+ assert a[2] == 23
+ b12[1] += 1
+ assert a[2] == 24
+ # out-of-bound access is allowed, if it's within the parent's bounds
+ assert len(b23) == 2
+ assert b23[-1] == 10
+ assert b12[3] == 40
+ py.test.raises(IndexError, "b01[-1]")
+ py.test.raises(IndexError, "b34[2]")
+ py.test.raises(IndexError, "b12[4]")
Modified: pypy/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py Wed Apr 12 20:15:25 2006
@@ -130,33 +130,33 @@
assert res == -1
def test_cast_subarray_pointer(self):
- A = GcArray(Signed)
- a = malloc(A, 5)
- a[0] = 0
- a[1] = 10
- a[2] = 20
- a[3] = 30
- a[4] = 40
- BOX = Ptr(FixedSizeArray(Signed, 2))
- b01 = cast_subarray_pointer(BOX, a, 0)
- b12 = cast_subarray_pointer(BOX, a, 1)
- b23 = cast_subarray_pointer(BOX, a, 2)
- b34 = cast_subarray_pointer(BOX, a, 3)
- def llf(n=int):
- saved = a[n]
- a[n] = 1000
- try:
- return b01[0] + b12[0] + b23[1] + b34[1]
- finally:
- a[n] = saved
- fn = self.getcompiled(llf)
- res = fn(0)
- assert res == 1000 + 10 + 30 + 40
- res = fn(1)
- assert res == 0 + 1000 + 30 + 40
- res = fn(2)
- assert res == 0 + 10 + 30 + 40
- res = fn(3)
- assert res == 0 + 10 + 1000 + 40
- res = fn(4)
- assert res == 0 + 10 + 30 + 1000
+ for a in [malloc(GcArray(Signed), 5),
+ malloc(FixedSizeArray(Signed, 5), immortal=True)]:
+ a[0] = 0
+ a[1] = 10
+ a[2] = 20
+ a[3] = 30
+ a[4] = 40
+ BOX = Ptr(FixedSizeArray(Signed, 2))
+ b01 = cast_subarray_pointer(BOX, a, 0)
+ b12 = cast_subarray_pointer(BOX, a, 1)
+ b23 = cast_subarray_pointer(BOX, a, 2)
+ b34 = cast_subarray_pointer(BOX, a, 3)
+ def llf(n=int):
+ saved = a[n]
+ a[n] = 1000
+ try:
+ return b01[0] + b12[0] + b23[1] + b34[1]
+ finally:
+ a[n] = saved
+ fn = self.getcompiled(llf)
+ res = fn(0)
+ assert res == 1000 + 10 + 30 + 40
+ res = fn(1)
+ assert res == 0 + 1000 + 30 + 40
+ res = fn(2)
+ assert res == 0 + 10 + 30 + 40
+ res = fn(3)
+ assert res == 0 + 10 + 1000 + 40
+ res = fn(4)
+ assert res == 0 + 10 + 30 + 1000
More information about the Pypy-commit
mailing list