go-hdf5
go-hdf5 copied to clipboard
panic: runtime error: cgo argument has Go pointer to Go pointer
I was able to install hdf5 on Mac OS X 10.11.4 via brew
go get worked fine on this package.
Running the simple hello world linked from your README worked fine:
Fils:hdf5 dfils$ go run main.go
=== go-hdf5 ===
=== version: 1.8.16=== bye.
However, trying the compound data test from https://github.com/sbinet/go-hdf5/blob/master/cmd/test-go-cpxcmpd/main.go results in
Fils:test dfils$ go run main.go
:: data: [{0 0 1 [0 0 0] --0--} {1 1 0.5 [1 2 3] --1--} {2 4 0.3333333333333333 [2 4 6] --2--} {3 9 0.25 [3 6 9] --3--} {4 16 0.2 [4 8 12] --4--} {5 25 0.16666666666666666 [5 10 15] --5--} {6 36 0.14285714285714285 [6 12 18] --6--} {7 49 0.125 [7 14 21] --7--} {8 64 0.1111111111111111 [8 16 24] --8--} {9 81 0.1 [9 18 27] --9--}]
:: file [SDScompound.h5] created (id=16777216)
:: dset (id=83886080)
:: dset.Write...
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
panic(0x4105d60, 0xc82000a620)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/sbinet/go-hdf5._cgoCheckPointer0(0x40d9880, 0xc82006e000, 0x0, 0x0, 0x0, 0x191)
??:0 +0x4d
github.com/sbinet/go-hdf5.(*Dataset).WriteSubset(0xc82000a608, 0x40cc2c0, 0xc82006e000, 0x0, 0x0, 0x0, 0x0)
/Users/dfils/src/go/src/github.com/sbinet/go-hdf5/h5d.go:151 +0x1f8
github.com/sbinet/go-hdf5.(*Dataset).Write(0xc82000a608, 0x40cc2c0, 0xc82006e000, 0x0, 0x0)
/Users/dfils/src/go/src/github.com/sbinet/go-hdf5/h5d.go:158 +0x53
main.main()
/Users/dfils/src/go/src/oceandrilling.org/hdf5/test/main.go:83 +0x8f5
exit status 2
I've seen this Go pointer to Go pointer error before in the Go Oracle driver Ora and it was when I was using an older version that had not been updates to the way go deals with external C libraries now. (if I recall what I was told). My go version is: go version go1.6.2 darwin/amd64
Its related to https://github.com/sbinet/go-hdf5/pull/24. I think the solution is to do some of the unsafe operations (the ones cgo complains about) in C so as to hide them from the runtime.
I resolved by using uintptr, ref: https://github.com/disktnk/go-hdf5/blob/1b12b12b59ae834c19b7b4321f9922d565ad9076/h5d.go
If this workaround is acceptable, I'll send PR.