aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-10-25 23:00:56 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-10-26 14:24:17 +0000
commit283d8a3d53ac1c7e1d7e297497480bf0071b6300 (patch)
treece7ce589f19e3880f341703797da01ffede0ee05 /src/reflect
parenta2b8c186f616db92f9812e09fb2c44b0e753f8a7 (diff)
downloadgo-283d8a3d53ac1c7e1d7e297497480bf0071b6300.tar.gz
go-283d8a3d53ac1c7e1d7e297497480bf0071b6300.zip
all: use reflect.{Pointer,PointerTo}
Updates #47651 Updates #48665 Change-Id: I69a87b45a5cad7a07fbd855040cd9935cf874554 Reviewed-on: https://go-review.googlesource.com/c/go/+/358454 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/abi.go2
-rw-r--r--src/reflect/all_test.go32
-rw-r--r--src/reflect/deepequal.go8
-rw-r--r--src/reflect/tostring_test.go2
-rw-r--r--src/reflect/type.go2
-rw-r--r--src/reflect/value.go44
-rw-r--r--src/reflect/visiblefields.go2
7 files changed, 46 insertions, 46 deletions
diff --git a/src/reflect/abi.go b/src/reflect/abi.go
index 2ce7ca2615..28204b8193 100644
--- a/src/reflect/abi.go
+++ b/src/reflect/abi.go
@@ -198,7 +198,7 @@ func (a *abiSeq) addRcvr(rcvr *rtype) (*abiStep, bool) {
// complete register-assignment algorithm for the Go ABI.
func (a *abiSeq) regAssign(t *rtype, offset uintptr) bool {
switch t.Kind() {
- case UnsafePointer, Ptr, Chan, Map, Func:
+ case UnsafePointer, Pointer, Chan, Map, Func:
return a.assignIntN(offset, t.size, 1, 0b1)
case Bool, Int, Uint, Int8, Uint8, Int16, Uint16, Int32, Uint32, Uintptr:
return a.assignIntN(offset, t.size, 1, 0b0)
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 922998125b..725be28bf0 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -546,7 +546,7 @@ func TestCanSetField(t *testing.T) {
for _, tc := range tt.cases {
f := tt.val
for _, i := range tc.index {
- if f.Kind() == Ptr {
+ if f.Kind() == Pointer {
f = f.Elem()
}
if i == -1 {
@@ -1373,7 +1373,7 @@ func TestIsZero(t *testing.T) {
{(map[string]string)(nil), true},
{map[string]string{}, false},
{make(map[string]string), false},
- // Ptr
+ // Pointer
{(*func())(nil), true},
{(*int)(nil), true},
{new(int), false},
@@ -3313,20 +3313,20 @@ func TestPtrTo(t *testing.T) {
typ := TypeOf(z)
for i = 0; i < 100; i++ {
- typ = PtrTo(typ)
+ typ = PointerTo(typ)
}
for i = 0; i < 100; i++ {
typ = typ.Elem()
}
if typ != TypeOf(z) {
- t.Errorf("after 100 PtrTo and Elem, have %s, want %s", typ, TypeOf(z))
+ t.Errorf("after 100 PointerTo and Elem, have %s, want %s", typ, TypeOf(z))
}
}
func TestPtrToGC(t *testing.T) {
type T *uintptr
tt := TypeOf(T(nil))
- pt := PtrTo(tt)
+ pt := PointerTo(tt)
const n = 100
var x []interface{}
for i := 0; i < n; i++ {
@@ -3360,11 +3360,11 @@ func BenchmarkPtrTo(b *testing.B) {
}
b.ResetTimer()
- // Now benchmark calling PtrTo on it: we'll have to hit the ptrMap cache on
+ // Now benchmark calling PointerTo on it: we'll have to hit the ptrMap cache on
// every call.
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- PtrTo(t)
+ PointerTo(t)
}
})
}
@@ -4896,7 +4896,7 @@ func TestArrayOfDirectIface(t *testing.T) {
v1 := ValueOf(&i1).Elem()
p1 := v1.InterfaceData()[1]
- i2 := Zero(ArrayOf(1, PtrTo(TypeOf(int8(0))))).Interface()
+ i2 := Zero(ArrayOf(1, PointerTo(TypeOf(int8(0))))).Interface()
v2 := ValueOf(&i2).Elem()
p2 := v2.InterfaceData()[1]
@@ -4914,7 +4914,7 @@ func TestArrayOfDirectIface(t *testing.T) {
v1 := ValueOf(&i1).Elem()
p1 := v1.InterfaceData()[1]
- i2 := Zero(ArrayOf(0, PtrTo(TypeOf(int8(0))))).Interface()
+ i2 := Zero(ArrayOf(0, PointerTo(TypeOf(int8(0))))).Interface()
v2 := ValueOf(&i2).Elem()
p2 := v2.InterfaceData()[1]
@@ -5615,7 +5615,7 @@ func TestStructOfWithInterface(t *testing.T) {
},
{
name: "StructI",
- typ: PtrTo(TypeOf(StructI(want))),
+ typ: PointerTo(TypeOf(StructI(want))),
val: ValueOf(func() interface{} {
v := StructI(want)
return &v
@@ -5624,7 +5624,7 @@ func TestStructOfWithInterface(t *testing.T) {
},
{
name: "StructIPtr",
- typ: PtrTo(TypeOf(StructIPtr(want))),
+ typ: PointerTo(TypeOf(StructIPtr(want))),
val: ValueOf(func() interface{} {
v := StructIPtr(want)
return &v
@@ -5713,7 +5713,7 @@ func TestStructOfWithInterface(t *testing.T) {
fields := []StructField{{
Name: "StructIPtr",
Anonymous: true,
- Type: PtrTo(TypeOf(StructIPtr(want))),
+ Type: PointerTo(TypeOf(StructIPtr(want))),
}}
rt := StructOf(fields)
rv := New(rt).Elem()
@@ -5727,7 +5727,7 @@ func TestStructOfWithInterface(t *testing.T) {
fields = []StructField{{
Name: "SettableStruct",
Anonymous: true,
- Type: PtrTo(TypeOf(SettableStruct{})),
+ Type: PointerTo(TypeOf(SettableStruct{})),
}}
rt = StructOf(fields)
rv = New(rt).Elem()
@@ -5743,7 +5743,7 @@ func TestStructOfWithInterface(t *testing.T) {
{
Name: "SettableStruct",
Anonymous: true,
- Type: PtrTo(TypeOf(SettableStruct{})),
+ Type: PointerTo(TypeOf(SettableStruct{})),
},
{
Name: "EmptyStruct",
@@ -6959,7 +6959,7 @@ func TestGCBits(t *testing.T) {
verifyGCBits(t, MapOf(ArrayOf(10000, Tscalarptr), Tscalar), lit(1))
verifyGCBits(t, TypeOf((*[10000]Xscalar)(nil)), lit(1))
- verifyGCBits(t, PtrTo(ArrayOf(10000, Tscalar)), lit(1))
+ verifyGCBits(t, PointerTo(ArrayOf(10000, Tscalar)), lit(1))
verifyGCBits(t, TypeOf(([][10000]Xscalar)(nil)), lit(1))
verifyGCBits(t, SliceOf(ArrayOf(10000, Tscalar)), lit(1))
@@ -7028,7 +7028,7 @@ func TestTypeOfTypeOf(t *testing.T) {
check("ChanOf", ChanOf(BothDir, TypeOf(T{})))
check("FuncOf", FuncOf([]Type{TypeOf(T{})}, nil, false))
check("MapOf", MapOf(TypeOf(T{}), TypeOf(T{})))
- check("PtrTo", PtrTo(TypeOf(T{})))
+ check("PtrTo", PointerTo(TypeOf(T{})))
check("SliceOf", SliceOf(TypeOf(T{})))
}
diff --git a/src/reflect/deepequal.go b/src/reflect/deepequal.go
index 7f1ecb2809..b71504fa21 100644
--- a/src/reflect/deepequal.go
+++ b/src/reflect/deepequal.go
@@ -38,7 +38,7 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool {
// and it's safe and valid to get Value's internal pointer.
hard := func(v1, v2 Value) bool {
switch v1.Kind() {
- case Ptr:
+ case Pointer:
if v1.typ.ptrdata == 0 {
// go:notinheap pointers can't be cyclic.
// At least, all of our current uses of go:notinheap have
@@ -56,13 +56,13 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool {
}
if hard(v1, v2) {
- // For a Ptr or Map value, we need to check flagIndir,
+ // For a Pointer or Map value, we need to check flagIndir,
// which we do by calling the pointer method.
// For Slice or Interface, flagIndir is always set,
// and using v.ptr suffices.
ptrval := func(v Value) unsafe.Pointer {
switch v.Kind() {
- case Ptr, Map:
+ case Pointer, Map:
return v.pointer()
default:
return v.ptr
@@ -120,7 +120,7 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool {
return v1.IsNil() == v2.IsNil()
}
return deepValueEqual(v1.Elem(), v2.Elem(), visited)
- case Ptr:
+ case Pointer:
if v1.UnsafePointer() == v2.UnsafePointer() {
return true
}
diff --git a/src/reflect/tostring_test.go b/src/reflect/tostring_test.go
index e416fd84da..193484a01b 100644
--- a/src/reflect/tostring_test.go
+++ b/src/reflect/tostring_test.go
@@ -39,7 +39,7 @@ func valueToString(val Value) string {
} else {
return "false"
}
- case Ptr:
+ case Pointer:
v := val
str = typ.String() + "("
if v.IsNil() {
diff --git a/src/reflect/type.go b/src/reflect/type.go
index 96f589ca9c..2bb2438381 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -1425,7 +1425,7 @@ func TypeOf(i interface{}) Type {
var ptrMap sync.Map // map[*rtype]*ptrType
// PtrTo returns the pointer type with element t.
-// For example, if t represents type Foo, PtrTo(t) represents *Foo.
+// For example, if t represents type Foo, PointerTo(t) represents *Foo.
//
// Deprecated: use PointerTo. PtrTo is the old spelling.
// The two functions behave identically.
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 3e723e82a4..5d9964eb9d 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -90,8 +90,8 @@ func (f flag) ro() flag {
}
// pointer returns the underlying pointer represented by v.
-// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
-// if v.Kind() == Ptr, the base type must not be go:notinheap.
+// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
+// if v.Kind() == Pointer, the base type must not be go:notinheap.
func (v Value) pointer() unsafe.Pointer {
if v.typ.size != goarch.PtrSize || !v.typ.pointers() {
panic("can't call pointer on a non-pointer Value")
@@ -274,7 +274,7 @@ func (v Value) Addr() Value {
// Preserve flagRO instead of using v.flag.ro() so that
// v.Addr().Elem() is equivalent to v (#32772)
fl := v.flag & flagRO
- return Value{v.typ.ptrTo(), v.ptr, fl | flag(Ptr)}
+ return Value{v.typ.ptrTo(), v.ptr, fl | flag(Pointer)}
}
// Bool returns v's underlying value.
@@ -1147,7 +1147,7 @@ func (v Value) Complex() complex128 {
// Elem returns the value that the interface v contains
// or that the pointer v points to.
-// It panics if v's Kind is not Interface or Ptr.
+// It panics if v's Kind is not Interface or Pointer.
// It returns the zero Value if v is nil.
func (v Value) Elem() Value {
k := v.kind()
@@ -1166,7 +1166,7 @@ func (v Value) Elem() Value {
x.flag |= v.flag.ro()
}
return x
- case Ptr:
+ case Pointer:
ptr := v.ptr
if v.flag&flagIndir != 0 {
if ifaceIndir(v.typ) {
@@ -1240,7 +1240,7 @@ func (v Value) FieldByIndex(index []int) Value {
v.mustBe(Struct)
for i, x := range index {
if i > 0 {
- if v.Kind() == Ptr && v.typ.Elem().Kind() == Struct {
+ if v.Kind() == Pointer && v.typ.Elem().Kind() == Struct {
if v.IsNil() {
panic("reflect: indirection through nil pointer to embedded struct")
}
@@ -1321,7 +1321,7 @@ func (v Value) Index(i int) Value {
return Value{typ, val, fl}
case Slice:
- // Element flag same as Elem of Ptr.
+ // Element flag same as Elem of Pointer.
// Addressable, indirect, possibly read-only.
s := (*unsafeheader.Slice)(v.ptr)
if uint(i) >= uint(s.Len) {
@@ -1451,7 +1451,7 @@ func (v Value) InterfaceData() [2]uintptr {
func (v Value) IsNil() bool {
k := v.kind()
switch k {
- case Chan, Func, Map, Ptr, UnsafePointer:
+ case Chan, Func, Map, Pointer, UnsafePointer:
if v.flag&flagMethod != 0 {
return false
}
@@ -1499,7 +1499,7 @@ func (v Value) IsZero() bool {
}
}
return true
- case Chan, Func, Interface, Map, Ptr, Slice, UnsafePointer:
+ case Chan, Func, Interface, Map, Pointer, Slice, UnsafePointer:
return v.IsNil()
case String:
return v.Len() == 0
@@ -1923,7 +1923,7 @@ func (v Value) OverflowUint(x uint64) bool {
// It returns uintptr instead of unsafe.Pointer so that
// code using reflect cannot obtain unsafe.Pointers
// without importing the unsafe package explicitly.
-// It panics if v's Kind is not Chan, Func, Map, Ptr, Slice, or UnsafePointer.
+// It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
//
// If v's Kind is Func, the returned pointer is an underlying
// code pointer, but not necessarily enough to identify a
@@ -1938,7 +1938,7 @@ func (v Value) OverflowUint(x uint64) bool {
func (v Value) Pointer() uintptr {
k := v.kind()
switch k {
- case Ptr:
+ case Pointer:
if v.typ.ptrdata == 0 {
val := *(*uintptr)(v.ptr)
// Since it is a not-in-heap pointer, all pointers to the heap are
@@ -2491,7 +2491,7 @@ func (v Value) UnsafeAddr() uintptr {
}
// UnsafePointer returns v's value as a unsafe.Pointer.
-// It panics if v's Kind is not Chan, Func, Map, Ptr, Slice, or UnsafePointer.
+// It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
//
// If v's Kind is Func, the returned pointer is an underlying
// code pointer, but not necessarily enough to identify a
@@ -2504,7 +2504,7 @@ func (v Value) UnsafeAddr() uintptr {
func (v Value) UnsafePointer() unsafe.Pointer {
k := v.kind()
switch k {
- case Ptr:
+ case Pointer:
if v.typ.ptrdata == 0 {
// Since it is a not-in-heap pointer, all pointers to the heap are
// forbidden! See comment in Value.Elem and issue #48399.
@@ -2908,7 +2908,7 @@ func MakeMapWithSize(typ Type, n int) Value {
// If v is a nil pointer, Indirect returns a zero Value.
// If v is not a pointer, Indirect returns v.
func Indirect(v Value) Value {
- if v.Kind() != Ptr {
+ if v.Kind() != Pointer {
return v
}
return v.Elem()
@@ -2960,7 +2960,7 @@ const maxZero = 1024
var zeroVal [maxZero]byte
// New returns a Value representing a pointer to a new zero value
-// for the specified type. That is, the returned Value's Type is PtrTo(typ).
+// for the specified type. That is, the returned Value's Type is PointerTo(typ).
func New(typ Type) Value {
if typ == nil {
panic("reflect: New(nil)")
@@ -2972,14 +2972,14 @@ func New(typ Type) Value {
panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)")
}
ptr := unsafe_New(t)
- fl := flag(Ptr)
+ fl := flag(Pointer)
return Value{pt, ptr, fl}
}
// NewAt returns a Value representing a pointer to a value of the
// specified type, using p as that pointer.
func NewAt(typ Type, p unsafe.Pointer) Value {
- fl := flag(Ptr)
+ fl := flag(Pointer)
t := typ.(*rtype)
return Value{t.ptrTo(), p, fl}
}
@@ -3048,7 +3048,7 @@ func (v Value) CanConvert(t Type) bool {
// Currently the only conversion that is OK in terms of type
// but that can panic depending on the value is converting
// from slice to pointer-to-array.
- if vt.Kind() == Slice && t.Kind() == Ptr && t.Elem().Kind() == Array {
+ if vt.Kind() == Slice && t.Kind() == Pointer && t.Elem().Kind() == Array {
n := t.Elem().Len()
if n > v.Len() {
return false
@@ -3118,7 +3118,7 @@ func convertOp(dst, src *rtype) func(Value, Type) Value {
}
// "x is a slice, T is a pointer-to-array type,
// and the slice and array types have identical element types."
- if dst.Kind() == Ptr && dst.Elem().Kind() == Array && src.Elem() == dst.Elem().Elem() {
+ if dst.Kind() == Pointer && dst.Elem().Kind() == Array && src.Elem() == dst.Elem().Elem() {
return cvtSliceArrayPtr
}
@@ -3134,8 +3134,8 @@ func convertOp(dst, src *rtype) func(Value, Type) Value {
}
// dst and src are non-defined pointer types with same underlying base type.
- if dst.Kind() == Ptr && dst.Name() == "" &&
- src.Kind() == Ptr && src.Name() == "" &&
+ if dst.Kind() == Pointer && dst.Name() == "" &&
+ src.Kind() == Pointer && src.Name() == "" &&
haveIdenticalUnderlyingType(dst.Elem().common(), src.Elem().common(), false) {
return cvtDirect
}
@@ -3321,7 +3321,7 @@ func cvtSliceArrayPtr(v Value, t Type) Value {
panic("reflect: cannot convert slice with length " + itoa.Itoa(v.Len()) + " to pointer to array with length " + itoa.Itoa(n))
}
h := (*unsafeheader.Slice)(v.ptr)
- return Value{t.common(), h.Data, v.flag&^(flagIndir|flagAddr|flagKindMask) | flag(Ptr)}
+ return Value{t.common(), h.Data, v.flag&^(flagIndir|flagAddr|flagKindMask) | flag(Pointer)}
}
// convertOp: direct copy
diff --git a/src/reflect/visiblefields.go b/src/reflect/visiblefields.go
index 1a2b53570b..9375faa110 100644
--- a/src/reflect/visiblefields.go
+++ b/src/reflect/visiblefields.go
@@ -92,7 +92,7 @@ func (w *visibleFieldsWalker) walk(t Type) {
w.fields = append(w.fields, f)
}
if f.Anonymous {
- if f.Type.Kind() == Ptr {
+ if f.Type.Kind() == Pointer {
f.Type = f.Type.Elem()
}
if f.Type.Kind() == Struct {