-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: cmd/cgo: change GoStringN, GoBytes to take C.size_t #61361
Comments
That proposed change would break the spirit of the Go 1 compatibility guarantee, so we're not going to do it. (The Go 1 compatibility guarantee doesn't cover cgo, but, we're still not going to gratuitously break existing code without a really good reason.) And though the issue is marked "Go 2", there isn't going to be a Go 2, and we aren't going to make a cgov2 for something like this. So I suggest a different proposal: // GoStringBigN is like GoStringN but for very large strings.
func GoStringBigN(*C.char, C.size_t)
// GoBytesBig is like GoBytes but for very large data.
func GoBytesBig(unsafe.Pointer, C.size_t) |
That would be fine with me. Alternatively, perhaps it would be possible to widen the argument types to accept both (e.g., |
C.size_t
in C.GoStringN()
and C.GoBytes()
C.size_t
in C.GoStringN()
and C.GoBytes()
I think we already provide too many In particular, these functions seem redundant with the recently-added func goStringN(p *C.char, n C.size_t) string {
return string(unsafe.Slice((*byte)(unsafe.Pointer(p)), n))
}
func goBytes(p unsafe.Pointer, n C.size_t) []byte {
return bytes.Clone(unsafe.Slice((*byte)(p), n))
} |
C.size_t
in C.GoStringN()
and C.GoBytes()
This proposal has been declined as infeasible. |
Proposal
Change the signature of
GoStringN(*C.char, C.int)
toGoStringN(*C.char, C.size_t)
, and similarly forGoBytes
. This would enable C->Go transfer of >2GB strings on most Go systems, and avoid a cast when wrapping C APIs that follow modern usage guidelines.This would also improve consistency with
_GoStringLen()
, which already returnssize_t
.Costs
All existing uses of
GoStringN()
would require a change (either removing or adding a typecast).The text was updated successfully, but these errors were encountered: