[pypy-svn] r39873 - in pypy/dist/pypy/translator/llvm: . test

rxe at codespeak.net rxe at codespeak.net
Sun Mar 4 13:46:40 CET 2007


Author: rxe
Date: Sun Mar  4 13:46:36 2007
New Revision: 39873

Modified:
   pypy/dist/pypy/translator/llvm/structnode.py
   pypy/dist/pypy/translator/llvm/test/test_lltype.py
Log:
(mwh, rxe) fix case when we get childref inside another pbc (see tests)

Modified: pypy/dist/pypy/translator/llvm/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/structnode.py	(original)
+++ pypy/dist/pypy/translator/llvm/structnode.py	Sun Mar  4 13:46:36 2007
@@ -202,13 +202,12 @@
         if p is None:
             ref = self.ref
         else:
-            assert isinstance(self.value, lltype._subarray)
             ref = self.db.get_childref(p, c)
-
-            # ptr -> array of len 1
-            ref = "cast(%s* %s to %s*)" % (self.db.repr_type(self.arraytype),
-                                           ref,
-                                           self.db.repr_type(lltype.typeOf(self.value)))
+            if isinstance(self.value, lltype._subarray):
+                # ptr -> array of len 1
+                ref = "cast(%s* %s to %s*)" % (self.db.repr_type(self.arraytype),
+                                               ref,
+                                               self.db.repr_type(lltype.typeOf(self.value)))
         return ref
 
     def get_childref(self, index):

Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lltype.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_lltype.py	Sun Mar  4 13:46:36 2007
@@ -432,3 +432,56 @@
     res = fn()
     assert res == 8765
 
+def test_pointer2fixedsizearray():
+    A = FixedSizeArray(Signed, 1)
+    EmbedS = GcStruct('S', ('data', A))
+    S = GcStruct('S', ('c_data', Ptr(A)))
+                 
+    e = malloc(EmbedS, zero=True)
+    s = malloc(S, zero=True)
+    c_data = s.c_data = e.data
+    c_data[0] = 42
+
+    def llf():
+        return s.c_data[0]
+
+    fn = compile_function(llf, [])
+    res = fn()
+    assert res == 42
+
+def test_rctypes_array_access():
+    from ctypes import ARRAY, c_int
+    c_int_1 = ARRAY(c_int, 1)
+    
+    my_array = c_int_1()
+    
+    def llf():
+        my_array[0] = 42
+        return my_array[0]
+
+    fn = compile_function(llf, [])
+    res = fn()
+    assert res == 42
+
+def test_rctypes_char_array_value():
+    from ctypes import c_char
+    A = c_char * 3
+
+    def llf(n):
+        a = A()
+        a[n+0] = 'x'
+        a[n+1] = 'y'
+        return a.value == 'xy'
+
+    fn = compile_function(llf, [int])
+    res = fn(0)
+    assert res
+
+def test_rctypes_variants():
+    py.test.skip("wip")
+    from pypy.rpython.rctypes.test import test_rarray
+    llf, expected = test_rarray.maketest()
+
+    fn = compile_function(llf, [])
+    res = fn()
+    assert res == expected



More information about the Pypy-commit mailing list