deuill / go-php

PHP bindings for the Go programming language (Golang)
MIT License
930 stars 105 forks source link

Doesn't work in Go 1.6 #17

Closed dimaxgl closed 8 years ago

dimaxgl commented 8 years ago

I try to compile with Go 1.6rc1. Here is compiler output:

/usr/local/go/bin/go run -tags php7 /home/me/gocode/src/github.com/hello/world/src/embed_php7/main.go
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/deuill/go-php/engine._cgoCheckPointer0(0x69aec0, 0xc820012500, 0x0, 0x0, 0x0, 0x0)
    ??:0 +0x4d
github.com/deuill/go-php/engine.NewContext(0xc8200c0000, 0x0, 0x0)
    /home/me/gocode/src/github.com/deuill/go-php/engine/context.go:45 +0x152
github.com/deuill/go-php/engine.(*Engine).NewContext(0xc820016f60, 0x0, 0x0, 0x0)
    /home/me/gocode/src/github.com/deuill/go-php/engine/engine.go:53 +0x2e
main.main()
    /home/me/gocode/src/github.com/hello/world/src/embed_php7/main.go:10 +0x36
exit status 2
deuill commented 8 years ago

Ah, I feared this might be the case.

Currently, we use a somewhat "hacky" solution for having PHP write back to the Go context. We do so by instantiating a context.Context, then passing and storing the unsafe.Pointer down in the C context. When PHP wants to e.g. write something back to the user, we call an exported Go function and pass the context pointer, which is then used for writing to the correct context.

Go 1.6 makes passing pointers between Go and C a bit more strict (as per this proposal).

The solution to this would be to store contexts in a lookup table, and pass keys instead of direct references down to the C context. I'll see if I can fix this before 1.6 is released.

deuill commented 8 years ago

Started fixing this in #19, there are some issues related to Receivers which need some thinking-through before fixing.

deuill commented 8 years ago

Fixed in #19.