From 335493329551ce2483413ae25ad2876839bd31a5 Mon Sep 17 00:00:00 2001 From: Jacob Hatami Date: Fri, 7 Jan 2022 18:04:46 +0300 Subject: [PATCH 1/2] Fix for syn::Type::Reference. Properly represent a C pointer '*' or reference '&' --- src/bindgen/ir/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index 6f2ba6715..44486bb56 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -379,7 +379,7 @@ impl Type { ty: Box::new(converted), is_const, is_nullable: false, - is_ref: false, + is_ref: true, // Must be true when Type is reference } } syn::Type::Ptr(ref pointer) => { From 3ed28d878290b25df34225acde02a854f6a5dd49 Mon Sep 17 00:00:00 2001 From: Jacob Hatami Date: Fri, 7 Jan 2022 19:00:39 +0300 Subject: [PATCH 2/2] Fix for array types of arguments. Now C Arrays are passed without Pointers or Reference if required --- src/bindgen/ir/function.rs | 6 +++--- src/bindgen/ir/ty.rs | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index 840e3d391..e59250667 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -385,9 +385,9 @@ impl SynFnArgHelpers for syn::FnArg { Some(x) => x, None => return Ok(None), }; - if let Type::Array(..) = ty { - return Err("Array as function arguments are not supported".to_owned()); - } + // if let Type::Array(..) = ty { + // return Err("Array as function arguments are not supported".to_owned()); + // } Ok(Some(FunctionArgument { name, ty, diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index 44486bb56..613fcfb3f 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -375,11 +375,16 @@ impl Type { // TODO(emilio): we could make these use is_ref: true. let is_const = reference.mutability.is_none(); - Type::Ptr { - ty: Box::new(converted), - is_const, - is_nullable: false, - is_ref: true, // Must be true when Type is reference + match &converted { + Type::Array(_x, _y) => { + converted + }, + _ => Type::Ptr { + ty: Box::new(converted), + is_const, + is_nullable: false, + is_ref: true, // Must be true when Type is reference + } } } syn::Type::Ptr(ref pointer) => {