Do not accept array as function arguments (#540)
This commit is contained in:
commit
9d7516ef1a
@ -286,7 +286,14 @@ impl SynFnArgHelpers for syn::FnArg {
|
||||
}) => match **pat {
|
||||
syn::Pat::Ident(syn::PatIdent { ref ident, .. }) => {
|
||||
let ty = match Type::load(ty)? {
|
||||
Some(x) => x,
|
||||
Some(x) => {
|
||||
if let Type::Array(_, _) = x {
|
||||
return Err(
|
||||
"Array as function arguments are not supported".to_owned()
|
||||
);
|
||||
}
|
||||
x
|
||||
}
|
||||
None => return Ok(None),
|
||||
};
|
||||
Ok(Some((ident.to_string(), ty)))
|
||||
|
8
tests/expectations/both/function_args.c
Normal file
8
tests/expectations/both/function_args.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
16
tests/expectations/both/function_args.compat.c
Normal file
16
tests/expectations/both/function_args.compat.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
8
tests/expectations/function_args.c
Normal file
8
tests/expectations/function_args.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
16
tests/expectations/function_args.compat.c
Normal file
16
tests/expectations/function_args.compat.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
12
tests/expectations/function_args.cpp
Normal file
12
tests/expectations/function_args.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
extern "C" {
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust();
|
||||
|
||||
} // extern "C"
|
8
tests/expectations/tag/function_args.c
Normal file
8
tests/expectations/tag/function_args.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
16
tests/expectations/tag/function_args.compat.c
Normal file
16
tests/expectations/tag/function_args.compat.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
void pointer_test(const uint64_t *a);
|
||||
|
||||
void print_from_rust(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
22
tests/rust/function_args.rs
Normal file
22
tests/rust/function_args.rs
Normal file
@ -0,0 +1,22 @@
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn array_print(a: &[u64]) {
|
||||
eprintln!("{:?}", a);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn array_test(a: [u64; 3]) {
|
||||
array_print(&a);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn pointer_test(a: *const u64) {
|
||||
let a = std::slice::from_raw_parts(a, 3);
|
||||
array_print(a);
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn print_from_rust() {
|
||||
let a = [0, 1, 2];
|
||||
array_print(&a);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user