[pypy-commit] creflect default: Transform function argument types as C does
arigo
noreply at buildbot.pypy.org
Fri Nov 28 17:25:19 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r101:23d40e0eea11
Date: 2014-11-28 17:25 +0100
http://bitbucket.org/cffi/creflect/changeset/23d40e0eea11/
Log: Transform function argument types as C does
diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -249,8 +249,10 @@
return model.FunctionType(tuple(args), result, ellipsis)
def _as_func_arg(self, type):
- if isinstance(type, (model.ArrayType, model.FunctionType)):
- return model.PointerType(type.item)
+ if isinstance(type, model.ArrayType):
+ return model.PointerType(type.item, const=False)
+ elif isinstance(type, model.FunctionType):
+ return model.PointerType(type, const=False)
else:
return type
diff --git a/test/codegen/func-005.c b/test/codegen/func-005.c
new file mode 100644
--- /dev/null
+++ b/test/codegen/func-005.c
@@ -0,0 +1,41 @@
+void f(int[], long(char, short));
+
+# ____________________________________________________________
+
+void f(int a[], long g(char, short)) { }
+
+# ____________________________________________________________
+
+static void testfunc_005__c_f(void *args[], void *result) {
+ f(*(int **)args[0], *(long (**)(char, short))args[1]);
+}
+
+static void testfunc_005__d_f(int *a0, long (*a1)(char, short)) {
+ f(a0, a1);
+}
+
+static void testfunc_005__f4(void *func, void *args[], void *result) {
+ long (*f)(char, short) = func;
+ *(long *)result = f(*(char *)args[0], *(short *)args[1]);
+}
+
+void testfunc_005(crx_builder_t *cb)
+{
+ crx_type_t *t1, *t2, *t3, *t4, *t5, *t6, *a7[2], *t8, *t9, *a10[2];
+ {
+ t1 = cb->get_void_type(cb);
+ t2 = cb->get_signed_type(cb, sizeof(int), "int");
+ t3 = cb->get_pointer_type(cb, t2);
+ t4 = cb->get_signed_type(cb, sizeof(long), "long");
+ t5 = cb->get_char_type(cb);
+ t6 = cb->get_signed_type(cb, sizeof(short), "short");
+ a7[0] = t5;
+ a7[1] = t6;
+ t8 = cb->get_function_type(cb, t4, a7, 2, &testfunc_005__f4);
+ t9 = cb->get_pointer_type(cb, t8);
+ a10[0] = t3;
+ a10[1] = t9;
+ cb->define_func(cb, "f", t1, a10, 2, &testfunc_005__c_f, &testfunc_005__d_f);
+#expect FUNC f: PTR int -> PTR FUNC( char -> short -> long ) -> void
+ }
+}
More information about the pypy-commit
mailing list