projects
/
ldk-c-bindings
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c369682
)
Correctly handle methods on an enum that take self
author
Matt Corallo
<git@bluematt.me>
Sun, 18 Apr 2021 03:06:01 +0000
(
03:06
+0000)
committer
Matt Corallo
<git@bluematt.me>
Mon, 26 Apr 2021 17:26:03 +0000
(17:26 +0000)
c-bindings-gen/src/main.rs
patch
|
blob
|
history
diff --git
a/c-bindings-gen/src/main.rs
b/c-bindings-gen/src/main.rs
index a283c35d40d41d0612836ee3befdee6725f53182..149ae76791a9c82b94355535269e4eb5ba33d31f 100644
(file)
--- a/
c-bindings-gen/src/main.rs
+++ b/
c-bindings-gen/src/main.rs
@@
-993,12
+993,20
@@
fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
if r.mutability.is_some() { takes_mut_self = true; }
}
}
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();
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();
}
write_method_call_params(w, &m.sig, "", types, Some(&meth_gen_types), &ret_type, false);
writeln!(w, "\n}}\n").unwrap();