Commits

Amaury Forgeot d'Arc  committed 115ed6c

Fix rffi callback tests:
- arithmetic works only on lltype.Signed type
- llptr callbacks must precisely cast their return type

  • Participants
  • Parent commits 8cc22ca
  • Branches real-rffi.INT

Comments (0)

Files changed (2)

File pypy/rpython/lltypesystem/rffi.py

     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__', '?')

File pypy/rpython/lltypesystem/test/test_rffi.py

     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)
             return i
 
         def two(i):
-            return i + 2
+            return cast(lltype.Signed, i) + 2
         
         def f(i):
             if i > 3:
         eating_callback = self.eating_callback()
 
         def raising(i):
-            if i > 3:
+            if cast(lltype.Signed, i) > 3:
                 raise ValueError
             else:
                 return 3
     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))
 
     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