diff options
author | Matthew Dempsky <mdempsky@google.com> | 2022-08-31 10:24:04 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2022-11-09 22:11:13 +0000 |
commit | 42768b4c265065df9b7faeb9df0301ef64b271a2 (patch) | |
tree | 701c40527774087ad0809280a60d73c4f2631962 /src/unsafe | |
parent | 739618945ef271793d608b587694ca1df353951d (diff) | |
download | go-git-42768b4c265065df9b7faeb9df0301ef64b271a2.tar.gz |
unsafe: add docs for SliceData, String, and StringData
Updates #53003.
Change-Id: I076d1eb4bd0580002ad8008f3ca213c5edc951ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/427095
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/unsafe')
-rw-r--r-- | src/unsafe/unsafe.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index 5051b3ee9f..2f4212a1ae 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -239,3 +239,31 @@ func Add(ptr Pointer, len IntegerType) Pointer // At run time, if len is negative, or if ptr is nil and len is not zero, // a run-time panic occurs. func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType + +// SliceData returns a pointer to the underlying array of the argument +// slice. +// - If cap(slice) > 0, SliceData returns &slice[:1][0]. +// - If slice == nil, SliceData returns nil. +// - Otherwise, SliceData returns a non-nil pointer to an +// unspecified memory address. +func SliceData(slice []ArbitraryType) *ArbitraryType + +// String returns a string value whose underlying bytes +// start at ptr and whose length is len. +// +// The len argument must be of integer type or an untyped constant. +// A constant len argument must be non-negative and representable by a value of type int; +// if it is an untyped constant it is given type int. +// At run time, if len is negative, or if ptr is nil and len is not zero, +// a run-time panic occurs. +// +// Since Go strings are immutable, the bytes passed to String +// must not be modified afterwards. +func String(ptr *byte, len IntegerType) string + +// StringData returns a pointer to the underlying bytes of str. +// For an empty string the return value is unspecified, and may be nil. +// +// Since Go strings are immutable, the bytes returned by StringData +// must not be modified. +func StringData(str string) *byte |