[pypy-commit] pypy ffi-backend: Fix passing 'char' and 'short' arguments to vararg functions

arigo noreply at buildbot.pypy.org
Wed Aug 1 14:25:56 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56519:779ba71f0f0c
Date: 2012-08-01 14:25 +0200
http://bitbucket.org/pypy/pypy/changeset/779ba71f0f0c/

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

diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -103,6 +103,9 @@
     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'
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -50,9 +50,7 @@
         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 "
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -153,6 +153,9 @@
                               "cdata '%s' does not support iteration",
                               self.name)
 
+    def get_vararg_type(self):
+        return self
+
 
 W_CType.typedef = TypeDef(
     'CTypeDescr',
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -75,6 +75,10 @@
     _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_ = []
@@ -179,6 +183,12 @@
         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']
@@ -209,6 +219,12 @@
         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_ = []


More information about the pypy-commit mailing list