[pypy-svn] r75484 - in pypy/branch/fast-ctypes/pypy: module/jitffi module/jitffi/test rlib

getxsick at codespeak.net getxsick at codespeak.net
Tue Jun 22 01:47:06 CEST 2010


Author: getxsick
Date: Tue Jun 22 01:47:04 2010
New Revision: 75484

Modified:
   pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
   pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
   pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
Log:
ok, module/jitffi seems to work now...for specific cases (e.g. only ints)
at least one test passes :-)
this check in is a bit messy as i have some problems to get it workable.
need to clean it up a bit and add other functionality


Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py	Tue Jun 22 01:47:04 2010
@@ -1,18 +1,66 @@
+from pypy.rlib import rdynload
+from pypy.jit.backend.x86.runner import CPU
 from pypy.rlib import rjitffi
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root, Wrappable
 from pypy.interpreter.error import wrap_oserror
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef
 
+class W_Lib(Wrappable):
+    def __init__(self, space, name):
+        try:
+            self.handler = rdynload.dlopen(name)
+        except rdynload.DLOpenError, e:
+            raise OSError('%s: %s', name, e.msg or 'unspecified error')
+
+        self.space = space
+
+def descr_new_lib(space, w_type, name):
+    try:
+        return space.wrap(W_Lib(space, name))
+    except OSError, e:
+        raise wrap_oserror(space, e)
+descr_new_lib.unwrap_spec = [ObjSpace, W_Root, str]
+
+W_Lib.typedef = TypeDef(
+        'Lib',
+        __new__ = interp2app(descr_new_lib)
+)
+
+class W_Get(Wrappable, rjitffi._Get):
+    def __init__(self, space, cpu, lib, func, args_type, res_type='void'):
+        self.space = space
+        rjitffi._Get.__init__(self, cpu, lib, func, args_type, res_type)
+
+    def call_w(self, w_args):
+        args_w = [ self.space.int_w(w_x) for w_x in self.space.listview(w_args) ] # XXX only int!
+        return self.space.wrap(self.call(args_w))
+
+
+def descr_new_get(space, w_type, cpu, lib, func, args_type, res_type):
+    try:
+        return space.wrap(W_Get(space, w_type, cpu, lib, func, args_type, res_type))
+    except OSError, e:
+        raise wrap_oserror(space, e)
+descr_new_get.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root, str, W_Root, str]
+
+W_Get.typedef = TypeDef(
+        'Get',
+        #__new__ = interp2app(descr_new_get)
+        call = interp2app(W_Get.call_w, unwrap_spec=['self', W_Root])
+)
+
 class W_CDLL(Wrappable, rjitffi.CDLL):
     def __init__(self, space, name):
         self.space = space
-        rjitffi.CDLL.__init__(self, name)
+        self.lib = space.wrap(W_Lib(self.space, name))
+        self.name = name
+        self.cpu = CPU(None, None)
 
     def get_w(self, func, w_args_type, res_type='void'):
         args_type_w = [ self.space.str_w(w_x)
                         for w_x in self.space.listview(w_args_type) ]
-        return self.space.wrap(self.get(func, args_type_w, res_type))
+        return self.space.wrap(W_Get(self.space, self.cpu, self.space.wrap(self.lib), func, args_type_w, res_type))
 
 def descr_new_cdll(space, w_type, name):
     try:

Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/test/test_jitffi.py	Tue Jun 22 01:47:04 2010
@@ -65,7 +65,7 @@
         lib = jitffi.CDLL(self.lib_name)
 
         func = lib.get('add_integers', ['int', 'int'], 'int')
-        assert 3 == func.call(1,2)
+        assert 3 == func.call([1,2])
         func = lib.get('add_integers', ['int', 'int'], 'int')
         assert 1 == func.call(-1,2)
         func = lib.get('add_integers', ['int', 'int'], 'int')

Modified: pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py	(original)
+++ pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py	Tue Jun 22 01:47:04 2010
@@ -25,7 +25,7 @@
         self.args_type = args_type
         self.res_type = res_type
         self.cpu = cpu
-        self.lib = lib
+        self.lib = lib.handler
 
         if self.res_type == 'int':
             self.bres = BoxInt()



More information about the Pypy-commit mailing list