Add WR_DESTRUCTOR_SAFE_FUNC stuff

This commit is contained in:
Kartikaya Gupta
2017-04-04 11:53:55 -04:00
parent b162d488b3
commit 39ca640b03
2 changed files with 15 additions and 6 deletions
+4 -4
View File
@@ -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() });
+11 -2
View File
@@ -14,6 +14,14 @@ fn has_no_mangle(attrs: &Vec<Attribute>) -> bool {
has_attribute(MetaItem::Word(Ident::new("no_mangle")), attrs)
}
fn wr_func_body(attrs: &Vec<Attribute>) -> 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<Abi>) -> 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::<Vec<_>>()
.join(", "));
.join(", "),
wr_func_body(&item.attrs));
}
}
_ => {}