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

cmd/cgo: please provide a way to set errno from a callback #23890

Open
jech opened this Issue Feb 17, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@jech

jech commented Feb 17, 2018

I'm interfacing with a C library that expects callbacks to return -1 with errno set upon error. As far as I can tell, the only way to set errno in a go function is to call back into C:

void
set_errno(int e)
{
    errno = e;
}
//export callback
func callback(...)  C.int {
    ...
    C.set_errno(C.int(syscall.EAGAIN))
    return -1
    ...
}

This is in contrast with retrieving errno in Go using multiple return values, which I find elegant and Go-like. Please provide a similarly tasteful way to return from Go to C while setting errno.

@bradfitz

This comment has been minimized.

Member

bradfitz commented Feb 17, 2018

@ianlancetaylor ianlancetaylor changed the title from Cgo: please provide a way to set errno from a callback to cmd/cgo: please provide a way to set errno from a callback Feb 17, 2018

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Feb 17, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Feb 17, 2018

This is doable in principle--we could apply special handling to an //extern function that returns two values where the second one has type int, but it would be so rarely used that I don't think it's worth the additional complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment