[pypy-svn] r25306 - in pypy/dist/pypy: annotation rpython/rctypes/test

arigo at codespeak.net arigo at codespeak.net
Tue Apr 4 18:04:07 CEST 2006


Author: arigo
Date: Tue Apr  4 18:04:05 2006
New Revision: 25306

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/rpython/rctypes/test/test_rarray.py
Log:
(arre, arigo)

Re-enabled a test.  Reorganized a little bit things although the test
passed at once.



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Tue Apr  4 18:04:05 2006
@@ -745,6 +745,9 @@
 
     def getitem((s_cto, s_index)):
         if s_index.is_constant():
+            # check that the constant index is valid, just because we
+            # are nice (users should really catch such errors by
+            # testing their programs!)
             idx = s_index.const
             knowntype = s_cto.knowntype
             try:
@@ -758,18 +761,20 @@
                     raise IndexError( "invalid index" )
                 elif idx < 0:
                     raise IndexError( "invalid index" )
-        try:
-            # This is the case for unboxed values, which
-            # are those having memorystate NOMEMORY
-            return s_cto.knowntype._type_.annotator_type
-        except AttributeError:
-            if extregistry.is_registered_type(s_cto.knowntype._type_):
-                entry = extregistry.lookup_type(s_cto.knowntype._type_)
-                return lltype_to_annotation(entry.lowleveltype)
-                
+
+        # Note: The following works for index either pointers and arrays,
+        # because both have a _type_ attribute that contains the type of the
+        # object pointed to or in the case of an array the element type.
+        assert hasattr(s_cto.knowntype, '_type_')
+        assert extregistry.is_registered_type(s_cto.knowntype._type_)
+        entry = extregistry.lookup_type(s_cto.knowntype._type_)
+        if hasattr(entry, 'lowleveltype'):
+            # special case for reading primitives out of arrays
+            return lltype_to_annotation(entry.lowleveltype)
+        else:
             return SomeCTypesObject(
-                    s_cto.knowntype._type_,
-                    memorystate=s_cto.memorystate)
+                s_cto.knowntype._type_,
+                memorystate=s_cto.memorystate)
 
 class __extend__(pairtype(SomeCTypesObject, SomeSlice)):
     def setitem((s_cto, s_slice), s_iterable):

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	Tue Apr  4 18:04:05 2006
@@ -15,10 +15,9 @@
 except ImportError:
     py.test.skip("this test needs ctypes installed")
 
-from ctypes import c_int, ARRAY, POINTER
+from ctypes import c_int, ARRAY, POINTER, pointer
 
 c_int_10 = ARRAY(c_int,10)
-c_int_p_test = POINTER(c_int)
 
 #py.test.skip("Reworking primitive types")
 
@@ -50,22 +49,15 @@
         if conftest.option.view:
             t.view()
 
-    def x_test_annotate_pointer_access_as_array(self):
+    def test_annotate_pointer_access_as_array(self):
         """
-        Make sure that pointers work the same way as arrays, for 
-        ctypes compatibility.
-
-        :Note: This works because pointer and array classes both
-        have a _type_ attribute, that contains the type of the 
-        object pointed to or in the case of an array the element type. 
+        Make sure that pointers work the same way as arrays.
         """
         def access_array():
             # Never run this function!
-            # See test_annotate_pointer_access_as_array_or_whatever
-            # for the weird reasons why this gets annotated
-            my_pointer = c_int_p_test(10)
+            my_pointer = pointer(c_int(10))
             my_pointer[0] = c_int(1)
-            my_pointer[1] = 2
+            my_pointer[1] = 2    # <== because of this
 
             return my_pointer[0]
 
@@ -73,7 +65,9 @@
         a = t.buildannotator()
         s = a.build_types(access_array, [])
         assert s.knowntype == int
-        #d#t.view()
+
+        if conftest.option.view:
+            t.view()
 
     def x_test_annotate_array_slice_access(self):
         def slice_access():



More information about the Pypy-commit mailing list