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

Go 1.6 - panic: runtime error: cgo argument has Go pointer to Go pointer #17

Closed
dzan opened this issue Mar 4, 2016 · 4 comments
Closed
Assignees

Comments

@dzan
Copy link

dzan commented Mar 4, 2016

Hi,

https://github.com/sbinet/go-clang/blob/master/cursor.go#L798

it seems like this line causes issues when passed a closure if building with go 1.6. Using GODEBUG=cgocheck=0 when running works but that's not really a good idea. Passing it a closure is the only way to actually pass arguments to your visitor I think, e.g.

// collectMatchKind collects all or one element name(s) in the sub AST-tree rooted at
// the provided cursor.
func collectMatchKind(entityCursor clang.Cursor, kind clang.CursorKind,
        collectAll bool) (names []string) {

        // Invoke the visitor with this closure.
        entityCursor.Visit(func(cursor, parent clang.Cursor) (
                status clang.ChildVisitResult) {

                if cursor.Kind() == kind {
                        names = append(names, cursor.DisplayName())
                        if !collectAll {
                                return clang.CVR_Break
                        }
                }
                return clang.CVR_Continue
        })
        return // named
}
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
panic(0x42247c0, 0xc82000eae0)
        /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
github.com/sbinet/go-clang._cgoCheckPointer0(0x41c8c80, 0xc82002c050, 0xc82000ead0, 0x1, 0x1, 0xc82002c048)
        ??:0 +0x4d
github.com/sbinet/go-clang.Cursor.Visit(0xb, 0x6e24080, 0x1, 0x6095c30, 0xc820014ec0, 0x4236f20)
        /Users/dzan/Source/go/src/github.com/sbinet/go-clang/cursor.go:798 +0x12f
main.collectMatchKind(0xb, 0x6e24080, 0x1, 0x6095c30, 0x28, 0x0, 0x0, 0x0)
@sbinet
Copy link
Owner

sbinet commented Mar 5, 2016

indeed, this needs to be fixed.
thanks for the report.

note to self: perhaps draw some inspiration from adg/notify@4268ed7 ?

@sbinet sbinet self-assigned this Mar 5, 2016
@justinfx
Copy link

justinfx commented Apr 4, 2016

Hi. I was about to post a new issue surrounding this exact problem, and saw this existing one. I too have the same need to collect results during the visit routines. Currently I have had to resort to using global state. I can't seem to find a combination that works, to enable me to associate any kind of unique state collection with a particular visit.

I've tried using a method on a struct that can store state and also a function closing over identifiers. But everything I try seems to end up with this same cgo pointer limitation. Is there a concrete example that anyone can post which allows even some form of managing unique state for a visit operation?

Thanks so much for this binding btw. Its enabled me to write an awesome codegen tool at work. I just want to be able to make the codegen tool work in parallel, but I can't solve this need to have multiple visitors running.

@doppioandante
Copy link
Contributor

doppioandante commented Sep 4, 2016

Hello, any update on this? How can I work around this?
Is it difficult to fix the bug?

@sbinet sbinet closed this as completed in 78d39fd Sep 5, 2016
@justinfx
Copy link

justinfx commented Sep 5, 2016

Awesome! Thanks for this.

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