X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Fmain.rs;h=fd32a1ca776610dd5813d7f6dc2fce41b6e5bb72;hb=HEAD;hp=5b432d3c20070cac8a7ee9cf541ff7876cd97aa6;hpb=28b0ccfd27d3a6e08364e377be8155727eb4a899;p=ldk-c-bindings diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 5b432d3..fd4ea8f 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -1185,28 +1185,29 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet { + takes_self = true; + break; + }, + syn::FnArg::Typed(ty) => { + if let syn::Pat::Ident(id) = &*ty.pat { + if format!("{}", id.ident) == "self" { + takes_self = true; + break; + } + } + } } } - let mut t_gen_args = String::new(); - for (idx, _) in $trait.generics.params.iter().enumerate() { - if idx != 0 { t_gen_args += ", " }; - t_gen_args += "_" - } - // rustc doesn't like <_> if the _ is actually a lifetime, so - // if all the parameters are lifetimes just skip it. - let mut nonlifetime_param = false; - for param in $trait.generics.params.iter() { - if let syn::GenericParam::Lifetime(_) = param {} - else { nonlifetime_param = true; } - } - if !nonlifetime_param { t_gen_args = String::new(); } + let mut t_gen_args_vec = Vec::new(); + maybe_write_type_non_lifetime_generics(&mut t_gen_args_vec, &$trait.generics, &trait_resolver); + let t_gen_args = String::from_utf8(t_gen_args_vec).unwrap(); if takes_self { - write!(w, ">::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap(); + write!(w, "::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap(); } else { - write!(w, ">::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap(); + write!(w, "::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap(); } let mut real_type = "".to_string(); @@ -1300,8 +1301,8 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet {} {{\n", ident, ident).unwrap(); write!(w, "\t{} {{ inner: ObjOps::heap_alloc(Default::default()), is_owned: true }}\n", ident).unwrap(); write!(w, "}}\n").unwrap(); - } else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "PartialEq"]) { - } else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "Eq"]) { + } else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::PartialEq") { + } else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::Eq") { writeln!(w, "/// Checks if two {}s contain equal inner contents.", ident).unwrap(); writeln!(w, "/// This ignores pointers and is_owned flags and looks at the values in fields.").unwrap(); if types.c_type_has_inner_from_path(&resolved_path) { @@ -1327,7 +1328,7 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet u64 {{\n", ident, ident).unwrap(); if types.c_type_has_inner_from_path(&resolved_path) { @@ -1347,8 +1348,8 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet Self {{").unwrap(); writeln!(w, "\t\tSelf {{").unwrap(); @@ -1401,7 +1402,7 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet Str {{", ident).unwrap(); @@ -1456,10 +1457,23 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet { + takes_self = true; + if r.mutability.is_some() { takes_mut_self = true; } + if r.reference.is_none() { takes_owned_self = true; } + break; + }, + syn::FnArg::Typed(ty) => { + if let syn::Pat::Ident(id) = &*ty.pat { + if format!("{}", id.ident) == "self" { + takes_self = true; + if id.mutability.is_some() { takes_mut_self = true; } + if id.by_ref.is_none() { takes_owned_self = true; } + break; + } + } + } } } if !takes_mut_self && !takes_self {