From 182293c507c499d9acae210276fa831628857c0a Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Fri, 20 Oct 2023 14:08:32 +0300 Subject: [PATCH] cxgo: Convert dynamic C arrays to slices. --- c_decl_test.go | 11 +++++++++++ c_type.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/c_decl_test.go b/c_decl_test.go index 9de82a6..3303c1c 100644 --- a/c_decl_test.go +++ b/c_decl_test.go @@ -673,6 +673,17 @@ func foo() { var a [1][0]int32 _ = a } +`, + }, + { + name: "dyn array arg", + src: ` +void foo(int a[]) { +} +`, + exp: ` +func foo(a []int32) { +} `, }, { diff --git a/c_type.go b/c_type.go index 07586e1..e7effae 100644 --- a/c_type.go +++ b/c_type.go @@ -85,6 +85,9 @@ func (g *translator) convertTypeRoot(conf IdentConfig, t cc.Type, where token.Po if p, ok := ft.(types.PtrType); ok && p.ElemKind().IsFunc() { ft = p.Elem() } + if p, ok := ft.(types.ArrayType); ok && p.Len() == 0 { + ft = types.SliceT(p.Elem()) + } return ft }