From: Matt Corallo Date: Wed, 14 Apr 2021 02:58:12 +0000 (-0400) Subject: Impl Send+Sync for every trait, not just those with it explicit X-Git-Tag: v0.0.98~4^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d26e7c63d7321a7da2afd2efc52296e19ddd641b;p=ldk-c-bindings Impl Send+Sync for every trait, not just those with it explicit Because Send+Sync are generated by the compiler for us, we don't really know when we should or should not generate it. That said, Send+Sync aren't exposed outside of Rust, so it only impacts whether we can use a type when passed to Rust, not how users will ultimately interact with types. --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 7f95ef8..8bbbdf0 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -450,11 +450,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), ( - ("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(); @@ -464,6 +464,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(&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(); @@ -495,11 +496,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(); - 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); }