Commits

Armin Rigo committed 779ba71

Fix passing 'char' and 'short' arguments to vararg functions

  • Participants
  • Parent commits a0252dc
  • Branches ffi-backend

Comments (0)

Files changed (4)

File pypy/module/_cffi_backend/ctypearray.py

     def iter(self, cdata):
         return W_CDataIter(self.space, self.ctitem, cdata)
 
+    def get_vararg_type(self):
+        return self.ctptr
+
 
 class W_CDataIter(Wrappable):
     _immutable_fields_ = ['ctitem', 'cdata', '_stop']    # but not '_next'

File pypy/module/_cffi_backend/ctypefunc.py

         for i in range(nargs_declared, len(args_w)):
             w_obj = args_w[i]
             if isinstance(w_obj, cdataobj.W_CData):
-                ct = w_obj.ctype
-                if isinstance(ct, ctypearray.W_CTypeArray):
-                    ct = ct.ctptr
+                ct = w_obj.ctype.get_vararg_type()
             else:
                 raise operationerrfmt(space.w_TypeError,
                              "argument %d passed in the variadic part "

File pypy/module/_cffi_backend/ctypeobj.py

                               "cdata '%s' does not support iteration",
                               self.name)
 
+    def get_vararg_type(self):
+        return self
+
 
 W_CType.typedef = TypeDef(
     'CTypeDescr',

File pypy/module/_cffi_backend/ctypeprim.py

     _attrs_ = []
     is_primitive_integer = True
 
+    def get_vararg_type(self):
+        from pypy.module._cffi_backend import newtype
+        return newtype.new_primitive_type(self.space, "int")
+
 
 class W_CTypePrimitiveChar(W_CTypePrimitiveCharOrUniChar):
     _attrs_ = []
         value = r_ulonglong(value)
         misc.write_raw_integer_data(cdata, value, self.size)
 
+    def get_vararg_type(self):
+        if self.size < rffi.sizeof(rffi.INT):
+            from pypy.module._cffi_backend import newtype
+            return newtype.new_primitive_type(self.space, "int")
+        return self
+
 
 class W_CTypePrimitiveUnsigned(W_CTypePrimitive):
     _attrs_            = ['value_fits_long', 'vrangemax']
         else:
             return self.space.wrap(value)    # r_ulonglong => 'long' object
 
+    def get_vararg_type(self):
+        if self.size < rffi.sizeof(rffi.INT):
+            from pypy.module._cffi_backend import newtype
+            return newtype.new_primitive_type(self.space, "int")
+        return self
+
 
 class W_CTypePrimitiveFloat(W_CTypePrimitive):
     _attrs_ = []