[pypy-svn] pypy real-rffi.INT: Fix rffi callback tests:
amauryfa
commits-noreply at bitbucket.org
Wed Mar 2 20:23:06 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: real-rffi.INT
Changeset: r42390:115ed6c4bee8
Date: 2011-03-02 15:08 +0100
http://bitbucket.org/pypy/pypy/changeset/115ed6c4bee8/
Log: Fix rffi callback tests:
- arithmetic works only on lltype.Signed type
- llptr callbacks must precisely cast their return type
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -243,7 +243,7 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lloperation import llop
if hasattr(callable, '_errorcode_'):
- errorcode = callable._errorcode_
+ errorcode = cast(TP.TO.RESULT, callable._errorcode_)
else:
errorcode = TP.TO.RESULT._example()
callable_name = getattr(callable, '__name__', '?')
diff --git a/pypy/rpython/lltypesystem/test/test_rffi.py b/pypy/rpython/lltypesystem/test/test_rffi.py
--- a/pypy/rpython/lltypesystem/test/test_rffi.py
+++ b/pypy/rpython/lltypesystem/test/test_rffi.py
@@ -407,7 +407,7 @@
def test_c_callback(self):
eating_callback = self.eating_callback()
def g(i):
- return i + 3
+ return cast(lltype.Signed, i) + 3
def f():
return eating_callback(3, g)
@@ -423,7 +423,7 @@
return i
def two(i):
- return i + 2
+ return cast(lltype.Signed, i) + 2
def f(i):
if i > 3:
@@ -441,7 +441,7 @@
eating_callback = self.eating_callback()
def raising(i):
- if i > 3:
+ if cast(lltype.Signed, i) > 3:
raise ValueError
else:
return 3
@@ -456,8 +456,8 @@
def test_callback_already_llptr(self):
eating_callback = self.eating_callback()
def g(i):
- return i + 3
- G = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
+ return cast(LONG, cast(lltype.Signed, i) + 3)
+ G = lltype.Ptr(lltype.FuncType([LONG], LONG))
def f():
return eating_callback(3, llhelper(G, g))
@@ -467,9 +467,9 @@
def test_pass_opaque_pointer_via_callback(self):
eating_callback = self.eating_callback()
- TP = lltype.Ptr(lltype.GcStruct('X', ('x', lltype.Signed)))
+ TP = lltype.Ptr(lltype.GcStruct('X', ('x', LONG)))
struct = lltype.malloc(TP.TO) # gc structure
- struct.x = 8
+ struct.x = cast(LONG, 8)
def g(i):
return get_keepalive_object(i, TP).x
More information about the Pypy-commit
mailing list