[pypy-svn] r55860 - in pypy/branch/faster-ctypes/pypy/module/_ctypes: . test
fijal at codespeak.net
fijal at codespeak.net
Sun Jun 15 22:01:44 CEST 2008
Author: fijal
Date: Sun Jun 15 22:01:36 2008
New Revision: 55860
Added:
pypy/branch/faster-ctypes/pypy/module/_ctypes/app_stubs.py (contents, props changed)
Modified:
pypy/branch/faster-ctypes/pypy/module/_ctypes/__init__.py
pypy/branch/faster-ctypes/pypy/module/_ctypes/interp_func.py
pypy/branch/faster-ctypes/pypy/module/_ctypes/test/support.py
pypy/branch/faster-ctypes/pypy/module/_ctypes/test/test_basic.py
Log:
Add some support for setting restype
Modified: pypy/branch/faster-ctypes/pypy/module/_ctypes/__init__.py
==============================================================================
--- pypy/branch/faster-ctypes/pypy/module/_ctypes/__init__.py (original)
+++ pypy/branch/faster-ctypes/pypy/module/_ctypes/__init__.py Sun Jun 15 22:01:36 2008
@@ -5,8 +5,9 @@
applevelname = '_ctypes'
interpleveldefs = {
- 'CDLL' : 'interp_lib.W_CDLL',
+ 'dlopen' : 'interp_lib.W_CDLL',
}
appleveldefs = {
+ '_SimpleCData' : 'app_stubs._SimpleCData',
}
Added: pypy/branch/faster-ctypes/pypy/module/_ctypes/app_stubs.py
==============================================================================
--- (empty file)
+++ pypy/branch/faster-ctypes/pypy/module/_ctypes/app_stubs.py Sun Jun 15 22:01:36 2008
@@ -0,0 +1,3 @@
+
+class _SimpleCData(object):
+ pass
Modified: pypy/branch/faster-ctypes/pypy/module/_ctypes/interp_func.py
==============================================================================
--- pypy/branch/faster-ctypes/pypy/module/_ctypes/interp_func.py (original)
+++ pypy/branch/faster-ctypes/pypy/module/_ctypes/interp_func.py Sun Jun 15 22:01:36 2008
@@ -13,12 +13,14 @@
self.lib = lib
self.name = name
# we create initial handle with no args, returning int
- self.handle = self._gethandle([], 'i')
+ self.restype = 'i'
+ self.argtypes = []
+ self._regen_handle()
- def _gethandle(self, args, res):
- args = [TYPEMAP[i] for i in args]
- res = TYPEMAP[res]
- return self.lib.getpointer(self.name, args, res)
+ def _regen_handle(self):
+ args = [TYPEMAP[i] for i in self.argtypes]
+ res = TYPEMAP[self.restype]
+ self.handle = self.lib.getpointer(self.name, args, res)
def call(self, space, args):
""" Calling routine - note that we cache handle to ll
@@ -28,7 +30,28 @@
return space.wrap(self.handle.call(lltype.Signed))
call.unwrap_spec = ['self', ObjSpace, Arguments]
+ def getargtypes(space, self):
+ xxx
+
+ def setargtypes(space, self, w_value):
+ xxx
+
+ def getrestype(space, self):
+ return self.w_restype
+
+ def setrestype(space, self, w_value):
+ # XXX isinstance check here
+ restype = space.str_w(space.getattr(w_value, space.wrap('_type_')))
+ if len(restype) != 1 or restype[0] not in TYPEMAP:
+ raise OperationError(space.w_TypeError, space.wrap(
+ "Unknown type %d" % restype))
+ self.w_restype = w_value
+ self.restype = restype[0]
+ self._regen_handle()
+
W_FuncPtr.typedef = TypeDef(
'_FuncPtr',
__call__ = interp2app(W_FuncPtr.call),
+ restype = GetSetProperty(W_FuncPtr.getrestype, W_FuncPtr.setrestype),
+ argtypes = GetSetProperty(W_FuncPtr.getargtypes, W_FuncPtr.setargtypes),
)
Modified: pypy/branch/faster-ctypes/pypy/module/_ctypes/test/support.py
==============================================================================
--- pypy/branch/faster-ctypes/pypy/module/_ctypes/test/support.py (original)
+++ pypy/branch/faster-ctypes/pypy/module/_ctypes/test/support.py Sun Jun 15 22:01:36 2008
@@ -40,4 +40,7 @@
space = gettestobjspace(usemodules=('_ctypes', 'struct'))
cls.space = space
cls.w_so_file = space.wrap(str(compile_so_file()))
-
+ cls.w_dll = space.appexec([cls.w_so_file], """(so_file):
+ from _ctypes import dlopen
+ return dlopen(so_file)
+ """)
Modified: pypy/branch/faster-ctypes/pypy/module/_ctypes/test/test_basic.py
==============================================================================
--- pypy/branch/faster-ctypes/pypy/module/_ctypes/test/test_basic.py (original)
+++ pypy/branch/faster-ctypes/pypy/module/_ctypes/test/test_basic.py Sun Jun 15 22:01:36 2008
@@ -3,7 +3,13 @@
class AppTestBasic(BasicAppTest):
def test_int_base(self):
- from _ctypes import CDLL
- dll = CDLL(self.so_file)
- assert dll.get_an_integer() == 42
+ assert self.dll.get_an_integer() == 42
+ def test_restype(self):
+ from _ctypes import _SimpleCData
+ class c_int(_SimpleCData):
+ _type_ = 'i'
+
+ f = self.dll.get_an_integer
+ f.restype = c_int
+ assert f() == 42
More information about the Pypy-commit
mailing list