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
Closed

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

jbardin opened this issue Mar 16, 2016 · 4 comments

Comments

@jbardin
Copy link
Contributor

jbardin 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
Copy link
Contributor

Want to send in a CL?

@jbardin
Copy link
Contributor Author

jbardin 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
Copy link
Contributor

Yes.

@gopherbot
Copy link

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

@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
Development

No branches or pull requests

3 participants