Skip to content

Commit 73c46cc

Browse files
committed
[bindings] Use == null() instead of is_null() to avoid ambiguity
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.
1 parent 9b3862f commit 73c46cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

c-bindings-gen/src/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
653653
fn empty_val_check_suffix_from_path(&self, full_path: &str) -> Option<&str> {
654654
match full_path {
655655
"ln::channelmanager::PaymentSecret" => Some(".data == [0; 32]"),
656+
"bitcoin::secp256k1::key::PublicKey" => Some(".is_null()"),
657+
"bitcoin::secp256k1::Signature" => Some(".is_null()"),
656658
_ => None
657659
}
658660
}
@@ -1068,7 +1070,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10681070
write!(w, "{}", suffix).unwrap();
10691071
false // We may eventually need to allow empty_val_check_suffix_from_path to specify if we need a deref or not
10701072
} else {
1071-
write!(w, ".is_null()").unwrap();
1073+
write!(w, " == std::ptr::null_mut()").unwrap();
10721074
false
10731075
}
10741076
}
@@ -1084,7 +1086,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10841086
syn::Type::Slice(_) => {
10851087
// Option<[]> always implies that we want to treat len() == 0 differently from
10861088
// None, so we always map an Option<[]> into a pointer.
1087-
write!(w, ".is_null()").unwrap();
1089+
write!(w, " == std::ptr::null_mut()").unwrap();
10881090
true
10891091
},
10901092
_ => unimplemented!(),

0 commit comments

Comments
 (0)