zdelta-go runtime error: cgo argument has Go pointer to Go pointer

0

I'm using package zdelta-go to perform delta compression in a Go project. It uses cgo to call the C code in the source library zdelta-c. This is my code to test the package:

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))
}

The error output:

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

This error is caused by the change in Go1.6 specification that Go pointer can not be passed to C function as C pointer.

This is the code block that cause the error:

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
}

I'm new in Go and not familiar with C, can someone help me.

c
go
asked on Stack Overflow Nov 3, 2018 by nguoinaodo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0