summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Barnard <eabarnard@gmail.com>2015-01-01 13:48:28 +0000
committerEdward Barnard <eabarnard@gmail.com>2015-01-01 13:48:28 +0000
commit69b39ce4243a8da3ddf9bf4ca73d34ffe127b6c0 (patch)
treee646f079117da769aee3a5ea8c58b48b4255e8c3
parentfc0a9ab26a32344308d92407ec28ef43d155dc85 (diff)
Arrays of type in function arguments now generate pointers to type as per the C90 standard. Closes #97.
-rw-r--r--src/gen.rs10
-rw-r--r--tests/headers/func_with_array_arg.h1
-rw-r--r--tests/test_func.rs11
3 files changed, 21 insertions, 1 deletions
diff --git a/src/gen.rs b/src/gen.rs
index 0b2c7f5c..9334096e 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -855,7 +855,15 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
first(rust_id(ctx, n.clone()))
};
- let arg_ty = P(cty_to_rs(ctx, t));
+ // From the C90 standard (http://c0x.coding-guidelines.com/6.7.5.3.html)
+ // 1598 - A declaration of a parameter as “array of type” shall be
+ // adjusted to “qualified pointer to type”, where the type qualifiers
+ // (if any) are those specified within the [ and ] of the array type
+ // derivation.
+ let arg_ty = P(match t {
+ &TArray(ref typ, _, ref l) => cty_to_rs(ctx, &TPtr(typ.clone(), false, l.clone())),
+ _ => cty_to_rs(ctx, t),
+ });
ast::Arg {
ty: arg_ty,
diff --git a/tests/headers/func_with_array_arg.h b/tests/headers/func_with_array_arg.h
new file mode 100644
index 00000000..1b81702b
--- /dev/null
+++ b/tests/headers/func_with_array_arg.h
@@ -0,0 +1 @@
+void f(int x[2]);
diff --git a/tests/test_func.rs b/tests/test_func.rs
index 8a0f2584..58faf37e 100644
--- a/tests/test_func.rs
+++ b/tests/test_func.rs
@@ -48,3 +48,14 @@ fn with_func_ptr_arg() {
}
));
}
+
+#[test]
+fn with_array_arg() {
+ assert_bind_eq!("headers/func_with_array_arg.h", cx,
+ quote_item!(cx,
+ extern "C" {
+ pub fn f(x: *mut ::libc::c_int);
+ }
+ )
+ );
+} \ No newline at end of file