Skip to content

Commit

Permalink
reflect: deprecate PtrTo
Browse files Browse the repository at this point in the history
Replace reflect.PtrTo with reflect.PointerTo

Fixes golang#59599

Change-Id: I49407193e2050543ef983cd637703acc682d9f51
  • Loading branch information
qiulaidongfeng committed Jul 22, 2023
1 parent 28ca813 commit 007cbbc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/next/59599.txt
@@ -0,0 +1 @@
pkg reflect, func PtrTo //deprecated
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/reflectdata/reflect.go
Expand Up @@ -1224,7 +1224,7 @@ func writeType(t *types.Type) *obj.LSym {
keep := base.Ctxt.Flag_dynlink
if !keep && t.Sym() == nil {
// For an unnamed type, we only need the link if the type can
// be created at run time by reflect.PtrTo and similar
// be created at run time by reflect.PointerTo and similar
// functions. If the type exists in the program, those
// functions must return the existing type structure rather
// than creating a new one.
Expand Down
2 changes: 1 addition & 1 deletion src/encoding/gob/decode.go
Expand Up @@ -656,7 +656,7 @@ func (dec *Decoder) decodeSlice(state *decoderState, value reflect.Value, elemOp
errorf("%s slice too big: %d elements of %d bytes", typ.Elem(), u, size)
}
if value.Cap() < n {
safe := saferio.SliceCap(reflect.Zero(reflect.PtrTo(typ.Elem())).Interface(), uint64(n))
safe := saferio.SliceCap(reflect.Zero(reflect.PointerTo(typ.Elem())).Interface(), uint64(n))
if safe < 0 {
errorf("%s slice too big: %d elements of %d bytes", typ.Elem(), u, size)
}
Expand Down
2 changes: 2 additions & 0 deletions src/reflect/type.go
Expand Up @@ -1171,6 +1171,8 @@ var ptrMap sync.Map // map[*rtype]*ptrType
//
// PtrTo is the old spelling of PointerTo.
// The two functions behave identically.
//
// Deprecated: Superseded by [PointerTo].
func PtrTo(t Type) Type { return PointerTo(t) }

// PointerTo returns the pointer type with element t.
Expand Down

0 comments on commit 007cbbc

Please sign in to comment.