Open vektah opened 8 years ago
This looks like a bug in Go runtime. Will try narrowing down it and posting to Go issue tracker.
As a temporary workaround you can use GODEBUG="cgocheck=0"
environment variable for disabling cgo check. See Environment Variables
chapter in runtime package for details.
Minimized it to:
package main
// static void foo(void *p) {}
import "C"
import (
"encoding/json"
"unsafe"
)
func main() {
b, err := json.Marshal(123)
if err != nil {
panic(err)
}
p := unsafe.Pointer(&b[0])
C.foo(p)
}
There is another workaround mentioned in the linked Go issue:
What is messing up is that encoding/json uses a 64 byte buffer in a larger struct, and if the encoding requires 64 bytes or fewer than the resulting pointer is into that struct. So one workaround is
if len(b) <= 64 {
b = append([]byte(nil), b...)
}
if err = cache.Set([]byte("key"), b, time.Hour); err != nil {
panic(err)
}
Not sure what is going on here...
gives
However, this works fine:
Running: