From 39ca640b03406602e729b5d2f47c9bb7dabad8d1 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Tue, 4 Apr 2017 11:53:55 -0400 Subject: [PATCH] Add WR_DESTRUCTOR_SAFE_FUNC stuff --- sample-input/bindings.rs | 8 ++++---- src/main.rs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sample-input/bindings.rs b/sample-input/bindings.rs index 48fc41f..36eadc7 100644 --- a/sample-input/bindings.rs +++ b/sample-input/bindings.rs @@ -696,7 +696,7 @@ pub extern "C" fn wr_renderer_current_epoch(renderer: &mut WrRenderer, return false; } -#[no_mangle] +#[no_mangle] #[destructor_safe] pub unsafe extern "C" fn wr_renderer_delete(renderer: *mut WrRenderer) { Box::from_raw(renderer); } @@ -722,7 +722,7 @@ pub unsafe extern "C" fn wr_rendered_epochs_next(pipeline_epochs: &mut WrRendere return false; } -#[no_mangle] +#[no_mangle] #[destructor_safe] pub unsafe extern "C" fn wr_rendered_epochs_delete(pipeline_epochs: *mut WrRenderedEpochs) { Box::from_raw(pipeline_epochs); } @@ -786,7 +786,7 @@ pub extern "C" fn wr_window_new(window_id: WrWindowId, return true; } -#[no_mangle] +#[no_mangle] #[destructor_safe] pub unsafe extern "C" fn wr_api_delete(api: *mut RenderApi) { let api = Box::from_raw(api); api.shut_down(); @@ -937,7 +937,7 @@ pub extern "C" fn wr_api_generate_frame(api: &mut RenderApi) { api.generate_frame(None); } -#[no_mangle] +#[no_mangle] #[destructor_safe] pub extern "C" fn wr_api_send_external_event(api: &mut RenderApi, evt: usize) { assert!(unsafe { !is_in_render_thread() }); diff --git a/src/main.rs b/src/main.rs index 39716e3..96bddda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,14 @@ fn has_no_mangle(attrs: &Vec) -> bool { has_attribute(MetaItem::Word(Ident::new("no_mangle")), attrs) } +fn wr_func_body(attrs: &Vec) -> String { + if has_attribute(MetaItem::Word(Ident::new("destructor_safe")), attrs) { + String::from("WR_DESTRUCTOR_SAFE_FUNC") + } else { + String::from("WR_FUNC") + } +} + fn is_c_abi(abi: &Option) -> bool { abi == &Some(Abi::Named(String::from("C"))) } @@ -75,14 +83,15 @@ fn main() { match item.node { ItemKind::Fn(decl, _unsafe, _const, abi, _generic, _block) => { if has_no_mangle(&item.attrs) && is_c_abi(&abi) { - println!("WR_INLINE {}\n{}({})\nWR_FUNC;\n", + println!("WR_INLINE {}\n{}({})\n{};\n", map_return_type(&decl.output), item.ident, decl.inputs .iter() .map(map_arg) .collect::>() - .join(", ")); + .join(", "), + wr_func_body(&item.attrs)); } } _ => {}