[pypy-svn] r25888 - in pypy/dist/pypy/rpython/rctypes: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Apr 17 14:31:53 CEST 2006
Author: arigo
Date: Mon Apr 17 14:31:52 2006
New Revision: 25888
Modified:
pypy/dist/pypy/rpython/rctypes/rarray.py
pypy/dist/pypy/rpython/rctypes/test/test_rarray.py
Log:
Test and bug fix.
Modified: pypy/dist/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rarray.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rarray.py Mon Apr 17 14:31:52 2006
@@ -77,14 +77,17 @@
class __extend__(pairtype(ArrayRepr, IntegerRepr)):
def rtype_getitem((r_array, r_int), hop):
v_array, v_index = hop.inputargs(r_array, lltype.Signed)
- if isinstance(r_array.r_item, CTypesRefRepr):
+ if isinstance(r_array.r_item, PrimitiveRepr):
+ # primitive case (optimization; the below also works in this case)
+ # NB. this optimization is invalid for PointerReprs! See for
+ # example: a[0].contents = ... to change the first pointer of
+ # an array of pointers.
+ v_value = r_array.get_item_value(hop.llops, v_array, v_index)
+ return r_array.r_item.return_value(hop.llops, v_value)
+ else:
# ByRef case
v_c_data = r_array.get_c_data_of_item(hop.llops, v_array, v_index)
return r_array.r_item.return_c_data(hop.llops, v_c_data)
- else:
- # ByValue case (optimization; the above also works in this case)
- v_value = r_array.get_item_value(hop.llops, v_array, v_index)
- return r_array.r_item.return_value(hop.llops, v_value)
def rtype_setitem((r_array, r_int), hop):
v_array, v_index, v_item = hop.inputargs(r_array, lltype.Signed,
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rarray.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rarray.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rarray.py Mon Apr 17 14:31:52 2006
@@ -233,6 +233,20 @@
res = interpret(func, [])
assert res == 42
+ def test_array_of_pointers(self):
+ class S(Structure):
+ _fields_ = [('x', c_int)]
+ A = POINTER(S) * 10
+ def func():
+ a = A()
+ s = S()
+ s.x = 11
+ a[2].contents = s
+ a[3] = pointer(s)
+ return a[2].contents.x * a[3].contents.x
+ res = interpret(func, [])
+ assert res == 121
+
class Test_compilation:
def test_compile_array_access(self):
def access_array():
More information about the Pypy-commit
mailing list