Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: when running tests for pocketbase, xgo v1.0.26 fails, while xgo v1.0.25 pass #80

Open
xhd2015 opened this issue Apr 21, 2024 · 2 comments
Labels
bug Something isn't working done needs_internal_doc

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Apr 21, 2024

Fail message:

fatal error: runtime: C malloc failed
_cgo_gotypes.go:202 ...
github.com/mattn/go-sqlite3._Cfunc_CString({0xc00004f130, 0x4a})
        _cgo_gotypes.go:202 +0x1d2 fp=0xc000e663d8 sp=0xc000e662c8 pc=0x101ac2a72
github.com/mattn/go-sqlite3.(*SQLiteDriver).Open(0xc0008eaf60, {0xc00004f130, 0x4a})
        /Users/xhd2015/Projects/gopath/pkg/mod/github.com/mattn/go-sqlite3@v1.14.22/sqlite3.go:1456 +0x2a5e fp=0xc000e66920 sp=0xc000e663d8 pc=0x101af06be
database/sql.dsnConnector.Connect(...)
        /Users/xhd2015/.xgo/go-instrument/go1.21.7_Us_xh_in_go_096be049/go1.21.7/src/database/sql/sql.go:758

The line of code: name := C.CString(dsn).

After comparing xgo v1.0.26 with xgo v1.0.25, and do some bisect, found this is related to the new introduced --filepath:

fileValue := funcDecl.File   --> v1.0.26
fileValue := funcDecl.FileSyntax.Pos().RelFilename() --> v1.0.25

The actual fileValue for this package.

The stack trace shows that the file holding cgo types is _cgo_gotypes.go.

And by inserting a debug snippet into the go compiler:

relFile := f.Pos().RelFilename()
trimFile := TrimFilename(f.Pos().Base())
pkgPath := xgo_ctxt.GetPkgPath()
exec.Command("bash", "-c", fmt.Sprintf("echo 'pkg=%s relFile=%s trimFile=%s' >> /tmp/debug.log", pkgPath, relFile, trimFile)).Run()

The log shows:

pkg=github.com/mattn/go-sqlite3 relFile=/var/folders/y8/kmfy7f8s5bb5qfsp0z8h7j5m0000gq/T/go-build1192418818/b174/_cgo_gotypes.go trimFile=_cgo_gotypes.go

pkg=github.com/mattn/go-sqlite3 relFile=/var/folders/y8/kmfy7f8s5bb5qfsp0z8h7j5m0000gq/T/go-build1192418818/b174/_cgo_import.go trimFile=_cgo_import.go

Could be possibly introduced the difference between relFile and trimFile.
xgo v1.0.26: use trimFile
xgo v1.0.25: use relFile

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 21, 2024

The cgo names:

_Cgo_ptr
_Cgo_use
_cgoCheckResult
_cgo_runtime_gobytes
_cgoCheckPointer
_cgo_runtime_gostring
_cgoexp_accf84c05a34_callbackTrampoline
_cgo_cmalloc

We should add a rule: if a function starts with _, we shoud skip it.

@xhd2015 xhd2015 added bug Something isn't working needs_internal_doc labels Apr 21, 2024
xhd2015 added a commit that referenced this issue Apr 21, 2024
xhd2015 added a commit that referenced this issue Apr 21, 2024
xhd2015 added a commit that referenced this issue Apr 21, 2024
xhd2015 added a commit that referenced this issue Apr 21, 2024
@xhd2015 xhd2015 added the done label Apr 21, 2024
@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 22, 2024

This golang issue may be related: golang/go#34968

Searching google: go "runtime: C malloc failed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done needs_internal_doc
Projects
None yet
Development

No branches or pull requests

1 participant