[pypy-svn] r24503 - in pypy/dist/pypy/rpython/rctypes: . test

goden at codespeak.net goden at codespeak.net
Fri Mar 17 05:57:59 CET 2006


Author: goden
Date: Fri Mar 17 05:57:55 2006
New Revision: 24503

Modified:
   pypy/dist/pypy/rpython/rctypes/implementation.py
   pypy/dist/pypy/rpython/rctypes/interface.py
   pypy/dist/pypy/rpython/rctypes/rprimitive.py
   pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
removed references to the R* versions of POINTER, ARRAY, and byref from
interface.py.  took a stab at fixing the annotation and translation of
ctypes function calls by adding lookups to the extregistry.  appears to work
for primitive types.  re-enabled some of the tests in test_rctypes.py which
pass.



Modified: pypy/dist/pypy/rpython/rctypes/implementation.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/implementation.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/implementation.py	Fri Mar 17 05:57:55 2006
@@ -83,10 +83,22 @@
 CFuncPtrType = type(ctypes.CFUNCTYPE(None))
 
 def cfuncptrtype_compute_annotation(type, instance):
+    from pypy.annotation.model import ll_to_annotation_map
+
     def compute_result_annotation(*args_s):
         """
         Answer the annotation of the external function's result
         """
+
+        # results of external function calls *must* be in the registry
+        # XXX: goden: check metatype too?
+        assert extregistry.is_registered_type(instance.restype)
+
+        entry = extregistry.lookup_type(instance.restype)
+
+        # XXX: goden: this probably isn't right
+        return ll_to_annotation_map.get(entry.lowleveltype)
+        
         # Take 3, Check whether we can get away with the cheap
         # precomputed solution and if not it, use a special
         # attribute with the memory state
@@ -126,10 +138,15 @@
                 answer.append(ctype_type.wrap_arg(ll_type, arg_name))
         return answer
 
+    assert extregistry.is_registered_type(cfuncptr.restype)
+
+    # results of external function calls *must* be in the registry
+    entry = extregistry.lookup_type(cfuncptr.restype)
+
     return hop.llops.gencapicall(
             cfuncptr.__name__,
             hop.args_v,
-            resulttype = cfuncptr.restype.ll_type,
+            resulttype = entry.lowleveltype,
             _callable=None,
             convert_params = convert_params ) 
 

Modified: pypy/dist/pypy/rpython/rctypes/interface.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/interface.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/interface.py	Fri Mar 17 05:57:55 2006
@@ -3,8 +3,7 @@
         c_char, c_byte, c_ubyte, \
         c_short, c_ushort, c_uint,\
         c_long, c_ulong, c_longlong, c_ulonglong, c_float, c_double, \
-        RStructure as Structure, RByref as byref, RPOINTER as POINTER, \
-        ARRAY
+        Structure, byref, POINTER, ARRAY
 #try:
 #    from implementation import RWinDLL as WinDLL
 #except ImportError:

Modified: pypy/dist/pypy/rpython/rctypes/rprimitive.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rprimitive.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/rprimitive.py	Fri Mar 17 05:57:55 2006
@@ -104,6 +104,7 @@
     def compute_result_annotation_function(s_arg=None):
         return annmodel.SomeCTypesObject(the_type,
                 annmodel.SomeCTypesObject.OWNSMEMORY)
+
     extregistry.register_value(the_type,
         compute_result_annotation=compute_result_annotation_function,
         specialize_call=primitive_specialize_call

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	Fri Mar 17 05:57:55 2006
@@ -43,7 +43,7 @@
     py.test.skip("this test needs ctypes installed")
 
 
-py.test.skip("these tests are broken while the ctypes primitive types are ported to use the extregistry")
+#py.test.skip("these tests are broken while the ctypes primitive types are ported to use the extregistry")
 
 from pypy.rpython.rctypes import cdll, c_char_p, c_int, c_char, \
         c_char, c_byte, c_ubyte, c_short, c_ushort, c_uint,\
@@ -303,7 +303,7 @@
         res = py_testfunc_struct(in_point)
         assert res == 30
 
-    def test_annotate_struct(self):
+    def x_test_annotate_struct(self):
         a = RPythonAnnotator()
         s = a.build_types(py_testfunc_struct, [tagpoint])
         assert s.knowntype == int
@@ -311,14 +311,14 @@
         if conftest.option.view:
             a.translator.view()
 
-    def test_annotate_struct2(self):
+    def x_test_annotate_struct2(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_struct_id, [tagpoint])
         assert s.knowntype == tagpoint
         assert s.memorystate == SomeCTypesObject.OWNSMEMORY
 
-    def test_annotate_pointer_to_struct(self):
+    def x_test_annotate_pointer_to_struct(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_struct_pointer_id, [oppoint_type])
@@ -326,7 +326,7 @@
         assert s.memorystate == SomeCTypesObject.MEMORYALIAS
         return t
 
-    def test_create_point(self):
+    def x_test_create_point(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_create_point,[])
@@ -335,7 +335,7 @@
         if conftest.option.view:
             a.translator.view()
 
-    def test_annotate_byval(self):
+    def x_test_annotate_byval(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_byval,[tagpoint])
@@ -345,7 +345,7 @@
         assert s.items[1].knowntype == tagpoint
         assert s.items[1].memorystate == SomeCTypesObject.OWNSMEMORY 
 
-    def test_annotate_POINTER(self):
+    def x_test_annotate_POINTER(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_POINTER,[tagpoint])
@@ -356,7 +356,7 @@
         assert s.items[1].memorystate == SomeCTypesObject.OWNSMEMORY 
         #d#t.view()
 
-    def test_annotate_POINTER_dereference(self):
+    def x_test_annotate_POINTER_dereference(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_POINTER_dereference, [tagpoint])
@@ -369,7 +369,7 @@
         assert s.items[2].memorystate == SomeCTypesObject.OWNSMEMORY 
         #d#t.view()
     
-    def test_annotate_mixed_memorystate(self):
+    def x_test_annotate_mixed_memorystate(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_test_mixed_memory_state, [int])
@@ -409,7 +409,7 @@
         s = a.build_types(py_test_simple_ctypes_non_const,[])
         assert s.knowntype == c_float
 
-    def test_specialize_struct(self):
+    def x_test_specialize_struct(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_test_specialize_struct, [])
@@ -421,7 +421,7 @@
             if conftest.option.view:
                 t.view()
 
-    def test_specialize_struct_1(self):
+    def x_test_specialize_struct_1(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_test_compile_struct, [int, int]) 
@@ -432,7 +432,7 @@
             #d#t.view()
             pass
 
-    def test_specialize_pointer_to_struct(self):
+    def x_test_specialize_pointer_to_struct(self):
         t = self.test_annotate_pointer_to_struct()
         t.buildrtyper().specialize()
         if conftest.option.view:
@@ -441,12 +441,12 @@
     def x_test_compile_pointer_to_struct(self):
         fn = compile( py_testfunc_struct_pointer_id, [ oppoint_type ] )
 
-    def test_compile_struct(self):
+    def x_test_compile_struct(self):
         fn = compile( py_test_compile_struct, [ int, int ] )
         res = fn( 42, -42 )
         assert res == 42
 
-    def test_specialize_POINTER_dereference(self):
+    def x_test_specialize_POINTER_dereference(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_POINTER_dereference, [tagpoint])
@@ -457,7 +457,7 @@
             #d#t.view()
             pass
 
-    def test_specialize_pointer(self):
+    def x_test_specialize_pointer(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types( py_test_compile_pointer, [ int, int ] )
@@ -466,7 +466,7 @@
         t.buildrtyper().specialize()
         #d#t.view()
 
-    def test_compile_pointer(self):
+    def x_test_compile_pointer(self):
         fn = compile( py_test_compile_pointer, [ int, int ] )
         res = fn( -42, 42 )
         assert res == -42



More information about the Pypy-commit mailing list