From: Matt Corallo Date: Wed, 23 Sep 2020 01:46:26 +0000 (-0400) Subject: [bindings] Use == null() instead of is_null() to avoid ambiguity X-Git-Tag: v0.0.12~7^2~19 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=a1d0dde507db0336d336adf2771d74b023a74547 [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. --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 5dab3162..1fe427d5 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!(),