X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Fmain.rs;h=bfadca0ed8dc415be471efa712a620ac21c3fedf;hb=6adbe96a03e129820d161b12bff80e748c68f68e;hp=ce69294928af16714f3e7b645d34cbc2faa9f510;hpb=9a960fb8c9ab355628b08a4c43fe1241caa2fa77;p=ldk-c-bindings diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index ce69294..bfadca0 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -163,7 +163,6 @@ fn write_trait_impl_field_assign(w: &mut W, trait_path: &str, /// Write out the impl block for a defined trait struct which has a supertrait fn do_write_impl_trait(w: &mut W, trait_path: &str, _trait_name: &syn::Ident, for_obj: &str) { -eprintln!("{}", trait_path); match trait_path { "lightning::util::ser::Writeable" => { writeln!(w, "impl {} for {} {{", trait_path, for_obj).unwrap(); @@ -619,20 +618,19 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct, } if let Some(ident) = &field.ident { - let ref_type = syn::Type::Reference(syn::TypeReference { - and_token: syn::Token!(&)(Span::call_site()), lifetime: None, mutability: None, - elem: Box::new(field.ty.clone()) }); - if types.understood_c_type(&ref_type, Some(&gen_types)) { - writeln_arg_docs(w, &field.attrs, "", types, Some(&gen_types), vec![].drain(..), Some(&ref_type)); - write!(w, "#[no_mangle]\npub extern \"C\" fn {}_get_{}(this_ptr: &{}) -> ", struct_name, ident, struct_name).unwrap(); - types.write_c_type(w, &ref_type, Some(&gen_types), true); - write!(w, " {{\n\tlet mut inner_val = &mut this_ptr.get_native_mut_ref().{};\n\t", ident).unwrap(); - let local_var = types.write_to_c_conversion_new_var(w, &format_ident!("inner_val"), &ref_type, Some(&gen_types), true); - if local_var { write!(w, "\n\t").unwrap(); } - types.write_to_c_conversion_inline_prefix(w, &ref_type, Some(&gen_types), true); - write!(w, "inner_val").unwrap(); - types.write_to_c_conversion_inline_suffix(w, &ref_type, Some(&gen_types), true); - writeln!(w, "\n}}").unwrap(); + if let Some(ref_type) = types.create_ownable_reference(&field.ty, Some(&gen_types)) { + if types.understood_c_type(&ref_type, Some(&gen_types)) { + writeln_arg_docs(w, &field.attrs, "", types, Some(&gen_types), vec![].drain(..), Some(&ref_type)); + write!(w, "#[no_mangle]\npub extern \"C\" fn {}_get_{}(this_ptr: &{}) -> ", struct_name, ident, struct_name).unwrap(); + types.write_c_type(w, &ref_type, Some(&gen_types), true); + write!(w, " {{\n\tlet mut inner_val = &mut this_ptr.get_native_mut_ref().{};\n\t", ident).unwrap(); + let local_var = types.write_to_c_conversion_new_var(w, &format_ident!("inner_val"), &ref_type, Some(&gen_types), true); + if local_var { write!(w, "\n\t").unwrap(); } + types.write_to_c_conversion_inline_prefix(w, &ref_type, Some(&gen_types), true); + write!(w, "inner_val").unwrap(); + types.write_to_c_conversion_inline_suffix(w, &ref_type, Some(&gen_types), true); + writeln!(w, "\n}}").unwrap(); + } } if types.understood_c_type(&field.ty, Some(&gen_types)) {