Skip to content

Commit 05cfd2e

Browse files
committed
Drop special handling for more Option types and all-0 array handling
1 parent 4b3fb77 commit 05cfd2e

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

c-bindings-gen/src/types.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14551455

14561456
fn empty_val_check_suffix_from_path(&self, full_path: &str) -> Option<&str> {
14571457
match full_path {
1458-
"lightning::ln::PaymentSecret" => Some(".data == [0; 32]"),
14591458
"secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => Some(".is_null()"),
14601459
"bitcoin::secp256k1::ecdsa::Signature" => Some(".is_null()"),
14611460
_ => None
@@ -1535,11 +1534,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
15351534
// clear for users. Thus, we default to false but override for a few
15361535
// types which had mappings defined when we were avoiding the `Option_`s.
15371536
match &resolved as &str {
1538-
"lightning::ln::PaymentSecret" => true,
1539-
"lightning::ln::PaymentHash" => true,
1540-
"lightning::ln::PaymentPreimage" => true,
1541-
"lightning::ln::channelmanager::PaymentId" => true,
1542-
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" => true,
15431537
"secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => true,
15441538
_ => false,
15451539
}
@@ -1996,19 +1990,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
19961990
}
19971991
}
19981992

1999-
fn is_real_type_array(&self, resolved_type: &str) -> Option<syn::Type> {
2000-
if let Some(real_ty) = self.c_type_from_path(&resolved_type, true, false) {
2001-
if real_ty.ends_with("]") && real_ty.starts_with("*const [u8; ") {
2002-
let mut split = real_ty.split("; ");
2003-
split.next().unwrap();
2004-
let tail_str = split.next().unwrap();
2005-
assert!(split.next().is_none());
2006-
let len = usize::from_str_radix(&tail_str[..tail_str.len() - 1], 10).unwrap();
2007-
Some(parse_quote!([u8; #len]))
2008-
} else { None }
2009-
} else { None }
2010-
}
2011-
20121993
/// Prints a suffix to determine if a variable is empty (ie was set by write_empty_rust_val).
20131994
/// See EmptyValExpectedTy for information on return types.
20141995
fn write_empty_rust_val_check_suffix<W: std::io::Write>(&self, generics: Option<&GenericTypes>, w: &mut W, t: &syn::Type) -> EmptyValExpectedTy {
@@ -2018,9 +1999,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
20181999
},
20192000
syn::Type::Path(p) => {
20202001
let resolved = self.resolve_path(&p.path, generics);
2021-
if let Some(arr_ty) = self.is_real_type_array(&resolved) {
2022-
return self.write_empty_rust_val_check_suffix(generics, w, &arr_ty);
2023-
}
20242002
if self.crate_types.opaques.get(&resolved).is_some() {
20252003
write!(w, ".inner.is_null()").unwrap();
20262004
EmptyValExpectedTy::NonPointer
@@ -2810,12 +2788,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
28102788
if self.c_type_has_inner_from_path(&subtype) {
28112789
if !self.write_c_path_intern(w, &$p_arg.path, generics, is_ref, is_mut, ptr_for_ref, false, true) { return false; }
28122790
} else {
2813-
if let Some(arr_ty) = self.is_real_type_array(&subtype) {
2814-
if !self.write_c_type_intern(w, &arr_ty, generics, false, true, false, false, true) { return false; }
2815-
} else {
2816-
// Option<T> needs to be converted to a *mut T, ie mut ptr-for-ref
2817-
if !self.write_c_path_intern(w, &$p_arg.path, generics, true, true, true, false, true) { return false; }
2818-
}
2791+
// Option<T> needs to be converted to a *mut T, ie mut ptr-for-ref
2792+
if !self.write_c_path_intern(w, &$p_arg.path, generics, true, true, true, false, true) { return false; }
28192793
}
28202794
} else {
28212795
write!(w, "{}", $p_arg.path.segments.last().unwrap().ident).unwrap();

0 commit comments

Comments
 (0)