Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgo argument has Go pointer to Go pointer #25

Open
aep opened this issue May 22, 2017 · 3 comments
Open

cgo argument has Go pointer to Go pointer #25

aep opened this issue May 22, 2017 · 3 comments

Comments

@aep
Copy link

aep commented May 22, 2017

the example straight from README.md doesnt work.

$ ./derp 
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/qiniu/py.(*Closure).NewFunction.func2(0xc420020120, 0x2, 0x2645d50)
	/home/aep/ai/makepage/.workspace/src/github.com/qiniu/py/gofunction.go:25 +0x52
github.com/qiniu/py.(*Closure).NewFunction(0xc4200200f0, 0xc4200102a1, 0x7, 0x2, 0x0, 0x0, 0x0)
	/home/aep/ai/makepage/.workspace/src/github.com/qiniu/py/gofunction.go:25 +0xb7
github.com/qiniu/py.Register(0x7f4a8bddfd70, 0xc42004fe18, 0x4, 0x4f2380, 0x7c93c8, 0xc42004fe18, 0x4, 0xc4200102d0)
	/home/aep/ai/makepage/.workspace/src/github.com/qiniu/py/goregister.go:64 +0x4a5
github.com/qiniu/py.NewGoModule(0x50eaea, 0x3, 0x0, 0x0, 0x4f2380, 0x7c93c8, 0x7f4a8bde66e0, 0x0, 0x0, 0x0, ...)
	/home/aep/ai/makepage/.workspace/src/github.com/qiniu/py/gomodule.go:33 +0x1bf
main.main()
	/home/aep/ai/makepage/.workspace/src/derp/main.go:46 +0x83
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aep/gocode"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build102676572=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

@jerrybean
Copy link

i meet the same. i use https://github.com/sbinet/go-python instead.

@yangst90
Copy link

yangst90 commented Sep 2, 2019

+PyMethodDef*
+_gopy_malloc_PyMethodDefArray(size_t n) {

  • return (PyMethodDef*)malloc(n * sizeof(PyMethodDef));
    +}
    diff --git a/gofunction.go b/gofunction.go
    index 696e143..c17890e 100644
    --- a/gofunction.go
    +++ b/gofunction.go
    @@ -11,14 +11,14 @@ import "unsafe"
    import "reflect"

type Closure struct { // closure = self.method

  •   Self      reflect.Value
    
  •   Method    reflect.Value
    
  •   methodDef C.PyMethodDef
    
  •   Self   reflect.Value
    
  •   Method reflect.Value
    
  •   //methodDef C.PyMethodDef
    

}

func (closure *Closure) NewFunction(name string, nin int, doc string) *Base {

  •   d := &closure.methodDef
    
  •   d := C._gopy_malloc_PyMethodDefArray(1)
      d.ml_name = C.CString(name)
      defer C.free(unsafe.Pointer(d.ml_name))
    

diff --git a/gofunction.h b/gofunction.h
index 635d212..57e2372 100644
--- a/gofunction.h
+++ b/gofunction.h
@@ -1,6 +1,8 @@
#ifndef QBOX_GOPY_GOFUNCTION_H
#define QBOX_GOPY_GOFUNCTION_H

+#include <Python.h>
+PyMethodDef*
+_gopy_malloc_PyMethodDefArray(size_t n);
int setMethod(PyMethodDef* d, int nin);

#endif /* _GO_PYTHON_UTILS_H */

try this

@xiyanxiyan10
Copy link

fixed
Please run this

 export GODEBUG=cgocheck=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants