cxgo icon indicating copy to clipboard operation
cxgo copied to clipboard

panic: interface conversion: types.Type is types.IntType, not *types.StructType

Open prologic opened this issue 2 years ago • 3 comments

I tried to transpile some C source from this project.

Getting this panic:

/Users/prologic/tmp/genext2fs # cxgo file genext2fs.c
panic: interface conversion: types.Type is types.IntType, not *types.StructType

goroutine 1 [running]:
github.com/gotranspile/cxgo.(*translator).convertStructType.func1()
	/go/pkg/mod/github.com/gotranspile/[email protected]/c_type.go:357 +0x6bd
github.com/gotranspile/cxgo.(*translator).newOrFindNamedType(0xc001932840, {0xc0000b4558, 0x8}, 0xc000fbfd98)
	/go/pkg/mod/github.com/gotranspile/[email protected]/c_type.go:149 +0x8e
github.com/gotranspile/cxgo.(*translator).convertStructType(0xc001932840, {{0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, ...}, ...)
	/go/pkg/mod/github.com/gotranspile/[email protected]/c_type.go:389 +0x275
github.com/gotranspile/cxgo.(*translator).newTypeCC(0xc001932840, {{0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, ...}, ...)
	/go/pkg/mod/github.com/gotranspile/[email protected]/c_type.go:241 +0x618
github.com/gotranspile/cxgo.(*translator).convertType(0xc001932840, {{0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, {0x0, 0x0}, 0x0, ...}, ...)
	/go/pkg/mod/github.com/gotranspile/[email protected]/c_type.go:59 +0x3c5
github.com/gotranspile/cxgo.(*translator).convertDecl(0xc001932840, 0xc000198640)
	/go/pkg/mod/github.com/gotranspile/[email protected]/convert.go:391 +0x24f8
github.com/gotranspile/cxgo.(*translator).translateC(0xc001932840, {0x7ffcd8a76f0c?, 0xc0000bcc60?}, 0xc0017cf080)
	/go/pkg/mod/github.com/gotranspile/[email protected]/translate.go:320 +0x133
github.com/gotranspile/cxgo.(*translator).translate(0xc001932840, {0x7ffcd8a76f0c, 0xb}, 0x4?)
	/go/pkg/mod/github.com/gotranspile/[email protected]/translate.go:267 +0x4b
github.com/gotranspile/cxgo.TranslateAST({0x7ffcd8a76f0c, _}, _, _, {{0x0, 0x0}, {0x876f27, 0x4}, {0xc0000b4810, 0xc}, ...})
	/go/pkg/mod/github.com/gotranspile/[email protected]/translate.go:163 +0x98
github.com/gotranspile/cxgo.Translate({0x0, _}, {_, _}, {_, _}, _, {{0x0, 0x0}, {0x876f27, ...}, ...})
	/go/pkg/mod/github.com/gotranspile/[email protected]/translate.go:77 +0x233
main.init.0.func1(0xc0000b6780?, {0xc000098870?, 0x1?, 0x1?})
	/go/pkg/mod/github.com/gotranspile/[email protected]/cmd/cxgo/file.go:40 +0x19a
github.com/spf13/cobra.(*Command).execute(0xc0000b6780, {0xc000098840, 0x1, 0x1})
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0xb765c0)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2ee
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:864
main.main()
	/go/pkg/mod/github.com/gotranspile/[email protected]/cmd/cxgo/main.go:63 +0x25
/Users/prologic/tmp/genext2fs #

To reproduce:

$ git clone https://github.com/bestouff/genext2fs.git
$ docker run -i -t --rm -v $PWD:$PWD -w $PWD golang:alpine /bin/sh
# apk add musl-dev
# ln -s /usr/include .
# go install github.com/gotranspile/cxgo/cmd/cxgo@latest
# cxgo file genext2fs.c

prologic avatar Jul 17 '22 06:07 prologic

Thank you for reporting it! I updated a few headers and you should now have an initial transpilation of that repo using this config and cxgo v0.3.5.

As a rule of thumb, please do not symlink include - it's always better if cxgo uses it's own headers. This way it could replace usages of those functions with Go equivalents (or wrappers). If it doesn't find something - you could quickly add a stub like this.

dennwc avatar Jul 31 '22 10:07 dennwc

I have the same problem, but I don't know which struct or int define cause this panic, can you give me some advertise?

sunburst-yz avatar Jul 14 '23 08:07 sunburst-yz

@sunburst-yz is the repo you are working on public?

dennwc avatar Jul 14 '23 12:07 dennwc