Skip to content

Commit

Permalink
cxgo: Convert dynamic C arrays to slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Oct 20, 2023
1 parent c37b0f6 commit 182293c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions c_decl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
`,
},
{
Expand Down
3 changes: 3 additions & 0 deletions c_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 182293c

Please sign in to comment.