Skip to content

Commit

Permalink
reflect: deprecate (Slice|String)Header
Browse files Browse the repository at this point in the history
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.

We should either keep them as-is and document when/how they can be used
safely, or deprecate them so that uses will eventually die out.

After some discussion, it was decided to deprecate them outright.
Since the docs already mentioned that they may be unstable across
releases, it should be possible to get rid of them completely later on.

Change-Id: I3b75819409177b5a286c1e9861a2edb6fd1301b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/401434
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
  • Loading branch information
CAFxX authored and gopherbot committed May 18, 2022
1 parent 5f2fdbe commit bc2e961
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/go1.19.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
</dd>
</dl> <!-- os/exec -->

<dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt>
<dd>
<p><!-- CL 401434 -->
<a href="/pkg/strconv/#reflect.SliceHeader"></a><code>reflect.SliceHeader</code>
and <a href="/pkg/strconv/#reflect.StringHeader"></a><code>reflect.StringHeader</code>
are now deprecated, and their use should be avoided.
</p>
</dd>
</dl><!-- reflect -->

<dl id="runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
<dd>
<p><!-- https://go.dev/issue/51461 -->
Expand Down
6 changes: 6 additions & 0 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,9 @@ 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: this type should not be used, it exists only for
// backward compatibility.
type StringHeader struct {
Data uintptr
Len int
Expand All @@ -2671,6 +2674,9 @@ 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: this type should not be used, it exists only for
// backward compatibility.
type SliceHeader struct {
Data uintptr
Len int
Expand Down

0 comments on commit bc2e961

Please sign in to comment.