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

cmd/cgo: could we add a C.CBytes function? #14838

Closed
jbardin opened this issue Mar 16, 2016 · 4 comments

Comments

@jbardin
Copy link
Contributor

commented Mar 16, 2016

Would it be possible to add func C.Cbytes([]byte) unsafe.Pointer to the cgo package?

I have copied the C.CString function, minus the added 0 byte a couple times, and this seems like it could be a useful addition. Granted it's only 3 lines to do the malloc and copy, but this would also serve as documentation for users needing to copy data into C.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 16, 2016

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 16, 2016

Want to send in a CL?

@jbardin

This comment has been minimized.

Copy link
Contributor Author

commented Mar 16, 2016

Sure, though I'm not quite as sure what to do with the cPrologGccgo. Should I use __go_open_array? Something like this:

void *_cgoPREFIX_Cfunc_CBytes(struct __go_open_array b) {
    char *p = malloc(b.__count);
    memmove(p, b.__data, b.__count);
    return p;
}
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 16, 2016

Yes.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 16, 2016

CL https://golang.org/cl/20762 mentions this issue.

@gopherbot gopherbot closed this in 5a34472 Mar 16, 2016

@golang golang locked and limited conversation to collaborators Mar 19, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.