我正在使用软件包zdelta-go在Go项目中执行增量压缩。它使用cgo调用源库zdelta-c中的C代码。 这是我测试程序包的代码:
import (
"github.com/snej/zdelta-go"
"log"
)
func main() {
v1 := []byte("This is versions one")
v2 := []byte("This is versions two")
delta, err := zdelta.CreateDelta(v1, v2)
if err != nil {
log.Fatal(err)
}
log.Print(len(delta))
}
错误输出:
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
github.com/snej/zdelta-go.zd_deflateInit.func1(0xc420086000, 0xffffffff, 0x146f2f0, 0x90, 0x0)
/home/ubuntu/dev/go/src/github.com/snej/zdelta-go/zdelta_utils.go:33 +0x52
github.com/snej/zdelta-go.zd_deflateInit(0xc420086000, 0xffffffff, 0x1)
/home/ubuntu/dev/go/src/github.com/snej/zdelta-go/zdelta_utils.go:33 +0x2c5
github.com/snej/zdelta-go.(*Compressor).WriteDelta(0xc420086000, 0xc42000c200, 0x14, 0x20, 0xc42000c220, 0x14, 0x20, 0x72ffe0, 0xc42
/home/ubuntu/dev/go/src/github.com/snej/zdelta-go/zdelta.go:132 +0x293
github.com/snej/zdelta-go.(*Compressor).CreateDelta(0xc420086000, 0xc42000c200, 0x14, 0x20, 0xc42000c220, 0x14, 0x20, 0x20, 0xc42000
/home/ubuntu/dev/go/src/github.com/snej/zdelta-go/zdelta.go:161 +0xa5
github.com/snej/zdelta-go.CreateDelta(0xc42000c200, 0x14, 0x20, 0xc42000c220, 0x14, 0x20, 0x0, 0x4be460, 0xc420056050, 0x0, ...)
/home/ubuntu/dev/go/src/github.com/snej/zdelta-go/zdelta.go:227 +0xb8
此错误是由于Go1.6规范中的更改(即Go指针不能作为C指针传递给C函数)引起的。
这是导致错误的代码块:
func zd_deflateInit(strm C.zd_streamp, level C.int) C.int {
vers := C.CString(C.ZDLIB_VERSION)
rval := C.zd_deflateInit_(strm, level, vers, C.int(unsafe.Sizeof(*strm))) --> ERROR
C.free(unsafe.Pointer(vers))
return rval
}
我是Go语言的新手,不熟悉C,有人可以帮我吗。