X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Fmain.rs;h=918a05a935e0c117d93f3dddfcb92365a178a78a;hb=27024f00ed3d424219c8ed8e652f6d1a97251e34;hp=a38e6e3750bdd8953a0d850c3a5c3ed42dfe66ad;hpb=5d83aff2dd572685d7f76406422167e12c836b0e;p=ldk-c-bindings diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index a38e6e3..918a05a 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -968,7 +968,7 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ writeln!(w, "pub extern \"C\" fn {}_from_str(s: crate::c_types::Str) -> {} {{", ident, container).unwrap(); writeln!(w, "\tmatch {}::from_str(s.into()) {{", resolved_path).unwrap(); writeln!(w, "\t\tOk(r) => {{").unwrap(); - let new_var = types.write_to_c_conversion_new_var(w, &syn::Ident::new("r", Span::call_site()), &*i.self_ty, Some(&gen_types), false); + let new_var = types.write_to_c_conversion_new_var(w, &format_ident!("r"), &*i.self_ty, Some(&gen_types), false); write!(w, "\t\t\tcrate::c_types::CResultTempl::ok(\n\t\t\t\t").unwrap(); types.write_to_c_conversion_inline_prefix(w, &*i.self_ty, Some(&gen_types), false); write!(w, "{}r", if new_var { "local_" } else { "" }).unwrap(); @@ -980,8 +980,17 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ } else if path_matches_nongeneric(&trait_path.1, &["Display"]) { writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "/// Get the string representation of a {} object", ident).unwrap(); - writeln!(w, "pub extern \"C\" fn {}_to_str(o: &{}) -> Str {{", ident, resolved_path).unwrap(); - writeln!(w, "\tformat!(\"{{}}\", o).into()").unwrap(); + writeln!(w, "pub extern \"C\" fn {}_to_str(o: &crate::{}) -> Str {{", ident, resolved_path).unwrap(); + + let self_ty = &i.self_ty; + let ref_type: syn::Type = syn::parse_quote!(&#self_ty); + let new_var = types.write_from_c_conversion_new_var(w, &format_ident!("o"), &ref_type, Some(&gen_types)); + write!(w, "\tformat!(\"{{}}\", ").unwrap(); + types.write_from_c_conversion_prefix(w, &ref_type, Some(&gen_types)); + write!(w, "{}o", if new_var { "local_" } else { "" }).unwrap(); + types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types)); + writeln!(w, ").into()").unwrap(); + writeln!(w, "}}").unwrap(); } else { //XXX: implement for other things like ToString @@ -1388,7 +1397,8 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a> writeln!(out, "#![allow(unused_parens)]").unwrap(); writeln!(out, "#![allow(unused_unsafe)]").unwrap(); writeln!(out, "#![allow(unused_braces)]").unwrap(); - writeln!(out, "#![deny(missing_docs)]").unwrap(); + // TODO: We need to map deny(missing_docs) in the source crate(s) + //writeln!(out, "#![deny(missing_docs)]").unwrap(); writeln!(out, "pub mod c_types;").unwrap(); writeln!(out, "pub mod bitcoin;").unwrap(); } else {