X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Ftypes.rs;h=73ba02a3e1dc87b4501c0a38990c5f4b12ef54dd;hb=5dfc948805a85fdd0ca37386228114f55ce4287a;hp=029fc63f807b721c9add26e21488d69c86f9c62c;hpb=8dc4d5c556cafa326969474c17f34c77e8abcc0c;p=ldk-c-bindings diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 029fc63..73ba02a 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -805,6 +805,7 @@ fn initial_clonable_types() -> HashSet { res.insert("crate::c_types::SixteenBytes".to_owned()); res.insert("crate::c_types::TwentyBytes".to_owned()); res.insert("crate::c_types::ThirtyTwoBytes".to_owned()); + res.insert("crate::c_types::EightU16s".to_owned()); res.insert("crate::c_types::SecretKey".to_owned()); res.insert("crate::c_types::PublicKey".to_owned()); res.insert("crate::c_types::Transaction".to_owned()); @@ -971,6 +972,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes"), "[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes"), "[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes"), // Used for RGB values + "[u16; 8]" if !is_ref => Some("crate::c_types::EightU16s"), "str" if is_ref => Some("crate::c_types::Str"), "alloc::string::String"|"String" => Some("crate::c_types::Str"), @@ -1060,6 +1062,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "[u8; 12]" if !is_ref => Some(""), "[u8; 4]" if !is_ref => Some(""), "[u8; 3]" if !is_ref => Some(""), + "[u16; 8]" if !is_ref => Some(""), "[u8]" if is_ref => Some(""), "[usize]" if is_ref => Some(""), @@ -1155,6 +1158,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "[u8; 12]" if !is_ref => Some(".data"), "[u8; 4]" if !is_ref => Some(".data"), "[u8; 3]" if !is_ref => Some(".data"), + "[u16; 8]" if !is_ref => Some(".data"), "[u8]" if is_ref => Some(".to_slice()"), "[usize]" if is_ref => Some(".to_slice()"), @@ -1253,6 +1257,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes { data: "), "[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "), "[u8; 3]" if is_ref => Some(""), + "[u16; 8]" if !is_ref => Some("crate::c_types::EightU16s { data: "), "[u8]" if is_ref => Some("local_"), "[usize]" if is_ref => Some("local_"), @@ -1338,6 +1343,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "[u8; 12]" if !is_ref => Some(" }"), "[u8; 4]" if !is_ref => Some(" }"), "[u8; 3]" if is_ref => Some(""), + "[u16; 8]" if !is_ref => Some(" }"), "[u8]" if is_ref => Some(""), "[usize]" if is_ref => Some(""), @@ -2104,11 +2110,12 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { } else { unimplemented!(); } }, syn::Type::Array(a) => { - // We assume all arrays contain only [int_literal; X]s. - // This may result in some outputs not compiling. - if let syn::Expr::Lit(l) = &a.len { - if let syn::Lit::Int(i) = &l.lit { - write!(w, "{}", path_lookup(&format!("[u8; {}]", i.base10_digits()), is_ref, ptr_for_ref).unwrap()).unwrap(); + if let syn::Type::Path(p) = &*a.elem { + let inner_ty = self.resolve_path(&p.path, generics); + if let syn::Expr::Lit(l) = &a.len { + if let syn::Lit::Int(i) = &l.lit { + write!(w, "{}", path_lookup(&format!("[{}; {}]", inner_ty, i.base10_digits()), is_ref, ptr_for_ref).unwrap()).unwrap(); + } else { unimplemented!(); } } else { unimplemented!(); } } else { unimplemented!(); } }, @@ -2810,6 +2817,13 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { if let syn::Type::Path(p) = &*refelem.elem { write_path!(p, Some(&mut mangled_tuple_type)); } else { return false; } + } else if let syn::Type::Array(_) = elem { + let mut resolved = Vec::new(); + if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, true, false, true) { return false; } + let array_inner = String::from_utf8(resolved).unwrap(); + let arr_name = array_inner.split("::").last().unwrap(); + write!(w, "{}", arr_name).unwrap(); + write!(mangled_type, "{}", arr_name).unwrap(); } else { return false; } } write!(w, "Z").unwrap(); @@ -2958,15 +2972,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { } else if is_ref { write!(w, "*const [").unwrap(); if !self.write_c_type_intern(w, &a.elem, generics, false, false, ptr_for_ref, with_ref_lifetime, c_ty) { return false; } - } else { - let mut typecheck = Vec::new(); - if !self.write_c_type_intern(&mut typecheck, &a.elem, generics, false, false, ptr_for_ref, with_ref_lifetime, c_ty) { return false; } - if typecheck[..] != ['u' as u8, '8' as u8] { return false; } } if let syn::Expr::Lit(l) = &a.len { if let syn::Lit::Int(i) = &l.lit { + let mut inner_ty = Vec::new(); + if !self.write_c_type_intern(&mut inner_ty, &*a.elem, generics, false, false, ptr_for_ref, false, c_ty) { return false; } + let inner_ty_str = String::from_utf8(inner_ty).unwrap(); if !is_ref { - if let Some(ty) = self.c_type_from_path(&format!("[u8; {}]", i.base10_digits()), false, ptr_for_ref) { + if let Some(ty) = self.c_type_from_path(&format!("[{}; {}]", inner_ty_str, i.base10_digits()), false, ptr_for_ref) { write!(w, "{}", ty).unwrap(); true } else { false }