X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Ftypes.rs;h=398d0241c61d3b10d524e37a602a5c0a3fc3e2aa;hb=4b3fb779db8866b0f557d9daf997d102a3330b8e;hp=b92ca77c397c6d5af0b9e26098be36bafc527d72;hpb=cd178385527ffe4e15b935005df984fc042be30f;p=ldk-c-bindings diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index b92ca77..398d024 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -474,9 +474,12 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr let crate_name_ident = format_ident!("{}", crate_name); path.push(parse_quote!(#crate_name_ident)); } else if partial_path == "" && !dependencies.contains(&$ident) { - new_path = format!("{}::{}{}", crate_name, $ident, $path_suffix); - let crate_name_ident = format_ident!("{}", crate_name); - path.push(parse_quote!(#crate_name_ident)); + new_path = format!("{}::{}{}", module_path, $ident, $path_suffix); + for module in module_path.split("::") { + path.push(syn::PathSegment { ident: syn::Ident::new(module, Span::call_site()), arguments: syn::PathArguments::None }); + } + let ident_str = format_ident!("{}", $ident); + path.push(parse_quote!(#ident_str)); } else if format!("{}", $ident) == "self" { let mut path_iter = partial_path.rsplitn(2, "::"); path_iter.next().unwrap(); @@ -814,6 +817,7 @@ fn initial_clonable_types() -> HashSet { res.insert("crate::c_types::TxOut".to_owned()); res.insert("crate::c_types::Signature".to_owned()); res.insert("crate::c_types::RecoverableSignature".to_owned()); + res.insert("crate::c_types::BigEndianScalar".to_owned()); res.insert("crate::c_types::Bech32Error".to_owned()); res.insert("crate::c_types::Secp256k1Error".to_owned()); res.insert("crate::c_types::IOError".to_owned()); @@ -1624,7 +1628,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap(); return Some(("if ", vec![ (format!(".is_none() {{ {}::None }} else {{ {}::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */", inner_name, inner_name), - format!("{}.clone().unwrap()", var_access)) + format!("(*{}.as_ref().unwrap()).clone()", var_access)) ], ") }", ContainerPrefixLocation::PerConv)); } } else { @@ -1717,10 +1721,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { (format!("{} {{ None }} else {{ Some(", s), format!("unsafe {{ &mut *{} }}", var_access)) ], ") }", ContainerPrefixLocation::NoPrefix)), EmptyValExpectedTy::OptionType => - return Some(("{ /* ", vec![ - (format!("*/ let {}_opt = {};", var_name, var_access), - format!("}} if {}_opt{} {{ None }} else {{ Some({{ {}_opt.take()", var_name, s, var_name)) - ], ") } }", ContainerPrefixLocation::PerConv)), + return Some(("{ /*", vec![ + (format!("*/ let {}_opt = {}; if {}_opt{} {{ None }} else {{ Some({{", var_name, var_access, var_name, s), + format!("{{ {}_opt.take() }}", var_name)) + ], "})} }", ContainerPrefixLocation::PerConv)), EmptyValExpectedTy::NonPointer => return Some(("if ", vec![ (format!("{} {{ None }} else {{ Some(", s), format!("{}", var_access))