From ace45fa9423735accfa303919d49461e7c0a075a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 31 Oct 2020 23:38:49 -0700 Subject: [PATCH 1/2] Re-enable c_take_callback test --- tests/ffi/lib.rs | 3 --- tests/ffi/tests.cc | 3 --- tests/ffi/tests.h | 3 --- tests/test.rs | 3 --- 4 files changed, 12 deletions(-) diff --git a/tests/ffi/lib.rs b/tests/ffi/lib.rs index c79aff3d1..742062d19 100644 --- a/tests/ffi/lib.rs +++ b/tests/ffi/lib.rs @@ -169,10 +169,7 @@ pub mod ffi { fn c_take_ref_rust_vec_string(v: &Vec); fn c_take_ref_rust_vec_index(v: &Vec); fn c_take_ref_rust_vec_copy(v: &Vec); - /* - // https://github.com/dtolnay/cxx/issues/232 fn c_take_callback(callback: fn(String) -> usize); - */ fn c_take_enum(e: Enum); fn c_take_ns_enum(e: AEnum); fn c_take_nested_ns_enum(e: ABEnum); diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc index 4abc45642..a03ec2b75 100644 --- a/tests/ffi/tests.cc +++ b/tests/ffi/tests.cc @@ -385,12 +385,9 @@ void c_take_ref_rust_vec_copy(const rust::Vec &v) { } } -/* -// https://github.com/dtolnay/cxx/issues/232 void c_take_callback(rust::Fn callback) { callback("2020"); } -*/ void c_take_enum(Enum e) { if (e == Enum::AVal) { diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h index 6b1ec1ef6..e5510485c 100644 --- a/tests/ffi/tests.h +++ b/tests/ffi/tests.h @@ -134,10 +134,7 @@ void c_take_ref_rust_vec(const rust::Vec &v); void c_take_ref_rust_vec_string(const rust::Vec &v); void c_take_ref_rust_vec_index(const rust::Vec &v); void c_take_ref_rust_vec_copy(const rust::Vec &v); -/* -// https://github.com/dtolnay/cxx/issues/232 void c_take_callback(rust::Fn callback); -*/ void c_take_enum(Enum e); void c_take_ns_enum(::A::AEnum e); void c_take_nested_ns_enum(::A::B::ABEnum e); diff --git a/tests/test.rs b/tests/test.rs index b651feb3f..a90b8fc34 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -149,8 +149,6 @@ fn test_c_take() { check!(ffi::c_take_nested_ns_enum(ffi::ABEnum::ABAVal)); } -/* -// https://github.com/dtolnay/cxx/issues/232 #[test] fn test_c_callback() { fn callback(s: String) -> usize { @@ -162,7 +160,6 @@ fn test_c_callback() { check!(ffi::c_take_callback(callback)); } -*/ #[test] fn test_c_call_r() { From b8ebeb0e8406e3a8cb20795e1e90fdc43e9ce492 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 31 Oct 2020 23:52:06 -0700 Subject: [PATCH 2/2] Fix fn arg representation to eliminate warning on rust 1.46+ --- macro/src/expand.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macro/src/expand.rs b/macro/src/expand.rs index 1bcaa1e30..b25d83054 100644 --- a/macro/src/expand.rs +++ b/macro/src/expand.rs @@ -594,7 +594,7 @@ fn expand_rust_function_shim_impl( quote!(#receiver_type::#ident) } }, - None => quote!(__extern), + None => quote!(::std::mem::transmute::<*const (), #sig>(__extern)), }; call.extend(quote! { (#(#vars),*) }); @@ -662,7 +662,7 @@ fn expand_rust_function_shim_impl( }; let pointer = match invoke { - None => Some(quote!(__extern: #sig)), + None => Some(quote!(__extern: *const ())), Some(_) => None, };