Author: Armin Rigo <[email protected]>
Branch:
Changeset: r59022:51fdf5d0ffd5
Date: 2012-11-21 01:19 +0100
http://bitbucket.org/pypy/pypy/changeset/51fdf5d0ffd5/
Log: Update to cffi/dd928004c3bf (release-0.4).
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -224,7 +224,7 @@
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:
@@ -240,10 +240,13 @@
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:
diff --git a/pypy/module/_cffi_backend/ccallback.py
b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -77,23 +77,23 @@
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
@@ -179,11 +179,14 @@
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:
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -982,8 +982,8 @@
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]
@@ -1096,8 +1096,13 @@
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]
@@ -1110,12 +1115,12 @@
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:
@@ -1125,9 +1130,9 @@
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
$
@@ -1137,7 +1142,8 @@
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:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit