sjwhitworth / golearn

Machine Learning for Go
MIT License
9.29k stars 1.19k forks source link

CGoPointer Error #196

Open RickMu opened 6 years ago

RickMu commented 6 years ago

Hey I'm using Go1.9 and is experiencing a CGO Pointer Error. I think this is a reference to #129, but I don't understand how

export GODEBUG=cgocheck=0

is a temporary fix

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/sjwhitworth/golearn/linear_models.Train.func1(0xc04211b540, 0xc042242340, 0x3e)
    C:/Go/src/github.com/sjwhitworth/golearn/linear_models/liblinear.go:61 +0xa1
github.com/sjwhitworth/golearn/linear_models.Train(0xc04211b540, 0xc042242340, 0x3e)
    C:/Go/src/github.com/sjwhitworth/golearn/linear_models/liblinear.go:61 +0x49
github.com/sjwhitworth/golearn/linear_models.(*LinearSVC).Fit(0xc04211b420, 0x670640, 0xc042124af0, 0xc04211b400, 0xc042124af0)
    C:/Go/src/github.com/sjwhitworth/golearn/linear_models/linearsvc.go:179 +0x1cd
github.com/sjwhitworth/golearn/meta.(*OneVsAllModel).Fit(0xc042242280, 0x6705c0, 0xc042128000)
    C:/Go/src/github.com/sjwhitworth/golearn/meta/one_v_all.go:90 +0x290
github.com/sjwhitworth/golearn/ensemble.(*MultiLinearSVC).Fit(0xc042004588, 0x6705c0, 0xc042128000, 0x2, 0x1)
    C:/Go/src/github.com/sjwhitworth/golearn/ensemble/multisvc.go:61 +0x49
Sentimentron commented 6 years ago

Because Go is garbage collected, and the garbage collector can run concurrently to any executing C code, they made the pointer semantics stricter at some point to avoid use-after-free bugs. Passing GODEBUG=cgocheck=0 in the environment disables these checks so that old code continues to work. I tried to address the issue in #167 but unfortunately I never managed to completely fix the problem.