]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Use == null() instead of is_null() to avoid ambiguity
authorMatt Corallo <git@bluematt.me>
Wed, 23 Sep 2020 01:46:26 +0000 (21:46 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 12 Oct 2020 16:17:26 +0000 (12:17 -0400)
When we have a `Trait` wrapped as an `Option<Trait>`, 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<Target=Trait> 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

index 5dab31622d2f8660b8b521e01868a2bceecb39cf..1fe427d54f51c1bfe11ac729bd32ffd0a90e327d 100644 (file)
@@ -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!(),