X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Fblocks.rs;h=e419fe095abb8dd6bd5d6dc3b403090b5b664b82;hb=aab29c474f02e0b291d305db2a1cac35eff8af81;hp=84a971bd43405dbfa877d60762f5c4e24d68cd58;hpb=45ad3320df3768514d968c70fc4b6a9d50028050;p=ldk-c-bindings diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs index 84a971b..e419fe0 100644 --- a/c-bindings-gen/src/blocks.rs +++ b/c-bindings-gen/src/blocks.rs @@ -250,7 +250,7 @@ pub fn write_vec_block(w: &mut W, mangled_container: &str, in writeln!(w, "impl Drop for {} {{", mangled_container).unwrap(); writeln!(w, "\tfn drop(&mut self) {{").unwrap(); writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap(); - writeln!(w, "\t\tunsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap(); + writeln!(w, "\t\tlet _ = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap(); writeln!(w, "\t}}").unwrap(); writeln!(w, "}}").unwrap(); if clonable { @@ -442,7 +442,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut match token_iter.next().unwrap() { TokenTree::Literal(lit) => { // Drop the first and last chars from lit as they are always " - let doc = format!("{}", lit); + let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}//!", prefix)); writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap(); }, _ => unimplemented!(), @@ -452,7 +452,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut match token_iter.next().unwrap() { TokenTree::Literal(lit) => { // Drop the first and last chars from lit as they are always " - let doc = format!("{}", lit); + let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}///", prefix)); writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap(); }, _ => unimplemented!(), @@ -747,7 +747,7 @@ pub fn write_method_call_params(w: &mut W, sig: &syn::Signatu /// Prints concrete generic parameters for a struct/trait/function, including the less-than and /// greater-than symbols, if any generic parameters are defined. -pub fn maybe_write_generics(w: &mut W, generics: &syn::Generics, types: &TypeResolver, concrete_lifetimes: bool) { +pub fn maybe_write_generics(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) { let mut gen_types = GenericTypes::new(None); assert!(gen_types.learn_generics(generics, types)); if generics.params.is_empty() { return; } @@ -778,7 +778,15 @@ pub fn maybe_write_generics(w: &mut W, generics: &syn::Generi syn::GenericParam::Type(type_param) => { write!(w, "{}", if idx != 0 { ", " } else { "" }).unwrap(); let type_ident = &type_param.ident; - types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false); + if types.understood_c_type(&syn::parse_quote!(#type_ident), Some(&gen_types)) { + types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false); + } else { + if let syn::PathArguments::AngleBracketed(args) = generics_impld { + if let syn::GenericArgument::Type(ty) = &args.args[idx] { + types.write_c_type_in_generic_param(w, &ty, Some(&gen_types), false); + } + } + } }, syn::GenericParam::Lifetime(lt) => { if concrete_lifetimes {