diff --git a/src/codegen/function_body_chunk.rs b/src/codegen/function_body_chunk.rs index 36aee750a..442d83dff 100644 --- a/src/codegen/function_body_chunk.rs +++ b/src/codegen/function_body_chunk.rs @@ -242,11 +242,15 @@ impl Builder { Param { name: "res".to_string(), typ: format!("*mut {}::GAsyncResult", gio_crate_name) }, Param { name: "user_data".to_string(), typ: format!("{}::gpointer", glib_crate_name) }, ]; + let body = Chunk::Chunks(vec![ + Chunk::Custom("callback_guard!();".into()), + Chunk::Chunks(body), + ]); chunks.push(Chunk::ExternCFunc { name: format!("{}<{}: {}>", trampoline.name, trampoline.bound_name, trampoline.callback_type), parameters, - body: Box::new(Chunk::Chunks(body)), + body: Box::new(body), }); let chunk = Chunk::Let { name: "callback".to_string(), diff --git a/src/codegen/trampoline.rs b/src/codegen/trampoline.rs index 743399427..ed22a4523 100644 --- a/src/codegen/trampoline.rs +++ b/src/codegen/trampoline.rs @@ -51,6 +51,7 @@ pub fn generate( object_name )); } + try!(writeln!(w, "\tcallback_guard!();")); try!(writeln!(w, "\tlet f: &&({}) = transmute(f);", func_str)); try!(transformation_vars(w, analysis)); let call = trampoline_call_func(env, analysis, in_trait);