Skip to content

Commit 8dcbe33

Browse files
authored
Merge pull request #2004 from xushiwei/q
mini spec: unsafe.SliceData/String/StringData
2 parents 86dcb88 + 18c73f3 commit 8dcbe33

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/spec-mini.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,4 +1976,12 @@ except that, as a special case, if `ptr` is `nil` and `len` is zero, `Slice` ret
19761976

19771977
The `len` argument must be of [integer type](#numeric-types) or an untyped [constant](#constants). 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](#run-time-panics) occurs.
19781978

1979+
The function `SliceData` returns a pointer to the underlying array of the `slice` argument. If the slice's capacity `cap(slice)` is not zero, that pointer is `&slice[:1][0]`. If slice is `nil`, the result is `nil`. Otherwise it is a non-nil pointer to an unspecified memory address.
1980+
1981+
The function `String` returns a `string` value whose underlying bytes start at `ptr` and whose length is `len`. The same requirements apply to the `ptr` and `len` argument as in the function `Slice`. If `len` is zero, the result is the empty string `""`. Since Go+ strings are immutable, the bytes passed to `String` must not be modified afterwards.
1982+
1983+
The function `StringData` returns a pointer to the underlying bytes of the `str` argument. 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.
1984+
1985+
### Size and alignment guarantees
1986+
19791987
TODO

0 commit comments

Comments
 (0)