Skip to content

Commit 42768b4

Browse files
committed
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 7396189 commit 42768b4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/unsafe/unsafe.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,31 @@ func Add(ptr Pointer, len IntegerType) Pointer
239239
// At run time, if len is negative, or if ptr is nil and len is not zero,
240240
// a run-time panic occurs.
241241
func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
242+
243+
// SliceData returns a pointer to the underlying array of the argument
244+
// slice.
245+
// - If cap(slice) > 0, SliceData returns &slice[:1][0].
246+
// - If slice == nil, SliceData returns nil.
247+
// - Otherwise, SliceData returns a non-nil pointer to an
248+
// unspecified memory address.
249+
func SliceData(slice []ArbitraryType) *ArbitraryType
250+
251+
// String returns a string value whose underlying bytes
252+
// start at ptr and whose length is len.
253+
//
254+
// The len argument must be of integer type or an untyped constant.
255+
// A constant len argument must be non-negative and representable by a value of type int;
256+
// if it is an untyped constant it is given type int.
257+
// At run time, if len is negative, or if ptr is nil and len is not zero,
258+
// a run-time panic occurs.
259+
//
260+
// Since Go strings are immutable, the bytes passed to String
261+
// must not be modified afterwards.
262+
func String(ptr *byte, len IntegerType) string
263+
264+
// StringData returns a pointer to the underlying bytes of str.
265+
// For an empty string the return value is unspecified, and may be nil.
266+
//
267+
// Since Go strings are immutable, the bytes returned by StringData
268+
// must not be modified.
269+
func StringData(str string) *byte

0 commit comments

Comments
 (0)