From a1d0dde507db0336d336adf2771d74b023a74547 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 22 Sep 2020 21:46:26 -0400 Subject: [PATCH] [bindings] Use == null() instead of is_null() to avoid ambiguity When we have a `Trait` wrapped as an `Option`, we called `<*const Trait>.is_null()` which resulted in rustc trying to take the most braindead option of dereferencing the whole thing and hitting a recursive dereference since we `impl Deref for Trait` for all our traits. Instead, we can be explicit and just compare the pointer directly with `std::ptr::null()` which avoids this. --- c-bindings-gen/src/types.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 5dab31622..1fe427d54 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -653,6 +653,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { fn empty_val_check_suffix_from_path(&self, full_path: &str) -> Option<&str> { match full_path { "ln::channelmanager::PaymentSecret" => Some(".data == [0; 32]"), + "bitcoin::secp256k1::key::PublicKey" => Some(".is_null()"), + "bitcoin::secp256k1::Signature" => Some(".is_null()"), _ => None } } @@ -1068,7 +1070,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { write!(w, "{}", suffix).unwrap(); false // We may eventually need to allow empty_val_check_suffix_from_path to specify if we need a deref or not } else { - write!(w, ".is_null()").unwrap(); + write!(w, " == std::ptr::null_mut()").unwrap(); false } } @@ -1084,7 +1086,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { syn::Type::Slice(_) => { // Option<[]> always implies that we want to treat len() == 0 differently from // None, so we always map an Option<[]> into a pointer. - write!(w, ".is_null()").unwrap(); + write!(w, " == std::ptr::null_mut()").unwrap(); true }, _ => unimplemented!(), -- 2.39.5