Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libcc2rs/src/fn_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) trait FnSig: Copy + 'static {

macro_rules! impl_fn_sig {
() => {
impl_fn_sig!(@gen A B C D E F G H I J K L M N O P);
impl_fn_sig!(@gen A B C D E F G H I J K L M N O P Q S T U V W X Y);
};
(@gen $($a:ident)*) => {
impl<R: FnPtrArg $(, $a: FnPtrArg)*> FnSig for fn($($a,)*) -> R {
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<T: FnSig> FnPtr<T> {
// invokes, e.g. `fn_ptr.call(a0, a1)`.
macro_rules! impl_fn_ptr_call {
() => {
impl_fn_ptr_call!(@gen A B C D E F G H I J K L M N O P);
impl_fn_ptr_call!(@gen A B C D E F G H I J K L M N O P Q S T U V W X Y);
};
(@gen $($a:ident)*) => {
impl<R: FnPtrArg $(, $a: FnPtrArg)*> FnPtr<fn($($a,)*) -> R> {
Expand Down
4 changes: 2 additions & 2 deletions libcc2rs/src/fn_ptr_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<T: ?Sized + 'static> FnPtrArg for *const T {

macro_rules! impl_fn_ptr_arg_unsafe_fn {
() => {
impl_fn_ptr_arg_unsafe_fn!(@gen A B C D E F G H I J K L M N O P);
impl_fn_ptr_arg_unsafe_fn!(@gen A B C D E F G H I J K L M N O P Q S T U V W X Y);
};
(@gen $($a:ident)*) => {
impl<R: 'static $(, $a: 'static)*> FnPtrArg for Option<unsafe fn($($a,)*) -> R> {
Expand Down Expand Up @@ -224,7 +224,7 @@ pub(crate) trait FnPtrArgs: Sized + 'static {

macro_rules! impl_fn_ptr_args {
() => {
impl_fn_ptr_args!(@gen A B C D E F G H I J K L M N O P);
impl_fn_ptr_args!(@gen A B C D E F G H I J K L M N O P Q S T U V W X Y);
};
(@gen $($a:ident)*) => {
impl_fn_ptr_args!(@arity $($a)*);
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/fn_ptr_arity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ int foo(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9,
return 22;
}

int wide(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9,
int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17,
int a18, int a19, int a20, int a21, int a22) {
return a1 + a22;
}

int main() {
auto f = &foo;
assert(f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) == 22);

auto w = &wide;
assert(w(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22) == 23);

auto l = [](int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8,
int a9, int a10, int a11, int a12, int a13, int a14, int a15,
int a16, int a17, int a18) { return a1 * a18; };
assert(l(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9) == 18);
return 0;
}
156 changes: 156 additions & 0 deletions tests/unit/out/refcount/fn_ptr_arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,169 @@ pub fn foo_0(
) -> i32 {
return 22;
}
pub fn wide_1(
mut a1: i32,
mut a2: i32,
mut a3: i32,
mut a4: i32,
mut a5: i32,
mut a6: i32,
mut a7: i32,
mut a8: i32,
mut a9: i32,
mut a10: i32,
mut a11: i32,
mut a12: i32,
mut a13: i32,
mut a14: i32,
mut a15: i32,
mut a16: i32,
mut a17: i32,
mut a18: i32,
mut a19: i32,
mut a20: i32,
mut a21: i32,
mut a22: i32,
) -> i32 {
return (a1 + a22);
}
pub fn main() {
__cpp2rust_init_globals();
std::process::exit(main_0());
}
fn main_0() -> i32 {
let mut f : FnPtr<fn(i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,) -> i32 > = ( FnPtr::<fn(i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,i32 ,) -> i32 >::new(foo_0) ) ;
assert!((({ f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,) }) == 22));
let mut w: FnPtr<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
> = (FnPtr::<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
>::new(wide_1));
assert!(
(({
w.call(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
)
}) == 23)
);
let l: Value<
FnPtr<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
>,
> = Rc::new(RefCell::new(FnPtr::<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
>::new(
|a1: i32,
a2: i32,
a3: i32,
a4: i32,
a5: i32,
a6: i32,
a7: i32,
a8: i32,
a9: i32,
a10: i32,
a11: i32,
a12: i32,
a13: i32,
a14: i32,
a15: i32,
a16: i32,
a17: i32,
a18: i32|
-> i32 {
{
return (a1 * a18);
}
},
)));
assert!(
(({ (*l.borrow()).call(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,) }) == 18)
);
return 0;
}
pub fn __cpp2rust_init_globals() {}
127 changes: 127 additions & 0 deletions tests/unit/out/unsafe/fn_ptr_arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ pub unsafe fn foo_0(
) -> i32 {
return 22;
}
pub unsafe fn wide_1(
mut a1: i32,
mut a2: i32,
mut a3: i32,
mut a4: i32,
mut a5: i32,
mut a6: i32,
mut a7: i32,
mut a8: i32,
mut a9: i32,
mut a10: i32,
mut a11: i32,
mut a12: i32,
mut a13: i32,
mut a14: i32,
mut a15: i32,
mut a16: i32,
mut a17: i32,
mut a18: i32,
mut a19: i32,
mut a20: i32,
mut a21: i32,
mut a22: i32,
) -> i32 {
return ((a1) + (a22));
}
pub fn main() {
unsafe {
__cpp2rust_init_globals();
Expand All @@ -35,6 +61,107 @@ unsafe fn main_0() -> i32 {
unsafe fn(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> i32,
> = (Some(foo_0));
assert!(((unsafe { (f).unwrap()(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,) }) == (22)));
let mut w: Option<
unsafe fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
> = (Some(wide_1));
assert!(
((unsafe {
(w).unwrap()(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
)
}) == (23))
);
let mut l: FnPtr<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
> = FnPtr::<
fn(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
) -> i32,
>::new(
|a1: i32,
a2: i32,
a3: i32,
a4: i32,
a5: i32,
a6: i32,
a7: i32,
a8: i32,
a9: i32,
a10: i32,
a11: i32,
a12: i32,
a13: i32,
a14: i32,
a15: i32,
a16: i32,
a17: i32,
a18: i32|
-> i32 {
unsafe {
return ((a1) * (a18));
}
},
);
assert!(((unsafe { l.call(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,) }) == (18)));
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
Loading