@@ -108,7 +108,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
108108 }
109109 writeln ! ( w, "}}" ) . unwrap ( ) ;
110110 } ,
111- "lightning::util::ser::Readable" |"lightning::util::ser::ReadableArgs" |"lightning::util::ser::MaybeReadable" => {
111+ "lightning::util::ser::Readable" |"lightning::util::ser::LengthReadable" | "lightning::util::ser:: ReadableArgs" |"lightning::util::ser::MaybeReadable" => {
112112 // Create the Result<Object, DecodeError> syn::Type
113113 let mut res_ty: syn:: Type = parse_quote ! ( Result <#for_ty, lightning:: ln:: msgs:: DecodeError >) ;
114114
@@ -850,7 +850,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
850850 writeln_arg_docs( w, & $field. attrs, "" , types, Some ( & gen_types) , vec![ ] . drain( ..) , Some ( & ref_type) ) ;
851851 write!( w, "#[no_mangle]\n pub extern \" C\" fn {}_get_{}(this_ptr: &{}) -> " , struct_name, $new_name, struct_name) . unwrap( ) ;
852852 types. write_c_type( w, & ref_type, Some ( & gen_types) , true ) ;
853- write!( w, " {{\n \t let mut inner_val = &mut this_ptr. get_native_mut_ref().{};\n \t " , $real_name) . unwrap( ) ;
853+ write!( w, " {{\n \t let mut inner_val = &mut {}:: get_native_mut_ref(this_ptr ).{};\n \t " , struct_name , $real_name) . unwrap( ) ;
854854 let local_var = types. write_to_c_conversion_from_ownable_ref_new_var( w, & format_ident!( "inner_val" ) , & ref_type, Some ( & gen_types) ) ;
855855 if local_var { write!( w, "\n \t " ) . unwrap( ) ; }
856856 types. write_to_c_conversion_inline_prefix( w, & ref_type, Some ( & gen_types) , true ) ;
@@ -867,7 +867,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
867867 writeln_arg_docs( w, & $field. attrs, "" , types, Some ( & gen_types) , vec![ ] . drain( ..) , Some ( & $field. ty) ) ;
868868 writeln!( w, "///\n /// Returns a copy of the field." ) . unwrap( ) ;
869869 write!( w, "#[no_mangle]\n pub extern \" C\" fn {}_get_{}(this_ptr: &{}) -> {}" , struct_name, $new_name, struct_name, s) . unwrap( ) ;
870- write!( w, " {{\n \t let mut inner_val = this_ptr. get_native_mut_ref().{}.clone();\n \t " , $real_name) . unwrap( ) ;
870+ write!( w, " {{\n \t let mut inner_val = {}:: get_native_mut_ref(this_ptr ).{}.clone();\n \t " , struct_name , $real_name) . unwrap( ) ;
871871 let local_var = types. write_to_c_conversion_new_var( w, & format_ident!( "inner_val" ) , & $field. ty, Some ( & gen_types) , true ) ;
872872 if local_var { write!( w, "\n \t " ) . unwrap( ) ; }
873873 types. write_to_c_conversion_inline_prefix( w, & $field. ty, Some ( & gen_types) , true ) ;
@@ -981,8 +981,6 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
981981 write ! ( w, "\t }}" ) . unwrap ( ) ;
982982 } ,
983983 syn:: Fields :: Unnamed ( fields) => {
984- assert ! ( !s. generics. params. iter( )
985- . any( |gen | if let syn:: GenericParam :: Lifetime ( _) = gen { false } else { true } ) ) ;
986984 writeln ! ( w, "{} (" , types. maybe_resolve_ident( & s. ident) . unwrap( ) ) . unwrap ( ) ;
987985 for ( idx, field) in fields. unnamed . iter ( ) . enumerate ( ) {
988986 write ! ( w, "\t \t " ) . unwrap ( ) ;
@@ -1395,7 +1393,39 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13951393 // instantiated.
13961394 return ;
13971395 }
1398- if path_matches_nongeneric ( & trait_path. 1 , & [ "From" ] ) {
1396+ if path_matches_ignoring_generics ( & trait_path. 1 , & [ "From" ] ) {
1397+ let from_ty;
1398+ if let syn:: PathArguments :: AngleBracketed ( args) = & trait_path. 1 . segments . last ( ) . unwrap ( ) . arguments {
1399+ assert_eq ! ( args. args. len( ) , 1 ) ;
1400+ if let syn:: GenericArgument :: Type ( ref ty) = & args. args [ 0 ] {
1401+ from_ty = ty;
1402+ } else {
1403+ panic ! ( "From needs arguments?" ) ;
1404+ }
1405+ } else {
1406+ panic ! ( "From needs arguments?" ) ;
1407+ }
1408+ let to_std = resolved_path. starts_with ( "core::" ) || resolved_path. starts_with ( "std::" ) ;
1409+ if !to_std && types. understood_c_type ( & from_ty, Some ( & gen_types) ) {
1410+ if let syn:: Type :: Path ( from_path) = & from_ty {
1411+ let mut from_resolved_bytes = Vec :: new ( ) ;
1412+ types. write_c_type ( & mut from_resolved_bytes, from_ty, Some ( & gen_types) , true ) ;
1413+ let from_resolved = String :: from_utf8 ( from_resolved_bytes) . unwrap ( ) ;
1414+ let from_ty_ident = from_resolved. rsplit ( "::" ) . next ( ) . unwrap ( ) ;
1415+ writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
1416+ writeln ! ( w, "/// Build a {ident} from a {from_ty_ident}" ) . unwrap ( ) ;
1417+ writeln ! ( w, "pub extern \" C\" fn {ident}_from_{from_ty_ident}(f: {from_resolved}) -> crate::{resolved_path} {{" ) . unwrap ( ) ;
1418+ write ! ( w, "\t let from_obj = " ) . unwrap ( ) ;
1419+ types. write_from_c_conversion_prefix ( w, from_ty, Some ( & gen_types) ) ;
1420+ write ! ( w, "f" ) . unwrap ( ) ;
1421+ types. write_from_c_conversion_suffix ( w, from_ty, Some ( & gen_types) ) ;
1422+ write ! ( w, ";\n \t " ) . unwrap ( ) ;
1423+ types. write_to_c_conversion_inline_prefix ( w, & * i. self_ty , Some ( & gen_types) , true ) ;
1424+ write ! ( w, "({resolved_path}::from(from_obj))" ) . unwrap ( ) ;
1425+ types. write_to_c_conversion_inline_suffix ( w, & * i. self_ty , Some ( & gen_types) , true ) ;
1426+ writeln ! ( w, "\n }}" ) . unwrap ( ) ;
1427+ } else { panic ! ( "wat {:?}" , from_ty) ; }
1428+ }
13991429 } else if path_matches_nongeneric ( & trait_path. 1 , & [ "Default" ] ) {
14001430 writeln ! ( w, "/// Creates a \" default\" {}. See struct and individual field documentaiton for details on which values are used." , ident) . unwrap ( ) ;
14011431 write ! ( w, "#[must_use]\n #[no_mangle]\n pub extern \" C\" fn {}_default() -> {} {{\n " , ident, ident) . unwrap ( ) ;
@@ -1454,18 +1484,18 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
14541484 writeln ! ( w, "\t fn clone(&self) -> Self {{" ) . unwrap ( ) ;
14551485 writeln ! ( w, "\t \t Self {{" ) . unwrap ( ) ;
14561486 writeln ! ( w, "\t \t \t inner: if <*mut native{}>::is_null(self.inner) {{ core::ptr::null_mut() }} else {{" , ident) . unwrap ( ) ;
1457- writeln ! ( w, "\t \t \t \t ObjOps::heap_alloc(unsafe {{ &*ObjOps::untweak_ptr(self.inner) }}.clone( )) }}," ) . unwrap ( ) ;
1487+ writeln ! ( w, "\t \t \t \t ObjOps::heap_alloc(Clone::clone( unsafe {{ &*ObjOps::untweak_ptr(self.inner) }})) }}," ) . unwrap ( ) ;
14581488 writeln ! ( w, "\t \t \t is_owned: true," ) . unwrap ( ) ;
14591489 writeln ! ( w, "\t \t }}\n \t }}\n }}" ) . unwrap ( ) ;
14601490 writeln ! ( w, "#[allow(unused)]" ) . unwrap ( ) ;
14611491 writeln ! ( w, "/// Used only if an object of this type is returned as a trait impl by a method" ) . unwrap ( ) ;
14621492 writeln ! ( w, "pub(crate) extern \" C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{" , ident) . unwrap ( ) ;
1463- writeln ! ( w, "\t Box::into_raw(Box::new(unsafe {{ ( *(this_ptr as *const native{})).clone() }})) as *mut c_void" , ident) . unwrap ( ) ;
1493+ writeln ! ( w, "\t Box::into_raw(Box::new(Clone::clone( unsafe {{ & *(this_ptr as *const native{}) }}) )) as *mut c_void" , ident) . unwrap ( ) ;
14641494 writeln ! ( w, "}}" ) . unwrap ( ) ;
14651495 writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
14661496 writeln ! ( w, "/// Creates a copy of the {}" , ident) . unwrap ( ) ;
14671497 writeln ! ( w, "pub extern \" C\" fn {}_clone(orig: &{}) -> {} {{" , ident, ident, ident) . unwrap ( ) ;
1468- writeln ! ( w, "\t orig. clone()" ) . unwrap ( ) ;
1498+ writeln ! ( w, "\t Clone:: clone(orig )" ) . unwrap ( ) ;
14691499 writeln ! ( w, "}}" ) . unwrap ( ) ;
14701500 } else if path_matches_nongeneric ( & trait_path. 1 , & [ "FromStr" ] ) {
14711501 let mut err_opt = None ;
@@ -2556,6 +2586,7 @@ fn main() {
25562586
25572587 // Write a few manually-defined types into the C++ header file
25582588 write_cpp_wrapper ( & mut cpp_header_file, "Str" , true , None ) ;
2589+ write_cpp_wrapper ( & mut cpp_header_file, "ECDSASignature" , false , None ) ;
25592590
25602591 // First parse the full crate's ASTs, caching them so that we can hold references to the AST
25612592 // objects in other datastructures:
0 commit comments