Skip to content

Commit db5b769

Browse files
authored
Merge pull request #100 from TheBlueMatt/main
LDK 0.0.114
2 parents 8eeaa64 + 592a7c1 commit db5b769

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+9158
-5953
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
run: |
3838
git clone https://github.com/rust-bitcoin/rust-lightning
3939
cd rust-lightning
40-
git checkout 0.0.113-bindings
40+
git checkout 0.0.114-bindings
41+
- name: Fix Github Actions to not be broken
42+
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
4143
- name: Rebuild bindings without std, and check the sample app builds + links
4244
run: ./genbindings.sh ./rust-lightning false
4345
- name: Rebuild bindings, and check the sample app builds + links
@@ -88,7 +90,7 @@ jobs:
8890
run: |
8991
git clone https://github.com/rust-bitcoin/rust-lightning
9092
cd rust-lightning
91-
git checkout 0.0.113-bindings
93+
git checkout 0.0.114-bindings
9294
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
9395
run: ./genbindings.sh ./rust-lightning true
9496
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/main.rs

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -600,18 +600,31 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
600600
(s, i, generic_args) => {
601601
if let Some(supertrait) = types.crate_types.traits.get(s) {
602602
let resolver = get_module_type_resolver!(s, types.crate_libs, types.crate_types);
603-
604-
// Blindly assume that the same imports where `supertrait` is defined are also
605-
// imported here. This will almost certainly break at some point, but it should be
606-
// a compilation failure when it does so.
607-
write!(w, "impl").unwrap();
608-
maybe_write_lifetime_generics(w, &supertrait.generics, types);
609-
write!(w, " {}", s).unwrap();
610-
maybe_write_generics(w, &supertrait.generics, generic_args, types, false);
611-
writeln!(w, " for {} {{", trait_name).unwrap();
612-
613-
impl_trait_for_c!(supertrait, format!(".{}", i), &resolver, generic_args);
614-
writeln!(w, "}}").unwrap();
603+
macro_rules! impl_supertrait {
604+
($s: expr, $supertrait: expr, $i: expr, $generic_args: expr) => {
605+
let resolver = get_module_type_resolver!($s, types.crate_libs, types.crate_types);
606+
607+
// Blindly assume that the same imports where `supertrait` is defined are also
608+
// imported here. This will almost certainly break at some point, but it should be
609+
// a compilation failure when it does so.
610+
write!(w, "impl").unwrap();
611+
maybe_write_lifetime_generics(w, &$supertrait.generics, types);
612+
write!(w, " {}", $s).unwrap();
613+
maybe_write_generics(w, &$supertrait.generics, $generic_args, types, false);
614+
writeln!(w, " for {} {{", trait_name).unwrap();
615+
616+
impl_trait_for_c!($supertrait, format!(".{}", $i), &resolver, $generic_args);
617+
writeln!(w, "}}").unwrap();
618+
}
619+
}
620+
impl_supertrait!(s, supertrait, i, generic_args);
621+
walk_supertraits!(supertrait, Some(&resolver), (
622+
(s, supertrait_i, generic_args) => {
623+
if let Some(supertrait) = types.crate_types.traits.get(s) {
624+
impl_supertrait!(s, supertrait, format!("{}.{}", i, supertrait_i), generic_args);
625+
}
626+
}
627+
) );
615628
} else {
616629
do_write_impl_trait(w, s, i, &trait_name);
617630
}
@@ -1061,17 +1074,38 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
10611074
("core::fmt::Debug", _, _) => {},
10621075
(s, t, _) => {
10631076
if let Some(supertrait_obj) = types.crate_types.traits.get(s) {
1064-
writeln!(w, "\t\t{}: crate::{} {{", t, s).unwrap();
1065-
writeln!(w, "\t\t\tthis_arg: unsafe {{ ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }},").unwrap();
1066-
writeln!(w, "\t\t\tfree: None,").unwrap();
1067-
for item in supertrait_obj.items.iter() {
1068-
match item {
1069-
syn::TraitItem::Method(m) => {
1070-
write_meth!(m, supertrait_obj, "\t");
1077+
macro_rules! write_impl_fields {
1078+
($s: expr, $supertrait_obj: expr, $t: expr, $pfx: expr, $resolver: expr) => {
1079+
writeln!(w, "{}\t{}: crate::{} {{", $pfx, $t, $s).unwrap();
1080+
writeln!(w, "{}\t\tthis_arg: unsafe {{ ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }},", $pfx).unwrap();
1081+
writeln!(w, "{}\t\tfree: None,", $pfx).unwrap();
1082+
for item in $supertrait_obj.items.iter() {
1083+
match item {
1084+
syn::TraitItem::Method(m) => {
1085+
write_meth!(m, $supertrait_obj, $pfx);
1086+
},
1087+
_ => {},
1088+
}
1089+
}
1090+
walk_supertraits!($supertrait_obj, Some(&$resolver), (
1091+
("Clone", _, _) => {
1092+
writeln!(w, "{}\tcloned: Some({}_{}_cloned),", $pfx, $supertrait_obj.ident, ident).unwrap();
10711093
},
1072-
_ => {},
1094+
(_, _, _) => {}
1095+
) );
10731096
}
10741097
}
1098+
write_impl_fields!(s, supertrait_obj, t, "\t", types);
1099+
1100+
let resolver = get_module_type_resolver!(s, types.crate_libs, types.crate_types);
1101+
walk_supertraits!(supertrait_obj, Some(&resolver), (
1102+
(s, t, _) => {
1103+
if let Some(supertrait_obj) = types.crate_types.traits.get(s) {
1104+
write_impl_fields!(s, supertrait_obj, t, "\t\t", resolver);
1105+
write!(w, "\t\t\t}},\n").unwrap();
1106+
}
1107+
}
1108+
) );
10751109
write!(w, "\t\t}},\n").unwrap();
10761110
} else {
10771111
write_trait_impl_field_assign(w, s, ident);
@@ -1699,7 +1733,6 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
16991733
write!(w, ")").unwrap();
17001734
}
17011735
}
1702-
if var.discriminant.is_some() { unimplemented!(); }
17031736
write!(&mut constr, ") -> {} {{\n\t{}::{}", e.ident, e.ident, var.ident).unwrap();
17041737
if let syn::Fields::Named(fields) = &var.fields {
17051738
writeln!(&mut constr, " {{").unwrap();

c-bindings-gen/src/types.rs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
668668
// Now that we've resolved the path to the path as-imported, check whether the path
669669
// is actually a pub(.*) use statement and map it to the real path.
670670
let path_tmp = path.clone();
671-
let crate_name = path_tmp.splitn(1, "::").next().unwrap();
671+
let crate_name = path_tmp.splitn(2, "::").next().unwrap();
672672
let mut module_riter = path_tmp.rsplitn(2, "::");
673673
let obj = module_riter.next().unwrap();
674674
if let Some(module_path) = module_riter.next() {
@@ -805,6 +805,7 @@ fn initial_clonable_types() -> HashSet<String> {
805805
res.insert("crate::c_types::SixteenBytes".to_owned());
806806
res.insert("crate::c_types::TwentyBytes".to_owned());
807807
res.insert("crate::c_types::ThirtyTwoBytes".to_owned());
808+
res.insert("crate::c_types::EightU16s".to_owned());
808809
res.insert("crate::c_types::SecretKey".to_owned());
809810
res.insert("crate::c_types::PublicKey".to_owned());
810811
res.insert("crate::c_types::Transaction".to_owned());
@@ -971,6 +972,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
971972
"[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes"),
972973
"[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes"),
973974
"[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes"), // Used for RGB values
975+
"[u16; 8]" if !is_ref => Some("crate::c_types::EightU16s"),
974976

975977
"str" if is_ref => Some("crate::c_types::Str"),
976978
"alloc::string::String"|"String" => Some("crate::c_types::Str"),
@@ -1008,7 +1010,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10081010
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
10091011
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some("crate::c_types::Transaction"),
10101012
"bitcoin::Witness" => Some("crate::c_types::Witness"),
1011-
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"),
1013+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"),
10121014
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network"),
10131015
"bitcoin::util::address::WitnessVersion" => Some("crate::c_types::WitnessVersion"),
10141016
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"),
@@ -1020,9 +1022,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10201022
if is_ref => Some("*const [u8; 32]"),
10211023

10221024
// Newtypes that we just expose in their original form.
1023-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1025+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
10241026
if is_ref => Some("*const [u8; 32]"),
1025-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1027+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
10261028
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
10271029
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
10281030
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
@@ -1060,6 +1062,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10601062
"[u8; 12]" if !is_ref => Some(""),
10611063
"[u8; 4]" if !is_ref => Some(""),
10621064
"[u8; 3]" if !is_ref => Some(""),
1065+
"[u16; 8]" if !is_ref => Some(""),
10631066

10641067
"[u8]" if is_ref => Some(""),
10651068
"[usize]" if is_ref => Some(""),
@@ -1102,7 +1105,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11021105
"bitcoin::Witness" if is_ref => Some("&"),
11031106
"bitcoin::Witness" => Some(""),
11041107
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
1105-
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
1108+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
11061109
"bitcoin::network::constants::Network" => Some(""),
11071110
"bitcoin::util::address::WitnessVersion" => Some(""),
11081111
"bitcoin::blockdata::block::BlockHeader" => Some("&::bitcoin::consensus::encode::deserialize(unsafe { &*"),
@@ -1120,7 +1123,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11201123
// Newtypes that we just expose in their original form.
11211124
"bitcoin::hash_types::Txid" if is_ref => Some("&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*"),
11221125
"bitcoin::hash_types::Txid" if !is_ref => Some("::bitcoin::hash_types::Txid::from_slice(&"),
1123-
"bitcoin::hash_types::BlockHash" => Some("::bitcoin::hash_types::BlockHash::from_slice(&"),
1126+
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" => Some("::bitcoin::hash_types::BlockHash::from_slice(&"),
1127+
"bitcoin::blockdata::constants::ChainHash" => Some("::bitcoin::blockdata::constants::ChainHash::from_slice(&"),
11241128
"lightning::ln::PaymentHash" if !is_ref => Some("::lightning::ln::PaymentHash("),
11251129
"lightning::ln::PaymentHash" if is_ref => Some("&::lightning::ln::PaymentHash(unsafe { *"),
11261130
"lightning::ln::PaymentPreimage" if !is_ref => Some("::lightning::ln::PaymentPreimage("),
@@ -1155,6 +1159,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11551159
"[u8; 12]" if !is_ref => Some(".data"),
11561160
"[u8; 4]" if !is_ref => Some(".data"),
11571161
"[u8; 3]" if !is_ref => Some(".data"),
1162+
"[u16; 8]" if !is_ref => Some(".data"),
11581163

11591164
"[u8]" if is_ref => Some(".to_slice()"),
11601165
"[usize]" if is_ref => Some(".to_slice()"),
@@ -1192,7 +1197,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11921197
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
11931198
"bitcoin::Witness" => Some(".into_bitcoin()"),
11941199
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1195-
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
1200+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
11961201
"bitcoin::network::constants::Network" => Some(".into_bitcoin()"),
11971202
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
11981203
"bitcoin::blockdata::block::BlockHeader" => Some(" }).unwrap()"),
@@ -1205,7 +1210,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12051210
// Newtypes that we just expose in their original form.
12061211
"bitcoin::hash_types::Txid" if is_ref => Some(" }[..]).unwrap()"),
12071212
"bitcoin::hash_types::Txid" => Some(".data[..]).unwrap()"),
1208-
"bitcoin::hash_types::BlockHash" if !is_ref => Some(".data[..]).unwrap()"),
1213+
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash"|"bitcoin::blockdata::constants::ChainHash" if !is_ref => Some(".data[..]).unwrap()"),
12091214
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
12101215
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
12111216
|"lightning::chain::keysinterface::KeyMaterial"
@@ -1253,6 +1258,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12531258
"[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes { data: "),
12541259
"[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "),
12551260
"[u8; 3]" if is_ref => Some(""),
1261+
"[u16; 8]" if !is_ref => Some("crate::c_types::EightU16s { data: "),
12561262

12571263
"[u8]" if is_ref => Some("local_"),
12581264
"[usize]" if is_ref => Some("local_"),
@@ -1294,7 +1300,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12941300
"bitcoin::Witness" if is_ref => Some("crate::c_types::Witness::from_bitcoin("),
12951301
"bitcoin::Witness" if !is_ref => Some("crate::c_types::Witness::from_bitcoin(&"),
12961302
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
1297-
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
1303+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
12981304
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
12991305
"bitcoin::util::address::WitnessVersion" => Some(""),
13001306
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"),
@@ -1303,9 +1309,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13031309
"bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13041310

13051311
// Newtypes that we just expose in their original form.
1306-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1312+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
13071313
if is_ref => Some(""),
1308-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1314+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
13091315
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13101316
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
13111317
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
@@ -1338,6 +1344,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13381344
"[u8; 12]" if !is_ref => Some(" }"),
13391345
"[u8; 4]" if !is_ref => Some(" }"),
13401346
"[u8; 3]" if is_ref => Some(""),
1347+
"[u16; 8]" if !is_ref => Some(" }"),
13411348

13421349
"[u8]" if is_ref => Some(""),
13431350
"[usize]" if is_ref => Some(""),
@@ -1377,7 +1384,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13771384
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
13781385
"bitcoin::Witness" => Some(")"),
13791386
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
1380-
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
1387+
"bitcoin::TxOut"|"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
13811388
"bitcoin::network::constants::Network" => Some(")"),
13821389
"bitcoin::util::address::WitnessVersion" => Some(".into()"),
13831390
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""),
@@ -1386,9 +1393,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13861393
"bitcoin::hash_types::Txid" if !is_ref => Some(".into_inner() }"),
13871394

13881395
// Newtypes that we just expose in their original form.
1389-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1396+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
13901397
if is_ref => Some(".as_inner()"),
1391-
"bitcoin::hash_types::Txid"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"
1398+
"bitcoin::hash_types::Txid"|"bitcoin::BlockHash"|"bitcoin::hash_types::BlockHash"|"bitcoin_hashes::sha256::Hash"|"bitcoin::blockdata::constants::ChainHash"
13921399
if !is_ref => Some(".into_inner() }"),
13931400
"bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"),
13941401
"lightning::ln::PaymentHash"|"lightning::ln::PaymentPreimage"|"lightning::ln::PaymentSecret"
@@ -1492,7 +1499,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14921499
"lightning::ln::PaymentHash" => true,
14931500
"lightning::ln::PaymentPreimage" => true,
14941501
"lightning::ln::channelmanager::PaymentId" => true,
1495-
"bitcoin::hash_types::BlockHash" => true,
1502+
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" => true,
14961503
"secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => true,
14971504
_ => false,
14981505
}
@@ -2104,11 +2111,12 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
21042111
} else { unimplemented!(); }
21052112
},
21062113
syn::Type::Array(a) => {
2107-
// We assume all arrays contain only [int_literal; X]s.
2108-
// This may result in some outputs not compiling.
2109-
if let syn::Expr::Lit(l) = &a.len {
2110-
if let syn::Lit::Int(i) = &l.lit {
2111-
write!(w, "{}", path_lookup(&format!("[u8; {}]", i.base10_digits()), is_ref, ptr_for_ref).unwrap()).unwrap();
2114+
if let syn::Type::Path(p) = &*a.elem {
2115+
let inner_ty = self.resolve_path(&p.path, generics);
2116+
if let syn::Expr::Lit(l) = &a.len {
2117+
if let syn::Lit::Int(i) = &l.lit {
2118+
write!(w, "{}", path_lookup(&format!("[{}; {}]", inner_ty, i.base10_digits()), is_ref, ptr_for_ref).unwrap()).unwrap();
2119+
} else { unimplemented!(); }
21122120
} else { unimplemented!(); }
21132121
} else { unimplemented!(); }
21142122
},
@@ -2377,7 +2385,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
23772385
write!(w, "let mut local_{}{} = ", ident,
23782386
if (!to_c && needs_ref_map) || (to_c && $container_type == "Option" && contains_slice) {"_base"} else { "" }).unwrap();
23792387
if prefix_location == ContainerPrefixLocation::OutsideConv {
2380-
var_prefix(w, $args_iter().next().unwrap(), generics, is_ref, ptr_for_ref, true);
2388+
var_prefix(w, $args_iter().next().unwrap(), generics, is_ref, true, true);
23812389
}
23822390
write!(w, "{}{}", prefix, var).unwrap();
23832391

@@ -2810,6 +2818,13 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
28102818
if let syn::Type::Path(p) = &*refelem.elem {
28112819
write_path!(p, Some(&mut mangled_tuple_type));
28122820
} else { return false; }
2821+
} else if let syn::Type::Array(_) = elem {
2822+
let mut resolved = Vec::new();
2823+
if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, true, false, true) { return false; }
2824+
let array_inner = String::from_utf8(resolved).unwrap();
2825+
let arr_name = array_inner.split("::").last().unwrap();
2826+
write!(w, "{}", arr_name).unwrap();
2827+
write!(mangled_type, "{}", arr_name).unwrap();
28132828
} else { return false; }
28142829
}
28152830
write!(w, "Z").unwrap();
@@ -2958,15 +2973,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
29582973
} else if is_ref {
29592974
write!(w, "*const [").unwrap();
29602975
if !self.write_c_type_intern(w, &a.elem, generics, false, false, ptr_for_ref, with_ref_lifetime, c_ty) { return false; }
2961-
} else {
2962-
let mut typecheck = Vec::new();
2963-
if !self.write_c_type_intern(&mut typecheck, &a.elem, generics, false, false, ptr_for_ref, with_ref_lifetime, c_ty) { return false; }
2964-
if typecheck[..] != ['u' as u8, '8' as u8] { return false; }
29652976
}
29662977
if let syn::Expr::Lit(l) = &a.len {
29672978
if let syn::Lit::Int(i) = &l.lit {
2979+
let mut inner_ty = Vec::new();
2980+
if !self.write_c_type_intern(&mut inner_ty, &*a.elem, generics, false, false, ptr_for_ref, false, c_ty) { return false; }
2981+
let inner_ty_str = String::from_utf8(inner_ty).unwrap();
29682982
if !is_ref {
2969-
if let Some(ty) = self.c_type_from_path(&format!("[u8; {}]", i.base10_digits()), false, ptr_for_ref) {
2983+
if let Some(ty) = self.c_type_from_path(&format!("[{}; {}]", inner_ty_str, i.base10_digits()), false, ptr_for_ref) {
29702984
write!(w, "{}", ty).unwrap();
29712985
true
29722986
} else { false }

0 commit comments

Comments
 (0)