Author: Armin Rigo <[email protected]>
Branch: verifier2
Changeset: r727:adf3dfc90288
Date: 2012-07-27 18:27 +0200
http://bitbucket.org/cffi/cffi/changeset/adf3dfc90288/
Log: Fix the last failure in test_verify.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1729,8 +1729,18 @@
}
#endif
}
- if (convert_from_object(data, argtype, obj) < 0)
+ if (convert_from_object(data, argtype, obj) < 0) {
+ if (CData_Check(obj) && argtype->ct_flags & CT_POINTER &&
+ argtype->ct_itemdescr == ((CDataObject *)obj)->c_type) {
+ /* special case to make the life of verifier.py easier:
+ if the formal argument type is 'struct foo *' but
+ we pass a 'struct foo', then get a pointer to it */
+ PyErr_Clear();
+ ((char **)data)[0] = ((CDataObject *)obj)->c_data;
+ continue;
+ }
goto error;
+ }
}
resultdata = buffer + cif_descr->exchange_offset_arg[0];
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -199,8 +199,14 @@
return
prnt = self._prnt
numargs = len(tp.args)
- arglist = [type.get_c_name(' x%d' % i)
- for i, type in enumerate(tp.args)]
+ argnames = []
+ for i, type in enumerate(tp.args):
+ indirection = ''
+ if isinstance(type, model.StructOrUnion):
+ indirection = '*'
+ argnames.append('%sx%d' % (indirection, i))
+ arglist = [type.get_c_name(' %s' % arg)
+ for type, arg in zip(tp.args, argnames)]
arglist = ', '.join(arglist) or 'void'
funcdecl = ' _cffi_f_%s(%s)' % (name, arglist)
prnt(tp.result.get_c_name(funcdecl))
@@ -210,18 +216,25 @@
result_code = 'return '
else:
result_code = ''
- prnt(' %s%s(%s);' % (
- result_code, name,
- ', '.join(['x%d' % i for i in range(len(tp.args))])))
+ prnt(' %s%s(%s);' % (result_code, name, ', '.join(argnames)))
prnt('}')
prnt()
_loading_cpy_function = _loaded_noop
def _loaded_cpy_function(self, tp, name, module, library):
+ assert isinstance(tp, model.FunctionPtrType)
if tp.ellipsis:
newfunction = self._load_constant(False, tp, name, module)
else:
+ if any(isinstance(type, model.StructOrUnion) for type in tp.args):
+ indirect_args = []
+ for i, type in enumerate(tp.args):
+ if isinstance(type, model.StructOrUnion):
+ type = model.PointerType(type)
+ indirect_args.append(type)
+ tp = model.FunctionPtrType(tuple(indirect_args),
+ tp.result, tp.ellipsis)
BFunc = self.ffi._get_cached_btype(tp)
wrappername = '_cffi_f_%s' % name
newfunction = module.load_function(BFunc, wrappername)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit