feat(ffi): Initial C API for hyper
This commit is contained in:
23
src/ffi/macros.rs
Normal file
23
src/ffi/macros.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
macro_rules! ffi_fn {
|
||||
($(#[$doc:meta])* fn $name:ident($($arg:ident: $arg_ty:ty),*) -> $ret:ty $body:block) => {
|
||||
$(#[$doc])*
|
||||
#[no_mangle]
|
||||
pub extern fn $name($($arg: $arg_ty),*) -> $ret {
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
|
||||
match panic::catch_unwind(AssertUnwindSafe(move || $body)) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
// TODO: We shouldn't abort, but rather figure out how to
|
||||
// convert into the return type that the function errored.
|
||||
eprintln!("panic unwind caught, aborting");
|
||||
std::process::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($(#[$doc:meta])* fn $name:ident($($arg:ident: $arg_ty:ty),*) $body:block) => {
|
||||
ffi_fn!($(#[$doc])* fn $name($($arg: $arg_ty),*) -> () $body);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user