[pypy-svn] r47511 - pypy/dist/pypy/module/_ffi

fijal at codespeak.net fijal at codespeak.net
Wed Oct 17 13:16:11 CEST 2007


Author: fijal
Date: Wed Oct 17 13:16:09 2007
New Revision: 47511

Modified:
   pypy/dist/pypy/module/_ffi/interp_ffi.py
   pypy/dist/pypy/module/_ffi/structure.py
Log:
Name & args consistency


Modified: pypy/dist/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- pypy/dist/pypy/module/_ffi/interp_ffi.py	(original)
+++ pypy/dist/pypy/module/_ffi/interp_ffi.py	Wed Oct 17 13:16:09 2007
@@ -120,18 +120,18 @@
     push_func(add_arg, argdesc, ll_str)
     return ll_str
 
-def unwrap_arg(space, push_func, add_arg, argdesc, argtype, w_arg, to_free):
+def unwrap_value(space, push_func, add_arg, argdesc, tp, w_arg, to_free):
     w = space.wrap
     # XXX how to handle LONGLONG here?
     # they're probably long, so we'll not get them through int_w
-    if argtype == "d" or argtype == "f":
+    if tp == "d" or tp == "f":
         push_func(add_arg, argdesc, space.float_w(w_arg))
-    elif argtype == "s":
+    elif tp == "s":
         ll_str = rffi.str2charp(space.str_w(w_arg))
         if to_free is not None:
             to_free.append(ll_str)
         push_func(add_arg, argdesc, ll_str)
-    elif argtype == "P":
+    elif tp == "P":
         # check for NULL ptr
         if space.is_w(w_arg, space.w_None):
             push_func(add_arg, argdesc, lltype.nullptr(rffi.VOIDP.TO))
@@ -149,7 +149,7 @@
             else:
                 raise OperationError(space.w_TypeError, w(
                     "Expected structure, array or simple type"))
-    elif argtype == "c" or argtype == "b" or argtype == "B":
+    elif tp == "c" or tp == "b" or tp == "B":
         s = space.str_w(w_arg)
         if len(s) != 1:
             raise OperationError(space.w_ValueError, w(
@@ -157,40 +157,39 @@
         s = s[0]
         push_func(add_arg, argdesc, s)
     else:
-        #assert argtype  "iIhHlLqQ"
+        #assert tp  "iIhHlLqQ"
         push_func(add_arg, argdesc, space.int_w(w_arg))
-unwrap_arg._annspecialcase_ = 'specialize:arg(1)'
-# we should have also here specialize:argtype(5) :-/
+unwrap_value._annspecialcase_ = 'specialize:arg(1)'
 
 ll_typemap_iter = unrolling_iterable(LL_TYPEMAP.items())
 
-def wrap_result(space, restype, arg, argdesc, func):
+def wrap_value(space, func, add_arg, argdesc, tp):
     for c, ll_type in ll_typemap_iter:
-        if restype == c:
+        if tp == c:
             if c == 's':
-                ptr = func(arg, argdesc, rffi.CCHARP)
+                ptr = func(add_arg, argdesc, rffi.CCHARP)
                 if not ptr:
                     return space.w_None
                 return space.wrap(rffi.charp2str(ptr))
             elif c == 'P':
-                res = func(arg, argdesc, rffi.VOIDP)
+                res = func(add_arg, argdesc, rffi.VOIDP)
                 if not res:
                     return space.w_None
                 return space.wrap(rffi.cast(rffi.INT, res))
             #elif c == 'q' or c == 'Q' or c == 'L':
             #    return space.newlong(func(arg, ll_type))
             elif c == 'f' or c == 'd':
-                return space.wrap(float(func(arg, argdesc, ll_type)))
+                return space.wrap(float(func(add_arg, argdesc, ll_type)))
             elif c == 'c' or c == 'b' or c == 'B':
-                return space.wrap(chr(rffi.cast(rffi.INT, func(arg, argdesc,
+                return space.wrap(chr(rffi.cast(rffi.INT, func(add_arg, argdesc,
                                                                ll_type))))
             elif c == 'h' or c == 'H':
-                return space.wrap(rffi.cast(rffi.INT, func(arg, argdesc,
+                return space.wrap(rffi.cast(rffi.INT, func(add_arg, argdesc,
                                                            ll_type)))
             else:
-                return space.wrap(intmask(func(arg, argdesc, ll_type)))
+                return space.wrap(intmask(func(add_arg, argdesc, ll_type)))
     return space.w_None
-wrap_result._annspecialcase_ = 'specialize:arg(4)'
+wrap_value._annspecialcase_ = 'specialize:arg(1)'
 
 def ptr_call(ptr, some_arg, ll_type):
     return ptr.call(ll_type)
@@ -217,10 +216,10 @@
         for i in range(len(self.argtypes)):
             argtype = self.argtypes[i]
             w_arg = args_w[i]
-            unwrap_arg(space, push, self.ptr, i, argtype, w_arg, to_free)
+            unwrap_value(space, push, self.ptr, i, argtype, w_arg, to_free)
             i += 1
         try:
-            return wrap_result(space, self.restype, self.ptr, None, ptr_call)
+            return wrap_value(space, ptr_call, self.ptr, None, self.restype)
         finally:
             for elem in to_free:
                 lltype.free(elem, flavor='raw')

Modified: pypy/dist/pypy/module/_ffi/structure.py
==============================================================================
--- pypy/dist/pypy/module/_ffi/structure.py	(original)
+++ pypy/dist/pypy/module/_ffi/structure.py	Wed Oct 17 13:16:09 2007
@@ -13,7 +13,7 @@
 # the other one is in rlib/libffi, we should refactor it to reuse the same
 # logic, I'll not touch it by now, and refactor it later
 from pypy.module.struct.nativefmttable import native_fmttable as struct_native_fmttable
-from pypy.module._ffi.interp_ffi import wrap_result, unwrap_arg
+from pypy.module._ffi.interp_ffi import wrap_value, unwrap_value
 
 native_fmttable = {}
 for key, value in struct_native_fmttable.items():
@@ -81,7 +81,7 @@
         for i in range(len(self.fields)):
             name, c = self.fields[i]
             if name == attr:
-                return wrap_result(space, c, self, i, cast_pos)
+                return wrap_value(space, cast_pos, self, i, c)
         raise OperationError(space.w_AttributeError, space.wrap(
             "C Structure has no attribute %s" % attr))
     getattr.unwrap_spec = ['self', ObjSpace, str]
@@ -90,7 +90,7 @@
         for i in range(len(self.fields)):
             name, c = self.fields[i]
             if name == attr:
-                unwrap_arg(space, push_field, self, i, c, w_value, None)
+                unwrap_value(space, push_field, self, i, c, w_value, None)
                 return
     setattr.unwrap_spec = ['self', ObjSpace, str, W_Root]
 



More information about the Pypy-commit mailing list