@@ -668,7 +668,7 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
668
668
// Now that we've resolved the path to the path as-imported, check whether the path
669
669
// is actually a pub(.*) use statement and map it to the real path.
670
670
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 ( ) ;
672
672
let mut module_riter = path_tmp. rsplitn ( 2 , "::" ) ;
673
673
let obj = module_riter. next ( ) . unwrap ( ) ;
674
674
if let Some ( module_path) = module_riter. next ( ) {
@@ -805,6 +805,7 @@ fn initial_clonable_types() -> HashSet<String> {
805
805
res. insert ( "crate::c_types::SixteenBytes" . to_owned ( ) ) ;
806
806
res. insert ( "crate::c_types::TwentyBytes" . to_owned ( ) ) ;
807
807
res. insert ( "crate::c_types::ThirtyTwoBytes" . to_owned ( ) ) ;
808
+ res. insert ( "crate::c_types::EightU16s" . to_owned ( ) ) ;
808
809
res. insert ( "crate::c_types::SecretKey" . to_owned ( ) ) ;
809
810
res. insert ( "crate::c_types::PublicKey" . to_owned ( ) ) ;
810
811
res. insert ( "crate::c_types::Transaction" . to_owned ( ) ) ;
@@ -971,6 +972,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
971
972
"[u8; 12]" if !is_ref => Some ( "crate::c_types::TwelveBytes" ) ,
972
973
"[u8; 4]" if !is_ref => Some ( "crate::c_types::FourBytes" ) ,
973
974
"[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" ) ,
974
976
975
977
"str" if is_ref => Some ( "crate::c_types::Str" ) ,
976
978
"alloc::string::String" |"String" => Some ( "crate::c_types::Str" ) ,
@@ -1008,7 +1010,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1008
1010
"bitcoin::blockdata::transaction::OutPoint" => Some ( "crate::lightning::chain::transaction::OutPoint" ) ,
1009
1011
"bitcoin::blockdata::transaction::Transaction" |"bitcoin::Transaction" => Some ( "crate::c_types::Transaction" ) ,
1010
1012
"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" ) ,
1012
1014
"bitcoin::network::constants::Network" => Some ( "crate::bitcoin::network::Network" ) ,
1013
1015
"bitcoin::util::address::WitnessVersion" => Some ( "crate::c_types::WitnessVersion" ) ,
1014
1016
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some ( "*const [u8; 80]" ) ,
@@ -1020,9 +1022,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1020
1022
if is_ref => Some ( "*const [u8; 32]" ) ,
1021
1023
1022
1024
// 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 "
1024
1026
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 "
1026
1028
if !is_ref => Some ( "crate::c_types::ThirtyTwoBytes" ) ,
1027
1029
"bitcoin::secp256k1::Message" if !is_ref => Some ( "crate::c_types::ThirtyTwoBytes" ) ,
1028
1030
"lightning::ln::PaymentHash" |"lightning::ln::PaymentPreimage" |"lightning::ln::PaymentSecret"
@@ -1060,6 +1062,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1060
1062
"[u8; 12]" if !is_ref => Some ( "" ) ,
1061
1063
"[u8; 4]" if !is_ref => Some ( "" ) ,
1062
1064
"[u8; 3]" if !is_ref => Some ( "" ) ,
1065
+ "[u16; 8]" if !is_ref => Some ( "" ) ,
1063
1066
1064
1067
"[u8]" if is_ref => Some ( "" ) ,
1065
1068
"[usize]" if is_ref => Some ( "" ) ,
@@ -1102,7 +1105,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1102
1105
"bitcoin::Witness" if is_ref => Some ( "&" ) ,
1103
1106
"bitcoin::Witness" => Some ( "" ) ,
1104
1107
"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 ( "" ) ,
1106
1109
"bitcoin::network::constants::Network" => Some ( "" ) ,
1107
1110
"bitcoin::util::address::WitnessVersion" => Some ( "" ) ,
1108
1111
"bitcoin::blockdata::block::BlockHeader" => Some ( "&::bitcoin::consensus::encode::deserialize(unsafe { &*" ) ,
@@ -1120,7 +1123,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1120
1123
// Newtypes that we just expose in their original form.
1121
1124
"bitcoin::hash_types::Txid" if is_ref => Some ( "&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*" ) ,
1122
1125
"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(&" ) ,
1124
1128
"lightning::ln::PaymentHash" if !is_ref => Some ( "::lightning::ln::PaymentHash(" ) ,
1125
1129
"lightning::ln::PaymentHash" if is_ref => Some ( "&::lightning::ln::PaymentHash(unsafe { *" ) ,
1126
1130
"lightning::ln::PaymentPreimage" if !is_ref => Some ( "::lightning::ln::PaymentPreimage(" ) ,
@@ -1155,6 +1159,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1155
1159
"[u8; 12]" if !is_ref => Some ( ".data" ) ,
1156
1160
"[u8; 4]" if !is_ref => Some ( ".data" ) ,
1157
1161
"[u8; 3]" if !is_ref => Some ( ".data" ) ,
1162
+ "[u16; 8]" if !is_ref => Some ( ".data" ) ,
1158
1163
1159
1164
"[u8]" if is_ref => Some ( ".to_slice()" ) ,
1160
1165
"[usize]" if is_ref => Some ( ".to_slice()" ) ,
@@ -1192,7 +1197,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1192
1197
"bitcoin::blockdata::transaction::Transaction" |"bitcoin::Transaction" => Some ( ".into_bitcoin()" ) ,
1193
1198
"bitcoin::Witness" => Some ( ".into_bitcoin()" ) ,
1194
1199
"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()" ) ,
1196
1201
"bitcoin::network::constants::Network" => Some ( ".into_bitcoin()" ) ,
1197
1202
"bitcoin::util::address::WitnessVersion" => Some ( ".into()" ) ,
1198
1203
"bitcoin::blockdata::block::BlockHeader" => Some ( " }).unwrap()" ) ,
@@ -1205,7 +1210,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1205
1210
// Newtypes that we just expose in their original form.
1206
1211
"bitcoin::hash_types::Txid" if is_ref => Some ( " }[..]).unwrap()" ) ,
1207
1212
"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()" ) ,
1209
1214
"lightning::ln::PaymentHash" |"lightning::ln::PaymentPreimage" |"lightning::ln::PaymentSecret"
1210
1215
|"lightning::ln::channelmanager::PaymentId" |"lightning::ln::channelmanager::InterceptId"
1211
1216
|"lightning::chain::keysinterface::KeyMaterial"
@@ -1253,6 +1258,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1253
1258
"[u8; 12]" if !is_ref => Some ( "crate::c_types::TwelveBytes { data: " ) ,
1254
1259
"[u8; 4]" if !is_ref => Some ( "crate::c_types::FourBytes { data: " ) ,
1255
1260
"[u8; 3]" if is_ref => Some ( "" ) ,
1261
+ "[u16; 8]" if !is_ref => Some ( "crate::c_types::EightU16s { data: " ) ,
1256
1262
1257
1263
"[u8]" if is_ref => Some ( "local_" ) ,
1258
1264
"[usize]" if is_ref => Some ( "local_" ) ,
@@ -1294,7 +1300,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1294
1300
"bitcoin::Witness" if is_ref => Some ( "crate::c_types::Witness::from_bitcoin(" ) ,
1295
1301
"bitcoin::Witness" if !is_ref => Some ( "crate::c_types::Witness::from_bitcoin(&" ) ,
1296
1302
"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(" ) ,
1298
1304
"bitcoin::network::constants::Network" => Some ( "crate::bitcoin::network::Network::from_bitcoin(" ) ,
1299
1305
"bitcoin::util::address::WitnessVersion" => Some ( "" ) ,
1300
1306
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some ( "&local_" ) ,
@@ -1303,9 +1309,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1303
1309
"bitcoin::hash_types::Txid" if !is_ref => Some ( "crate::c_types::ThirtyTwoBytes { data: " ) ,
1304
1310
1305
1311
// 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 "
1307
1313
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 "
1309
1315
if !is_ref => Some ( "crate::c_types::ThirtyTwoBytes { data: " ) ,
1310
1316
"bitcoin::secp256k1::Message" if !is_ref => Some ( "crate::c_types::ThirtyTwoBytes { data: " ) ,
1311
1317
"lightning::ln::PaymentHash" |"lightning::ln::PaymentPreimage" |"lightning::ln::PaymentSecret"
@@ -1338,6 +1344,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1338
1344
"[u8; 12]" if !is_ref => Some ( " }" ) ,
1339
1345
"[u8; 4]" if !is_ref => Some ( " }" ) ,
1340
1346
"[u8; 3]" if is_ref => Some ( "" ) ,
1347
+ "[u16; 8]" if !is_ref => Some ( " }" ) ,
1341
1348
1342
1349
"[u8]" if is_ref => Some ( "" ) ,
1343
1350
"[usize]" if is_ref => Some ( "" ) ,
@@ -1377,7 +1384,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1377
1384
"bitcoin::blockdata::transaction::Transaction" |"bitcoin::Transaction" => Some ( ")" ) ,
1378
1385
"bitcoin::Witness" => Some ( ")" ) ,
1379
1386
"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 ( ")" ) ,
1381
1388
"bitcoin::network::constants::Network" => Some ( ")" ) ,
1382
1389
"bitcoin::util::address::WitnessVersion" => Some ( ".into()" ) ,
1383
1390
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some ( "" ) ,
@@ -1386,9 +1393,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1386
1393
"bitcoin::hash_types::Txid" if !is_ref => Some ( ".into_inner() }" ) ,
1387
1394
1388
1395
// 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 "
1390
1397
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 "
1392
1399
if !is_ref => Some ( ".into_inner() }" ) ,
1393
1400
"bitcoin::secp256k1::Message" if !is_ref => Some ( ".as_ref().clone() }" ) ,
1394
1401
"lightning::ln::PaymentHash" |"lightning::ln::PaymentPreimage" |"lightning::ln::PaymentSecret"
@@ -1492,7 +1499,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1492
1499
"lightning::ln::PaymentHash" => true ,
1493
1500
"lightning::ln::PaymentPreimage" => true ,
1494
1501
"lightning::ln::channelmanager::PaymentId" => true ,
1495
- "bitcoin::hash_types::BlockHash" => true ,
1502
+ "bitcoin::hash_types::BlockHash" | "bitcoin::BlockHash" => true ,
1496
1503
"secp256k1::PublicKey" |"bitcoin::secp256k1::PublicKey" => true ,
1497
1504
_ => false ,
1498
1505
}
@@ -2104,11 +2111,12 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2104
2111
} else { unimplemented ! ( ) ; }
2105
2112
} ,
2106
2113
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 ! ( ) ; }
2112
2120
} else { unimplemented ! ( ) ; }
2113
2121
} else { unimplemented ! ( ) ; }
2114
2122
} ,
@@ -2377,7 +2385,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2377
2385
write!( w, "let mut local_{}{} = " , ident,
2378
2386
if ( !to_c && needs_ref_map) || ( to_c && $container_type == "Option" && contains_slice) { "_base" } else { "" } ) . unwrap( ) ;
2379
2387
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 ) ;
2381
2389
}
2382
2390
write!( w, "{}{}" , prefix, var) . unwrap( ) ;
2383
2391
@@ -2810,6 +2818,13 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2810
2818
if let syn:: Type :: Path ( p) = & * refelem. elem {
2811
2819
write_path ! ( p, Some ( & mut mangled_tuple_type) ) ;
2812
2820
} 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 ( ) ;
2813
2828
} else { return false ; }
2814
2829
}
2815
2830
write ! ( w, "Z" ) . unwrap ( ) ;
@@ -2958,15 +2973,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2958
2973
} else if is_ref {
2959
2974
write ! ( w, "*const [" ) . unwrap ( ) ;
2960
2975
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 ; }
2965
2976
}
2966
2977
if let syn:: Expr :: Lit ( l) = & a. len {
2967
2978
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 ( ) ;
2968
2982
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) {
2970
2984
write ! ( w, "{}" , ty) . unwrap ( ) ;
2971
2985
true
2972
2986
} else { false }
0 commit comments