Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for extern functions without a return type #127

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/mun_runtime/src/function.rs
Expand Up @@ -72,6 +72,20 @@ macro_rules! into_function_info_impl {
)
}
}

impl<$($T: HasStaticTypeInfo,)*> IntoFunctionInfo
for extern "C" fn($($T),*)
{
fn into<S: AsRef<str>>(self, name: S, privacy: abi::Privacy) -> (abi::FunctionInfo, FunctionInfoStorage) {
FunctionInfoStorage::new_function(
name.as_ref(),
&[$($T::type_info(),)*],
None,
privacy,
self as *const std::ffi::c_void,
)
}
}
)+
}
}
Expand Down
16 changes: 16 additions & 0 deletions crates/mun_runtime/src/test.rs
Expand Up @@ -775,3 +775,19 @@ fn gc_trace() {
assert_eq!(driver.runtime_mut().borrow().gc_collect(), true);
assert_eq!(driver.runtime_mut().borrow().gc_stats().allocated_memory, 0);
}

#[test]
fn can_add_external_without_return() {
extern "C" fn foo(a: i64) {
println!("{}", a);
}

let mut driver = TestDriver::new(
r#"
extern fn foo(a: int,);
pub fn main(){ foo(3); }
"#,
)
.insert_fn("foo", foo as extern "C" fn(i64) -> ());
let _: () = invoke_fn!(driver.runtime_mut(), "main").unwrap();
}