From: Ian Lance Taylor Date: Thu, 1 Jul 2021 23:52:59 +0000 (-0700) Subject: spec, unsafe: clarify unsafe.Slice docs X-Git-Tag: go1.17rc1~15 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=743f03eeb0;p=gostls13.git spec, unsafe: clarify unsafe.Slice docs For #19367 Change-Id: If0ff8ddba3b6b48e2e198cf3653e73284c7572a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/332409 Trust: Ian Lance Taylor Reviewed-by: Matthew Dempsky Reviewed-by: Robert Griesemer Reviewed-by: Keith Randall --- diff --git a/doc/go_spec.html b/doc/go_spec.html index e0602418e8..ad21ffb1b8 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -6782,7 +6782,8 @@ The rules for valid uses of Pointer The function Slice returns a slice whose underlying array starts at ptr -and whose length and capacity are len: +and whose length and capacity are len. +Slice(ptr, len) is equivalent to

@@ -6790,7 +6791,8 @@ and whose length and capacity are len:
 

-As a special case, if ptr is nil and len is zero, +except that, as a special case, if ptr +is nil and len is zero, Slice returns nil.

diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index eaf72c9618..16e3890d0b 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -217,11 +217,13 @@ func Alignof(x ArbitraryType) uintptr func Add(ptr Pointer, len IntegerType) Pointer // The function Slice returns a slice whose underlying array starts at ptr -// and whose length and capacity are len: +// and whose length and capacity are len. +// Slice(ptr, len) is equivalent to // // (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] // -// As a special case, if ptr is nil and len is zero, Slice returns nil. +// except that, as a special case, if ptr is nil and len is zero, +// Slice returns nil. // // 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;