From 10d1bac4fa3a26f6df24523e3a226b9ff01647f5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 8 Oct 2023 05:52:44 +0000 Subject: [PATCH 1/3] Drop unused parameter from `get_module_type_resolver` --- c-bindings-gen/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 7c06687..c00b32d 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -267,8 +267,8 @@ macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $($pat: pat)|* => $ } } } macro_rules! get_module_type_resolver { - ($module: expr, $crate_libs: expr, $crate_types: expr) => { { - let module: &str = &$module; + ($type_in_module: expr, $crate_types: expr) => { { + let module: &str = &$type_in_module; let mut module_iter = module.rsplitn(2, "::"); module_iter.next().unwrap(); let module = module_iter.next().unwrap(); @@ -304,7 +304,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty (s, _i, _) => { if let Some(supertrait) = types.crate_types.traits.get(s) { supertrait_name = s.to_string(); - supertrait_resolver = get_module_type_resolver!(supertrait_name, types.crate_libs, types.crate_types); + supertrait_resolver = get_module_type_resolver!(supertrait_name, types.crate_types); gen_types.learn_associated_types(&supertrait, &supertrait_resolver); break; } @@ -600,10 +600,10 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty }, (s, i, generic_args) => { if let Some(supertrait) = types.crate_types.traits.get(s) { - let resolver = get_module_type_resolver!(s, types.crate_libs, types.crate_types); + let resolver = get_module_type_resolver!(s, types.crate_types); macro_rules! impl_supertrait { ($s: expr, $supertrait: expr, $i: expr, $generic_args: expr) => { - let resolver = get_module_type_resolver!($s, types.crate_libs, types.crate_types); + let resolver = get_module_type_resolver!($s, types.crate_types); // Blindly assume that the same imports where `supertrait` is defined are also // imported here. This will almost certainly break at some point, but it should be @@ -971,7 +971,7 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet { if let Some(supertrait) = types.crate_types.traits.get(s) { supertrait_name = s.to_string(); - supertrait_resolver = get_module_type_resolver!(supertrait_name, types.crate_libs, types.crate_types); + supertrait_resolver = get_module_type_resolver!(supertrait_name, types.crate_types); gen_types.learn_associated_types(&supertrait, &supertrait_resolver); break; } @@ -982,7 +982,7 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet(w: &mut W, w_uses: &mut HashSet { if let Some(supertrait_obj) = types.crate_types.traits.get(s) { From 6c7a4f5ecc7b225d480d5b5dc021af0a59430ad4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 8 Oct 2023 05:53:25 +0000 Subject: [PATCH 2/3] Update args on supertraits of supertraits when cloning trait impls When cloning implementations of traits from in-crate structs, we forgot to update the arguments for supertraits of supertraits, causing methods on that trait to be called against the previous struct, not the cloned one. This was ultimately identified downstream in the Java bindings, fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/138 --- c-bindings-gen/src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index c00b32d..22eabf7 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -1254,15 +1254,22 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet { - if types.crate_types.traits.get(s).is_some() { - assert!(!types.is_clonable(s)); // We don't currently support cloning with a clonable supertrait - writeln!(w, "\tnew_obj.{}.this_arg = new_obj.this_arg;", t).unwrap(); - writeln!(w, "\tnew_obj.{}.free = None;", t).unwrap(); + + fn seek_supertraits(w: &mut W, pfx: &str, tr: &syn::ItemTrait, types: &TypeResolver) { + walk_supertraits!(tr, Some(types), ( + (s, t, _) => { + if types.crate_types.traits.get(s).is_some() { + assert!(!types.is_clonable(s)); // We don't currently support cloning with a clonable supertrait + writeln!(w, "\tnew_obj.{}{}.this_arg = new_obj.this_arg;", pfx, t).unwrap(); + writeln!(w, "\tnew_obj.{}{}.free = None;", pfx, t).unwrap(); + let tr = types.crate_types.traits.get(s).unwrap(); + let resolver = get_module_type_resolver!(s, types.crate_types); + seek_supertraits(w, &format!("{}.", t), tr, &resolver); + } } - } - ) ); + ) ); + } + seek_supertraits(w, "", trait_obj, types); writeln!(w, "}}").unwrap(); } write!(w, "\n").unwrap(); From 35baacda84527bd86ccaf960a693db41a8070f5c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 8 Oct 2023 06:07:21 +0000 Subject: [PATCH 3/3] Update auto-generated bindings --- lightning-c-bindings/src/lightning/sign.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lightning-c-bindings/src/lightning/sign.rs b/lightning-c-bindings/src/lightning/sign.rs index 33d7316..ded5264 100644 --- a/lightning-c-bindings/src/lightning/sign.rs +++ b/lightning-c-bindings/src/lightning/sign.rs @@ -2188,6 +2188,8 @@ extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut cr new_obj.free = Some(InMemorySigner_free_void); new_obj.EcdsaChannelSigner.this_arg = new_obj.this_arg; new_obj.EcdsaChannelSigner.free = None; + new_obj.EcdsaChannelSigner.ChannelSigner.this_arg = new_obj.this_arg; + new_obj.EcdsaChannelSigner.ChannelSigner.free = None; } #[no_mangle]