python部分如下:
```
def OnReceive(sockid, str_from_golang):
print str_from_golang
CCReceiveFUNC = CFUNCTYPE(None, c_int32, c_char_p)
gReceiveFunc = CCReceiveFUNC(OnReceive)
mydll = cdll.LoadLibrary
lib = mydll("./basego.so")
print gReceiveFunc
lib.setCallbackFunc(gReceiveFunc) 用go的setCallbackFunc()来设置python的函数,作为回调函数
go部分:
var gReceive func(int32,*C.char)
//export setCallbackFunc
func setCallbackFunc(pReceive func(int32,*C.char)){
gReceive = pReceive;
fmt.Printf("func addr:%x,%x,%x\n", &pReceive);
}
(gReceive)(1,C.CString(" receive some string, call python "))
运行到上面这句报错:unexpected fault address 0x0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x7f90b0419acc]
```
有疑问加站长微信联系(非本文作者)