[pypy-svn] pypy jitypes2: small refactoring: now _wrap_result is called from within _build_result, only

antocuni commits-noreply at bitbucket.org
Thu Dec 30 14:12:59 CET 2010


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40277:6af28bf646a8
Date: 2010-12-28 10:40 +0100
http://bitbucket.org/pypy/pypy/changeset/6af28bf646a8/

Log:	small refactoring: now _wrap_result is called from within
	_build_result, only in the particular case where it makes sense.
	This lets more tests to pass, e.g. test_cfuncs.test_callwithresult

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -199,7 +199,7 @@
         restype = self._restype_
         funcptr = self._getfuncptr(argtypes, restype, thisarg)
         result = funcptr(*newargs)
-        result = self._wrap_result(restype, result)
+        result = self._build_result(restype, result, argtypes, newargs)
         #
         ## resbuffer = funcptr(*[arg._get_buffer_for_param()._buffer
         ##                       for arg in args])
@@ -445,12 +445,22 @@
             result = restype.from_address(result)
         return result
 
-    def _build_result(self, restype, resbuffer, argtypes, argsandobjs):
+    def _build_result(self, restype, result, argtypes, argsandobjs):
         """Build the function result:
            If there is no OUT parameter, return the actual function result
            If there is one OUT parameter, return it
            If there are many OUT parameters, return a tuple"""
 
+        # XXX: note for the future: the function used to take a "resbuffer",
+        # i.e. an array of ints. Now it takes a result, which is already a
+        # python object. All places that do "resbuffer[0]" should check that
+        # result is actually an int and just use it.
+        #
+        # Also, argsandobjs used to be "args" in __call__, now it's "newargs"
+        # (i.e., the already unwrapped objects). It's used only when we have a
+        # PARAMFLAG_FOUT and it's probably wrong, I'll fix it when I find a
+        # failing test
+
         retval = None
 
         if self._com_index:
@@ -469,9 +479,9 @@
                     val = val.value
                 retval = checker(val)
             elif not isinstance(restype, _CDataMeta):
-                retval = restype(resbuffer[0])
+                retval = restype(result)
             else:
-                retval = restype._CData_retval(resbuffer)
+                retval = self._wrap_result(restype, result)
 
         results = []
         if self._paramflags:


More information about the Pypy-commit mailing list