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

gromit at codespeak.net gromit at codespeak.net
Tue Jan 24 19:22:55 CET 2006


Author: gromit
Date: Tue Jan 24 19:22:53 2006
New Revision: 22619

Modified:
   pypy/dist/pypy/rpython/rctypes/interface.py
   pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
ADD: (stephan, gromit) Exposing ctypes structures and a c test module.

Modified: pypy/dist/pypy/rpython/rctypes/interface.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/interface.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/interface.py	Tue Jan 24 19:22:53 2006
@@ -1,5 +1,5 @@
 from ctypes import _DLLS
-from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, POINTER
+from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, POINTER, Structure, byref
 try:
     from implementation import RWinDLL as WinDLL
 except ImportError:

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	Tue Jan 24 19:22:53 2006
@@ -2,6 +2,8 @@
 from pypy.annotation.annrpython import RPythonAnnotator
 from pypy.translator.translator import TranslationContext
 from pypy.translator.c.test.test_genc import compile
+from pypy.translator.tool.cbuild import compile_c_module
+import sys
     
 
 def setup_module(mod):
@@ -10,8 +12,7 @@
     except ImportError:
         py.test.skip("this test needs ctypes installed")
     else:
-        import sys
-        from pypy.rpython.rctypes.interface import cdll, c_char_p, c_int, c_char, POINTER
+        from pypy.rpython.rctypes.interface import cdll, c_char_p, c_int, c_char, POINTER, Structure, byref
         if sys.platform == 'win32':
             mylib = cdll.LoadLibrary('msvcrt.dll')
         elif sys.platform == 'linux2':
@@ -27,13 +28,17 @@
         def o_atoi(a):
            return atoi(a)
         mod.o_atoi = o_atoi
+        mod.cdll = cdll
+        class tagpoint(Structure):
+            _fields_ = [("x", c_int),
+                        ("y", c_int)]
+        mod.tagpoint = tagpoint
+        mod.byref = byref
 
 
 class Test_rctypes:
 
     def test_simple(self):
-
-
         res = o_atoi('42')   
         assert res == 42 
 
@@ -57,3 +62,29 @@
         res = fn("42")
         assert res == 42
 
+
+class Test_structure:
+
+    def setup_class(cls):
+        compile_c_module( [ py.path.local( "_rctypes_test.c" ) ], "_rctypes_test" )
+
+    def test_simple_as_extension_module(self):
+        import _rctypes_test as t0
+        import _rctypes_test as t1
+        assert t1 is t0
+        assert "_rctypes_test" in sys.modules
+
+    def test_simple(self):
+        if sys.platform == "win32":
+            dll = cdll.LoadLibrary( "_rctypes_test.pyd" )
+        else:
+            dll = cdll.LoadLibrary( "_rctypes_test.so" )
+        in_point = tagpoint()
+        in_point.x = 42
+        in_point.y = 17
+        out_point = tagpoint()
+        assert in_point.x + in_point.y == dll._testfunc_byval( in_point, byref( out_point ) )
+        assert out_point.x == 42
+        assert out_point.y == 17
+
+



More information about the Pypy-commit mailing list