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

bind: bad return type name in generated method if original returned type is pointer #81

Closed
ryszard opened this issue Feb 12, 2016 · 2 comments
Assignees
Labels

Comments

@ryszard
Copy link

ryszard commented Feb 12, 2016

If I run go bind on the following code:

package pygo

type Bar struct{}

type Foo struct{}

func (Bar) Foo() *Foo {
    return &Foo{}
}

I get the following error:

2016/02/12 14:58:50 work: /var/folders/00/158q8000h01000cxqpysvccm004n2x/T/gopy-437831770
/var/folders/00/158q8000h01000cxqpysvccm004n2x/T/gopy-437831770/pygo.go:182:54: unrecognized Go type cgo_type_Foo
/var/folders/00/158q8000h01000cxqpysvccm004n2x/T/gopy-437831770/pygo.go:182:54: unrecognized Go type cgo_type_Foo
2016/02/12 14:58:51 error dispatching command: exit status 1

In the generated source, the method looks like

//export cgo_func_pygo_Bar_Foo
func cgo_func_pygo_Bar_Foo(self cgo_type_pygo_Bar) ( cgo_type_Foo) {
    _gopy_000 := (*pygo.Bar)(unsafe.Pointer(self)).Foo()
    cgopy_incref(unsafe.Pointer(&_gopy_000))
    return cgo_type_Foo(unsafe.Pointer(&_gopy_000))
}

The returned type is cgo_type_Foo, while it should actually be cgo_type_pygo_Foo (which is defined later in the generated file).

The fact that it's a pointer to Foo is important:

func (Bar) Foo() Foo {
    return Foo{}
}

is generated fine.

@sbinet sbinet self-assigned this Feb 12, 2016
@sbinet sbinet added the bug label Feb 12, 2016
@ryszard
Copy link
Author

ryszard commented Feb 12, 2016

Oh, and there's no problem if it's a function that returns the pointer.

@rcoreilly
Copy link
Member

for old version, closing

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

No branches or pull requests

3 participants