From: Matt Corallo Date: Sun, 18 Apr 2021 03:06:01 +0000 (+0000) Subject: Correctly handle methods on an enum that take self X-Git-Tag: v0.0.98~10^2~11 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1b1691ff11dc335218e5fbe21c94d7b83fd1acc2;p=ldk-c-bindings Correctly handle methods on an enum that take self --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index a283c35..149ae76 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -993,12 +993,20 @@ fn writeln_impl(w: &mut W, i: &syn::ItemImpl, types: &mut Typ if r.mutability.is_some() { takes_mut_self = true; } } } - if takes_mut_self { - write!(w, "unsafe {{ &mut (*(this_arg.inner as *mut native{})) }}.{}(", ident, m.sig.ident).unwrap(); - } else if takes_self { - write!(w, "unsafe {{ &*this_arg.inner }}.{}(", m.sig.ident).unwrap(); - } else { + if !takes_mut_self && !takes_self { write!(w, "{}::{}(", resolved_path, m.sig.ident).unwrap(); + } else { + match &declared_type { + DeclType::MirroredEnum => write!(w, "this_arg.to_native().{}(", m.sig.ident).unwrap(), + DeclType::StructImported => { + if takes_mut_self { + write!(w, "unsafe {{ &mut (*(this_arg.inner as *mut native{})) }}.{}(", ident, m.sig.ident).unwrap(); + } else { + write!(w, "unsafe {{ &*this_arg.inner }}.{}(", m.sig.ident).unwrap(); + } + }, + _ => unimplemented!(), + } } write_method_call_params(w, &m.sig, "", types, Some(&meth_gen_types), &ret_type, false); writeln!(w, "\n}}\n").unwrap();