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 blows up with runtime error: cgo argument has Go pointer to Go pointer #33

Closed
paultag opened this issue Oct 2, 2016 · 5 comments
Closed

Comments

@paultag
Copy link
Contributor

paultag commented Oct 2, 2016

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running, locked to thread]:
panic(0x65d200, 0xc4200185f0)
    /usr/lib/go-1.7/src/runtime/panic.go:500 +0x1a1
github.com/sourcegraph/go-webkit2/webkit2.(*WebView).RunJavaScript(0xc420018530, 0xc4200595d8, 0xf, 0xc4200185e0)
    /home/paultag/.goenvs/epson/src/github.com/sourcegraph/go-webkit2/webkit2/webview.go:147 +0xea
main.main.func3(0xc4200380b8, 0x3)
    /home/paultag/dev/local/go-webkit2/cmd/webkit-eval-js/evaljs.go:84 +0xfb
reflect.Value.call(0x650f40, 0xc42000c5a0, 0x13, 0x6aeb1c, 0x4, 0xc42000c7b0, 0x2, 0x2, 0x0, 0x6490c0, ...)
    /usr/lib/go-1.7/src/reflect/value.go:434 +0x5c8
reflect.Value.Call(0x650f40, 0xc42000c5a0, 0x13, 0xc42000c7b0, 0x2, 0x2, 0xc4200185d0, 0x82, 0x0)
    /usr/lib/go-1.7/src/reflect/value.go:302 +0xa4
github.com/gotk3/gotk3/glib.goMarshal(0x16b2180, 0x0, 0x2, 0x7ffe3a989690, 0x7ffe3a989610, 0x0)
    /home/paultag/.goenvs/epson/src/github.com/gotk3/gotk3/glib/glib.go:283 +0x601
github.com/gotk3/gotk3/glib._cgoexpwrap_cca433d51eec_goMarshal(0x16b2180, 0x0, 0x2, 0x7ffe3a989690, 0x7ffe3a989610, 0x0)
    ??:0 +0x5b
github.com/gotk3/gotk3/gtk._Cfunc_gtk_main()
    ??:0 +0x41
github.com/gotk3/gotk3/gtk.Main()
    /home/paultag/.goenvs/epson/src/github.com/gotk3/gotk3/gtk/gtk.go:766 +0x14
main.main()
    /home/paultag/dev/local/go-webkit2/cmd/webkit-eval-js/evaljs.go:93 +0x474

https://groups.google.com/forum/#!searchin/golang-nuts/cgo$20argument$20has$20Go$20pointer$20to$20Go$20pointer/golang-nuts/gnH0nhPf36I/4Shly3gxEwAJ

golang/go#12416

@paultag
Copy link
Contributor Author

paultag commented Oct 2, 2016

@paultag
Copy link
Contributor Author

paultag commented Oct 2, 2016

Ah, this is likely a gotk bug, I'll pass that along.

@paultag
Copy link
Contributor Author

paultag commented Oct 2, 2016

Nevermind this is go-webkit2 bug. Sorry for the noise.

@paultag paultag reopened this Oct 2, 2016
@paultag
Copy link
Contributor Author

paultag commented Oct 3, 2016

One possible fix may be to do:

index 3f79cc0..638db8b 100644
--- a/webkit2/gasyncreadycallback.go
+++ b/webkit2/gasyncreadycallback.go
@@ -25,6 +25,8 @@ func newGAsyncReadyCallback(f interface{}) (cCallback C.GAsyncReadyCallback, use
        if rf.Kind() != reflect.Func {
                return nil, nil, errors.New("f is not a function")
        }
-       cbinfo := &garCallback{rf}
+       data := C.malloc(C.size_t(unsafe.Sizeof(garCallback{})))
+       cbinfo := (*garCallback)(data)
+       cbinfo.f = rf
        return C.GAsyncReadyCallback(C._gasyncreadycallback_call), C.gpointer(unsafe.Pointer(cbinfo)), nil
 }
diff --git a/webkit2/webview.go b/webkit2/webview.go
index 8249757..5da804a 100644
--- a/webkit2/webview.go
+++ b/webkit2/webview.go
@@ -125,6 +125,7 @@ func (v *WebView) RunJavaScript(script string, resultCallback func(result *gojs.
        var err error
        if resultCallback != nil {
                callback := func(result *C.GAsyncResult) {
+                       C.free(unsafe.Pointer(userData))
                        var jserr *C.GError
                        jsResult := C.webkit_web_view_run_javascript_finish(v.webView, result, &jserr)
                        if jsResult == nil {

(And so forth)

@paultag
Copy link
Contributor Author

paultag commented Oct 7, 2016

Closed in #35

@paultag paultag closed this as completed Oct 7, 2016
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

1 participant