Commits

Armin Rigo committed 51fdf5d

Update to cffi/dd928004c3bf (release-0.4).

  • Participants
  • Parent commits b4e4017

Comments (0)

Files changed (3)

File pypy/interpreter/error.py

         return w_type
 
     def write_unraisable(self, space, where, w_object=None,
-                         with_traceback=False):
+                         with_traceback=False, extra_line=''):
         if w_object is None:
             objrepr = ''
         else:
                 w_tb = space.wrap(self.get_traceback())
                 space.appexec([space.wrap(where),
                                space.wrap(objrepr),
+                               space.wrap(extra_line),
                                w_t, w_v, w_tb],
-                """(where, objrepr, t, v, tb):
+                """(where, objrepr, extra_line, t, v, tb):
                     import sys, traceback
                     sys.stderr.write('From %s%s:\\n' % (where, objrepr))
+                    if extra_line:
+                        sys.stderr.write(extra_line)
                     traceback.print_exception(t, v, tb)
                 """)
             else:

File pypy/module/_cffi_backend/ccallback.py

                                  space.wrap("expected a function ctype"))
         return ctype
 
-    def invoke(self, ll_args, ll_res):
+    def invoke(self, ll_args):
         space = self.space
         ctype = self.getfunctype()
         args_w = []
         for i, farg in enumerate(ctype.fargs):
             ll_arg = rffi.cast(rffi.CCHARP, ll_args[i])
             args_w.append(farg.convert_to_object(ll_arg))
-        fresult = ctype.ctitem
-        #
-        w_res = space.call(self.w_callable, space.newtuple(args_w))
-        #
+        return space.call(self.w_callable, space.newtuple(args_w))
+
+    def convert_result(self, ll_res, w_res):
+        fresult = self.getfunctype().ctitem
         convert_from_object_fficallback(fresult, ll_res, w_res)
 
-    def print_error(self, operr):
+    def print_error(self, operr, extra_line):
         space = self.space
         operr.write_unraisable(space, "callback ", self.w_callable,
-                               with_traceback=True)
+                               with_traceback=True, extra_line=extra_line)
 
     def write_error_return_value(self, ll_res):
         fresult = self.getfunctype().ctitem
     try:
         ec = cerrno.get_errno_container(callback.space)
         cerrno.save_errno_into(ec, e)
+        extra_line = ''
         try:
-            callback.invoke(ll_args, ll_res)
+            w_res = callback.invoke(ll_args)
+            extra_line = "Trying to convert the result back to C:\n"
+            callback.convert_result(ll_res, w_res)
         except OperationError, e:
             # got an app-level exception
-            callback.print_error(e)
+            callback.print_error(e, extra_line)
             callback.write_error_return_value(ll_res)
         #
     except Exception, e:

File pypy/module/_cffi_backend/test/_backend_test_c.py

     complete_struct_or_union(BStruct, [('a', BArray10, -1)])
     BFunc22 = new_function_type((BStruct, BStruct), BStruct, False)
     f = cast(BFunc22, _testfunc(22))
-    p1 = newp(BStructP, {'a': range(100, 110)})
-    p2 = newp(BStructP, {'a': range(1000, 1100, 10)})
+    p1 = newp(BStructP, {'a': list(range(100, 110))})
+    p2 = newp(BStructP, {'a': list(range(1000, 1100, 10))})
     res = f(p1[0], p2[0])
     for i in range(10):
         assert res.a[i] == p1.a[i] - p2.a[i]
     assert str(e.value) == "'int(*)(int)' expects 1 arguments, got 0"
 
 def test_callback_exception():
-    import cStringIO, linecache
-    def matches(str, pattern):
+    try:
+        import cStringIO
+    except ImportError:
+        import io as cStringIO    # Python 3
+    import linecache
+    def matches(istr, ipattern):
+        str, pattern = istr, ipattern
         while '$' in pattern:
             i = pattern.index('$')
             assert str[:i] == pattern[:i]
     def check_value(x):
         if x == 10000:
             raise ValueError(42)
-    def cb1(x):
+    def Zcb1(x):
         check_value(x)
         return x * 3
     BShort = new_primitive_type("short")
     BFunc = new_function_type((BShort,), BShort, False)
-    f = callback(BFunc, cb1, -42)
+    f = callback(BFunc, Zcb1, -42)
     orig_stderr = sys.stderr
     orig_getline = linecache.getline
     try:
         assert sys.stderr.getvalue() == ''
         assert f(10000) == -42
         assert matches(sys.stderr.getvalue(), """\
-From callback <function cb1 at 0x$>:
+From callback <function$Zcb1 at 0x$>:
 Traceback (most recent call last):
-  File "$", line $, in cb1
+  File "$", line $, in Zcb1
     $
   File "$", line $, in check_value
     $
         bigvalue = 20000
         assert f(bigvalue) == -42
         assert matches(sys.stderr.getvalue(), """\
-From callback <function cb1 at 0x$>:
+From callback <function$Zcb1 at 0x$>:
+Trying to convert the result back to C:
 OverflowError: integer 60000 does not fit 'short'
 """)
     finally: