- writeln!(w, "\t\tlet mut rust_obj = {} {{ inner: ObjOps::heap_alloc(obj), is_owned: true }};", ident).unwrap();
- writeln!(w, "\t\tlet mut ret = {}_as_{}(&rust_obj);", ident, trait_obj.ident).unwrap();
- writeln!(w, "\t\t// We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn").unwrap();
- writeln!(w, "\t\trust_obj.inner = core::ptr::null_mut();").unwrap();
+ types.write_to_c_conversion_new_var(w, &format_ident!("obj"), &*i.self_ty, Some(&gen_types), false);
+ write!(w, "\t\tlet rust_obj = ").unwrap();
+ types.write_to_c_conversion_inline_prefix(w, &*i.self_ty, Some(&gen_types), false);
+ write!(w, "obj").unwrap();
+ types.write_to_c_conversion_inline_suffix(w, &*i.self_ty, Some(&gen_types), false);
+ writeln!(w, ";\n\t\tlet mut ret = {}_as_{}(&rust_obj);", ident, trait_obj.ident).unwrap();
+ writeln!(w, "\t\t// We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn").unwrap();
+ writeln!(w, "\t\tcore::mem::forget(rust_obj);").unwrap();