]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Support arrays inside Option types
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 19 May 2022 15:26:35 +0000 (10:26 -0500)
committerMatt Corallo <git@bluematt.me>
Tue, 28 Jun 2022 16:52:23 +0000 (16:52 +0000)
Previously we'd supported arrays in options only if the real type
was something which we'd aliased to an array, so its not a big
stretch to support Options containing arrays explicitly.

c-bindings-gen/src/types.rs

index 494a0ceec330b9c01d0cc30c7353ea18052ea9d3..772c34b1ea278e146a1e3c7a41350f8238a92b93 100644 (file)
@@ -1503,7 +1503,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
 
                                if let Some(t) = single_contained {
                                        match t {
-                                               syn::Type::Reference(_)|syn::Type::Path(_)|syn::Type::Slice(_) => {
+                                               syn::Type::Reference(_)|syn::Type::Path(_)|syn::Type::Slice(_)|syn::Type::Array(_) => {
                                                        let mut v = Vec::new();
                                                        let ret_ref = self.write_empty_rust_val_check_suffix(generics, &mut v, t);
                                                        let s = String::from_utf8(v).unwrap();
@@ -1799,7 +1799,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        syn::Type::Path(p) => {
                                let resolved = self.resolve_path(&p.path, generics);
                                if let Some(arr_ty) = self.is_real_type_array(&resolved) {
-                                       write!(w, ".data").unwrap();
                                        return self.write_empty_rust_val_check_suffix(generics, w, &arr_ty);
                                }
                                if self.crate_types.opaques.get(&resolved).is_some() {
@@ -1819,7 +1818,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        syn::Type::Array(a) => {
                                if let syn::Expr::Lit(l) = &a.len {
                                        if let syn::Lit::Int(i) = &l.lit {
-                                               write!(w, " == [0; {}]", i.base10_digits()).unwrap();
+                                               write!(w, ".data == [0; {}]", i.base10_digits()).unwrap();
                                                EmptyValExpectedTy::NonPointer
                                        } else { unimplemented!(); }
                                } else { unimplemented!(); }