projects
/
ldk-c-bindings
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #34 from TheBlueMatt/main
[ldk-c-bindings]
/
c-bindings-gen
/
src
/
main.rs
diff --git
a/c-bindings-gen/src/main.rs
b/c-bindings-gen/src/main.rs
index 7f95ef831446bcb2193a2942d91bf2a3d66cd49e..9693e3d560a04575cf51863ec180ce1d37956434 100644
(file)
--- a/
c-bindings-gen/src/main.rs
+++ b/
c-bindings-gen/src/main.rs
@@
-280,10
+280,9
@@
fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
writeln!(w, "\tpub set_{}: Option<extern \"C\" fn(&{})>,", m.sig.ident, trait_name).unwrap();
generated_fields.push((format!("set_{}", m.sig.ident), true));
// Note that cbindgen will now generate
writeln!(w, "\tpub set_{}: Option<extern \"C\" fn(&{})>,", m.sig.ident, trait_name).unwrap();
generated_fields.push((format!("set_{}", m.sig.ident), true));
// Note that cbindgen will now generate
- // typedef struct Thing {..., set_thing: (const Thing*), ...} Thing;
+ // typedef struct Thing {..., set_thing: (const
struct
Thing*), ...} Thing;
// which does not compile since Thing is not defined before it is used.
writeln!(extra_headers, "struct LDK{};", trait_name).unwrap();
// which does not compile since Thing is not defined before it is used.
writeln!(extra_headers, "struct LDK{};", trait_name).unwrap();
- writeln!(extra_headers, "typedef struct LDK{} LDK{};", trait_name, trait_name).unwrap();
continue;
}
// Sadly, this currently doesn't do what we want, but it should be easy to get
continue;
}
// Sadly, this currently doesn't do what we want, but it should be easy to get
@@
-317,7
+316,6
@@
fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "\t/// Checks if two objects are equal given this object's this_arg pointer and another object.").unwrap();
writeln!(w, "\tpub eq: extern \"C\" fn (this_arg: *const c_void, other_arg: &{}) -> bool,", trait_name).unwrap();
("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "\t/// Checks if two objects are equal given this object's this_arg pointer and another object.").unwrap();
writeln!(w, "\tpub eq: extern \"C\" fn (this_arg: *const c_void, other_arg: &{}) -> bool,", trait_name).unwrap();
- writeln!(extra_headers, "typedef struct LDK{} LDK{};", trait_name, trait_name).unwrap();
generated_fields.push(("eq".to_owned(), true));
},
("std::hash::Hash", _)|("core::hash::Hash", _) => {
generated_fields.push(("eq".to_owned(), true));
},
("std::hash::Hash", _)|("core::hash::Hash", _) => {
@@
-450,11
+448,11
@@
fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
}
}
}
}
+ writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap();
+ writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap();
// Implement supertraits for the C-mapped struct.
walk_supertraits!(t, Some(&types), (
// Implement supertraits for the C-mapped struct.
walk_supertraits!(t, Some(&types), (
- ("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(),
- ("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(),
("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "impl std::cmp::Eq for {} {{}}", trait_name).unwrap();
writeln!(w, "impl std::cmp::PartialEq for {} {{", trait_name).unwrap();
("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "impl std::cmp::Eq for {} {{}}", trait_name).unwrap();
writeln!(w, "impl std::cmp::PartialEq for {} {{", trait_name).unwrap();
@@
-464,6
+462,7
@@
fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
writeln!(w, "impl std::hash::Hash for {} {{", trait_name).unwrap();
writeln!(w, "\tfn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap();
},
writeln!(w, "impl std::hash::Hash for {} {{", trait_name).unwrap();
writeln!(w, "\tfn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap();
},
+ ("Send", _) => {}, ("Sync", _) => {},
("Clone", _) => {
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Creates a copy of a {}", trait_name).unwrap();
("Clone", _) => {
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Creates a copy of a {}", trait_name).unwrap();
@@
-495,11
+494,6
@@
fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
writeln!(w, "impl {} for {} {{", s, trait_name).unwrap();
impl_trait_for_c!(supertrait, format!(".{}", i), &resolver);
writeln!(w, "}}").unwrap();
writeln!(w, "impl {} for {} {{", s, trait_name).unwrap();
impl_trait_for_c!(supertrait, format!(".{}", i), &resolver);
writeln!(w, "}}").unwrap();
- walk_supertraits!(supertrait, Some(&types), (
- ("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(),
- ("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(),
- _ => unimplemented!()
- ) );
} else {
do_write_impl_trait(w, s, i, &trait_name);
}
} else {
do_write_impl_trait(w, s, i, &trait_name);
}