From d734203e393745626d2c705aaf433b210d86c241 Mon Sep 17 00:00:00 2001 From: hopehook Date: Fri, 9 Sep 2022 08:43:10 +0800 Subject: [PATCH] reflect: deprecate SliceHeader and StringHeader As discussed in CL 401434 there are substantial misuses of these in the wild, and they are a potential source of unsafety even for code that does not use them directly. Since proposal #53003 has already been implemented, now is the right time to deprecate reflect.{SliceHeader, StringHeader}. For #53003. Change-Id: I724cf46d4b22d2ed3cbf2b948e6aac5ee4bf0f6e Reviewed-on: https://go-review.googlesource.com/c/go/+/428757 Run-TryBot: hopehook TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Reviewed-by: Ian Lance Taylor Auto-Submit: Matthew Dempsky --- src/reflect/value.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/reflect/value.go b/src/reflect/value.go index 6830057d61..917a5a69c9 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -2742,6 +2742,8 @@ func (v Value) UnsafePointer() unsafe.Pointer { // Moreover, the Data field is not sufficient to guarantee the data // it references will not be garbage collected, so programs must keep // a separate, correctly typed pointer to the underlying data. +// +// Deprecated: Use unsafe.String or unsafe.StringData instead. type StringHeader struct { Data uintptr Len int @@ -2753,6 +2755,8 @@ type StringHeader struct { // Moreover, the Data field is not sufficient to guarantee the data // it references will not be garbage collected, so programs must keep // a separate, correctly typed pointer to the underlying data. +// +// Deprecated: Use unsafe.Slice or unsafe.SliceData instead. type SliceHeader struct { Data uintptr Len int