[pypy-svn] r72469 - pypy/branch/rawffi-64/pypy/module/_rawffi

arigo at codespeak.net arigo at codespeak.net
Sat Mar 20 19:39:29 CET 2010


Author: arigo
Date: Sat Mar 20 19:39:27 2010
New Revision: 72469

Modified:
   pypy/branch/rawffi-64/pypy/module/_rawffi/callback.py
   pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py
Log:
Start to pass the tests about callback.


Modified: pypy/branch/rawffi-64/pypy/module/_rawffi/callback.py
==============================================================================
--- pypy/branch/rawffi-64/pypy/module/_rawffi/callback.py	(original)
+++ pypy/branch/rawffi-64/pypy/module/_rawffi/callback.py	Sat Mar 20 19:39:27 2010
@@ -6,8 +6,9 @@
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.module._rawffi.structure import unpack_fields
 from pypy.module._rawffi.array import get_elem, push_elem
-from pypy.module._rawffi.interp_rawffi import W_DataInstance, _get_type_,\
-     wrap_value, unwrap_value, unwrap_truncate_int, letter2tp
+from pypy.module._rawffi.interp_rawffi import W_DataInstance, \
+     wrap_value, unwrap_value, unwrap_truncate_int, \
+     unpack_argshapes, unpack_resshape
 from pypy.rlib.libffi import USERDATA_P, CallbackFuncPtr, FUNCFLAG_CDECL
 from pypy.module._rawffi.tracker import tracker
 from pypy.interpreter.error import OperationError
@@ -26,21 +27,23 @@
     userdata = rffi.cast(USERDATA_P, ll_userdata)
     callback_ptr = global_counter.CallbackPtr_by_number[userdata.addarg]
     w_callable = callback_ptr.w_callable
-    argtypes = callback_ptr.args
+    argshapes = callback_ptr.argshapes
     space = callback_ptr.space
     try:
+        # XXX The app-level callback gets the arguments as a list of integers.
+        #     Irregular interface here.  Shows something, I say.
         w_args = space.newlist([space.wrap(rffi.cast(rffi.ULONG, ll_args[i]))
-                                for i in range(len(argtypes))])
+                                for i in range(len(argshapes))])
         w_res = space.call(w_callable, w_args)
-        if callback_ptr.result != 'O': # don't return void
+        if callback_ptr.resshape is not None: # don't return void
             unwrap_value(space, push_elem, ll_res, 0,
-                         callback_ptr.result, w_res)
+                         callback_ptr.resshape.itemcode, w_res)
     except OperationError, e:
         tbprint(space, space.wrap(e.application_traceback),
                 space.wrap(e.errorstr(space)))
         # force the result to be zero
-        if callback_ptr.result != 'O':
-            _, size, _ = letter2tp(space, callback_ptr.result)
+        if callback_ptr.resshape is not None:
+            size = callback_ptr.resshape.size
             for i in range(size):
                 ll_res[i] = '\x00'
 
@@ -58,18 +61,20 @@
     
     def __init__(self, space, w_callable, w_args, w_result,
                  flags=FUNCFLAG_CDECL):
+        self.space = space
+        self.w_callable = w_callable
+        self.argshapes = unpack_argshapes(space, w_args)
+        self.resshape = unpack_resshape(space, w_result)
+        ffiargs = [shape.get_ffi_type() for shape in self.argshapes]
+        if self.resshape is not None:
+            ffiresult = self.resshape.get_ffi_type()
+        else:
+            ffiresult = ffi_type_void
+        # necessary to keep stuff alive
         number = global_counter.CallbackPtr_id
         global_counter.CallbackPtr_id += 1
         global_counter.CallbackPtr_by_number[number] = self
-        self.space = space
-        self.w_callable = w_callable
         self.number = number
-        self.args = [space.str_w(w_arg) for w_arg in space.unpackiterable(
-            w_args)]
-        self.result = space.str_w(w_result)
-        ffiargs = [_get_type_(space, arg) for arg in self.args]
-        ffiresult = _get_type_(space, self.result)
-        # necessary to keep stuff alive
         self.ll_callback = CallbackFuncPtr(ffiargs, ffiresult,
                                            callback, number, flags)
         self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)

Modified: pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py
==============================================================================
--- pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py	(original)
+++ pypy/branch/rawffi-64/pypy/module/_rawffi/structure.py	Sat Mar 20 19:39:27 2010
@@ -103,6 +103,8 @@
     descr_fieldoffset.unwrap_spec = ['self', ObjSpace, str]
 
     # get the corresponding ffi_type
+    ffi_type = lltype.nullptr(libffi.FFI_TYPE_P.TO)
+
     def get_ffi_type(self):
         if not self.ffi_type:
             self.ffi_type = libffi.make_struct_ffitype(self.size,



More information about the Pypy-commit mailing list