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

stephan at codespeak.net stephan at codespeak.net
Mon Jan 23 16:35:54 CET 2006


Author: stephan
Date: Mon Jan 23 16:35:52 2006
New Revision: 22532

Modified:
   pypy/dist/pypy/rpython/rctypes/interface.py
   pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
extended the rctype test to something usable on Linux and Windows

Modified: pypy/dist/pypy/rpython/rctypes/interface.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/interface.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/interface.py	Mon Jan 23 16:35:52 2006
@@ -1,3 +1,47 @@
 from ctypes import *
 
+"""
+Loading
+-------
 
+windll.LoadLibrary(<somepath>) (<- Windows calling conventions)
+cdll.LoadLibrary(<somepath>) (<- Unix calling conventions)
+
+Types
+-----
+
+c_char
+c_byte
+c_ubyte
+c_short
+c_ushort
+c_int
+c_uint
+c_long
+c_ulong
+c_longlong
+c_ulonglong
+c_float
+c_double
+c_char_p
+c_wchar_p
+c_void_p
+
+Function Interface
+------------------
+
+somefunc.restype = c_char
+somefunc.argtypes = [c_char,c_int]
+
+Structure
+---------
+
+class POINT(Structure):
+    _fields_ = [("x", c_int),
+                ("y", c_int)]
+
+Arrays
+------
+
+TenPointsArray = POINT * 10
+"""

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	Mon Jan 23 16:35:52 2006
@@ -8,15 +8,22 @@
 
 class Test_rctypes:
     def test_simple(self):
-        from pypy.rpython.rctypes.interface import windll, c_char_p
+        from pypy.rpython.rctypes.interface import cdll, c_char_p, c_int
 
         import sys
         if sys.platform == 'win32':
-            py.test.raises(WindowsError,"windll.LoadLibrary('kernel42.dll')")
-            mylib = windll.LoadLibrary('kernel32.dll')
-            gcl = mylib.GetCommandLineA
-            gcl.restype = c_char_p
-            def tst():
-               return gcl()
-            res = tst()   
-            assert isinstance(res, str)
+            mylib = cdll.LoadLibrary('msvcrt.dll')
+        elif sys.platform == 'linux2':
+            mylib = cdll.LoadLibrary('libc')
+        else:
+            py.test.skip("don't know how to load the c lib for %s" % 
+                          sys.platform)
+
+        atoi = mylib.atoi
+        atoi.restype = c_int
+        atoi.argstype = [c_char_p]
+        def o_atoi(a):
+           return atoi(a)
+
+        res = o_atoi('42')   
+        assert res == 42 



More information about the Pypy-commit mailing list