go-python / gopy

gopy generates a CPython extension module from a go package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic when processing package

Keithcat1 opened this issue · comments

gopy pkg -symbols=false golang.org/x/mobile
...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0xc pc=0x5f578a]

goroutine 1 [running]:
go/types.(*Package).Name(...)
c:/go/src/go/types/package.go:33
github.com/go-python/gopy/bind.(*symbol).pyPkgId(0x11c92980, 0x120a0030, 0x2d, 0
x0)
C:/py/go/src/github.com/go-python/gopy/bind/symbols.go:361 +0x2a
github.com/go-python/gopy/bind.(*pyGen).genSliceInit(0x11ffaa80, 0x11e76400, 0x0
, 0x11ffca20)
C:/py/go/src/github.com/go-python/gopy/bind/gen_slice.go:162 +0x100c
github.com/go-python/gopy/bind.(*pyGen).genSlice(0x11ffaa80, 0x11e76400, 0x0, 0x
11ffca20)
C:/py/go/src/github.com/go-python/gopy/bind/gen_slice.go:53 +0x350
github.com/go-python/gopy/bind.(*pyGen).genAll(0x11ffaa80)
C:/py/go/src/github.com/go-python/gopy/bind/gen.go:663 +0x515
github.com/go-python/gopy/bind.(*pyGen).genPkg(0x11ffaa80, 0x120d5180)
C:/py/go/src/github.com/go-python/gopy/bind/gen.go:481 +0x124
github.com/go-python/gopy/bind.(*pyGen).gen(0x11ffaa80, 0x11ffaa80, 0x6d52f1)
C:/py/go/src/github.com/go-python/gopy/bind/gen.go:408 +0xa5
github.com/go-python/gopy/bind.GenPyBind(0x6c5d47, 0x3, 0x12132870, 0xc, 0x11c4e
14d, 0x6, 0x11cb9a70, 0x2b, 0x1209b1c0, 0x14, ...)
C:/py/go/src/github.com/go-python/gopy/bind/gen.go:369 +0x13a
main.genPkg(0x6c5d47, 0x3, 0x12132870, 0xc, 0x11c4e14d, 0x6, 0x11cb9a70, 0x2b, 0
x1209b1c0, 0x14, ...)
C:/py/go/src/github.com/go-python/gopy/gen.go:81 +0x146
main.runBuild(0x6c5d47, 0x3, 0x12132860, 0xc, 0x11c4e14d, 0x6, 0x11cb9a70, 0x2b,
0x11c510d0, 0x6, ...)
C:/py/go/src/github.com/go-python/gopy/cmd_build.go:82 +0xeb
main.gopyRunCmdPkg(0x11c56630, 0x11c3b9f8, 0x1, 0x1, 0x0, 0x0)
C:/py/go/src/github.com/go-python/gopy/cmd_pkg.go:128 +0xb5e
github.com/gonuts/commander.(*Command).Dispatch(0x11c56630, 0x11c3b9f0, 0x2, 0x2
, 0x0, 0x0)
C:/py/go/src/github.com/gonuts/commander/commands.go:221 +0x1a8
github.com/gonuts/commander.(*Command).Dispatch(0x11c56750, 0x11c3b9e8, 0x3, 0x3
, 0x0, 0x0)
C:/py/go/src/github.com/gonuts/commander/commands.go:187 +0xe1
main.run(0x11c3b9e8, 0x3, 0x3, 0x0, 0x0)
C:/py/go/src/github.com/go-python/gopy/main.go:37 +0x1cf
main.main()
C:/py/go/src/github.com/go-python/gopy/main.go:45 +0x52

this no longer crashes, maybe due to recent fixes. here's some notes for posterity:

$ go get golang.org/x/mobile
$ gopy pkg -vm=python3 golang.org/x/mobile
no required module provides package golang.org/x/mobile; to add it:
	go get golang.org/x/mobile
2021/08/31 22:42:00 Note: there was an error building [golang.org/x/mobile] -- will continue but it may fail later: exit status 1

--- skipping dir with no go files or only doc.go: golang.org/x/mobile -- []

--- building package ---
gopy pkg -name=mobile -vm=python3 golang.org/x/mobile
goimports -w mobile.go
go build -mod=mod -buildmode=c-shared -o mobile_go.so .
/usr/local/bin/python3 build.py
CGO_CFLAGS=-I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -fPIC -Ofast
CGO_LDFLAGS=-L/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib -lpython3.9 -ldl -framework CoreFoundation
go build -mod=mod -buildmode=c-shared -o _mobile.cpython-39-darwin.so .

The issue is that the top-level mobile package has no .go files, and apparently it then doesn't recognize it as a package and recursion into subdirs does not happen. So in this case, you need to list the relevant sub-packages, and use the -name=mobile arg.