来回传递字节数组到插件时发生致命错误

时间:2018-07-18 08:55:57

标签: go

我正在编写一个golang插件,在这里我需要不断从插件函数获取字节数组,并将其传递给该插件提供的另一个函数。 但是,经过几次迭代,我得到了这个错误

  

严重错误:在堆栈上找到无效的指针

client.go

package main

import (
    "plugin"
    "log"
)

type T interface {
    GenByte() []byte
    PrintByte(data []byte)
}

func main()  {
    plgin, _ := plugin.Open("./plugin.so")
    symbol, _ := plgin.Lookup("Endpoint")
    b, _ := symbol.(T)
    log.Println("From main")
    for{
        data := b.GenByte()
        b.PrintByte(data)
    }


}

plugin.go

package main

import (
    "log"
)

type dummy struct {}

func (d dummy)GenByte() []byte  {
    log.Println("From plugin GenByte")
    data:=[]byte{1,2,3,4,5}
    return data
}

func (d dummy)PrintByte(data []byte)  {
    log.Println("From plugin PrintByte")
    log.Println(data)
}

var Endpoint dummy


func main() {

}

output
2018/07/18 16:47:51 From plugin GenByte
2018/07/18 16:47:51 From plugin PrintByte
2018/07/18 16:47:51 [1 2 3 4 5]
[repeat a number of times]
runtime: bad pointer in frame plugin/unnamed-8b1a52c90a93f94ad1c14cee47dc41ef6a9bc487.dummy.PrintByte at 0xc420055eb0: 0x5
fatal error: invalid pointer found on stack

更新: go版本go1.10.3 darwin / amd64

转到环境

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yishengyang/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/yishengyang//go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vh/6m51srdn3ps28tc64qy1343h0000gp/T/go-build637303097=/tmp/go-build -gno-record-gcc-switches -fno-common"

0 个答案:

没有答案