...
Run Format

Source file src/reflect/value.go

     1	// Copyright 2009 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package reflect
     6	
     7	import (
     8		"math"
     9		"runtime"
    10		"unsafe"
    11	)
    12	
    13	const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
    14	
    15	// Value is the reflection interface to a Go value.
    16	//
    17	// Not all methods apply to all kinds of values. Restrictions,
    18	// if any, are noted in the documentation for each method.
    19	// Use the Kind method to find out the kind of value before
    20	// calling kind-specific methods. Calling a method
    21	// inappropriate to the kind of type causes a run time panic.
    22	//
    23	// The zero Value represents no value.
    24	// Its IsValid method returns false, its Kind method returns Invalid,
    25	// its String method returns "<invalid Value>", and all other methods panic.
    26	// Most functions and methods never return an invalid value.
    27	// If one does, its documentation states the conditions explicitly.
    28	//
    29	// A Value can be used concurrently by multiple goroutines provided that
    30	// the underlying Go value can be used concurrently for the equivalent
    31	// direct operations.
    32	//
    33	// Using == on two Values does not compare the underlying values
    34	// they represent, but rather the contents of the Value structs.
    35	// To compare two Values, compare the results of the Interface method.
    36	type Value struct {
    37		// typ holds the type of the value represented by a Value.
    38		typ *rtype
    39	
    40		// Pointer-valued data or, if flagIndir is set, pointer to data.
    41		// Valid when either flagIndir is set or typ.pointers() is true.
    42		ptr unsafe.Pointer
    43	
    44		// flag holds metadata about the value.
    45		// The lowest bits are flag bits:
    46		//	- flagStickyRO: obtained via unexported not embedded field, so read-only
    47		//	- flagEmbedRO: obtained via unexported embedded field, so read-only
    48		//	- flagIndir: val holds a pointer to the data
    49		//	- flagAddr: v.CanAddr is true (implies flagIndir)
    50		//	- flagMethod: v is a method value.
    51		// The next five bits give the Kind of the value.
    52		// This repeats typ.Kind() except for method values.
    53		// The remaining 23+ bits give a method number for method values.
    54		// If flag.kind() != Func, code can assume that flagMethod is unset.
    55		// If ifaceIndir(typ), code can assume that flagIndir is set.
    56		flag
    57	
    58		// A method value represents a curried method invocation
    59		// like r.Read for some receiver r. The typ+val+flag bits describe
    60		// the receiver r, but the flag's Kind bits say Func (methods are
    61		// functions), and the top bits of the flag give the method number
    62		// in r's type's method table.
    63	}
    64	
    65	type flag uintptr
    66	
    67	const (
    68		flagKindWidth        = 5 // there are 27 kinds
    69		flagKindMask    flag = 1<<flagKindWidth - 1
    70		flagStickyRO    flag = 1 << 5
    71		flagEmbedRO     flag = 1 << 6
    72		flagIndir       flag = 1 << 7
    73		flagAddr        flag = 1 << 8
    74		flagMethod      flag = 1 << 9
    75		flagMethodShift      = 10
    76		flagRO          flag = flagStickyRO | flagEmbedRO
    77	)
    78	
    79	func (f flag) kind() Kind {
    80		return Kind(f & flagKindMask)
    81	}
    82	
    83	// pointer returns the underlying pointer represented by v.
    84	// v.Kind() must be Ptr, Map, Chan, Func, or UnsafePointer
    85	func (v Value) pointer() unsafe.Pointer {
    86		if v.typ.size != ptrSize || !v.typ.pointers() {
    87			panic("can't call pointer on a non-pointer Value")
    88		}
    89		if v.flag&flagIndir != 0 {
    90			return *(*unsafe.Pointer)(v.ptr)
    91		}
    92		return v.ptr
    93	}
    94	
    95	// packEface converts v to the empty interface.
    96	func packEface(v Value) interface{} {
    97		t := v.typ
    98		var i interface{}
    99		e := (*emptyInterface)(unsafe.Pointer(&i))
   100		// First, fill in the data portion of the interface.
   101		switch {
   102		case ifaceIndir(t):
   103			if v.flag&flagIndir == 0 {
   104				panic("bad indir")
   105			}
   106			// Value is indirect, and so is the interface we're making.
   107			ptr := v.ptr
   108			if v.flag&flagAddr != 0 {
   109				// TODO: pass safe boolean from valueInterface so
   110				// we don't need to copy if safe==true?
   111				c := unsafe_New(t)
   112				typedmemmove(t, c, ptr)
   113				ptr = c
   114			}
   115			e.word = ptr
   116		case v.flag&flagIndir != 0:
   117			// Value is indirect, but interface is direct. We need
   118			// to load the data at v.ptr into the interface data word.
   119			e.word = *(*unsafe.Pointer)(v.ptr)
   120		default:
   121			// Value is direct, and so is the interface.
   122			e.word = v.ptr
   123		}
   124		// Now, fill in the type portion. We're very careful here not
   125		// to have any operation between the e.word and e.typ assignments
   126		// that would let the garbage collector observe the partially-built
   127		// interface value.
   128		e.typ = t
   129		return i
   130	}
   131	
   132	// unpackEface converts the empty interface i to a Value.
   133	func unpackEface(i interface{}) Value {
   134		e := (*emptyInterface)(unsafe.Pointer(&i))
   135		// NOTE: don't read e.word until we know whether it is really a pointer or not.
   136		t := e.typ
   137		if t == nil {
   138			return Value{}
   139		}
   140		f := flag(t.Kind())
   141		if ifaceIndir(t) {
   142			f |= flagIndir
   143		}
   144		return Value{t, e.word, f}
   145	}
   146	
   147	// A ValueError occurs when a Value method is invoked on
   148	// a Value that does not support it. Such cases are documented
   149	// in the description of each method.
   150	type ValueError struct {
   151		Method string
   152		Kind   Kind
   153	}
   154	
   155	func (e *ValueError) Error() string {
   156		if e.Kind == 0 {
   157			return "reflect: call of " + e.Method + " on zero Value"
   158		}
   159		return "reflect: call of " + e.Method + " on " + e.Kind.String() + " Value"
   160	}
   161	
   162	// methodName returns the name of the calling method,
   163	// assumed to be two stack frames above.
   164	func methodName() string {
   165		pc, _, _, _ := runtime.Caller(2)
   166		f := runtime.FuncForPC(pc)
   167		if f == nil {
   168			return "unknown method"
   169		}
   170		return f.Name()
   171	}
   172	
   173	// emptyInterface is the header for an interface{} value.
   174	type emptyInterface struct {
   175		typ  *rtype
   176		word unsafe.Pointer
   177	}
   178	
   179	// nonEmptyInterface is the header for a interface value with methods.
   180	type nonEmptyInterface struct {
   181		// see ../runtime/iface.go:/Itab
   182		itab *struct {
   183			ityp   *rtype // static interface type
   184			typ    *rtype // dynamic concrete type
   185			link   unsafe.Pointer
   186			bad    int32
   187			unused int32
   188			fun    [100000]unsafe.Pointer // method table
   189		}
   190		word unsafe.Pointer
   191	}
   192	
   193	// mustBe panics if f's kind is not expected.
   194	// Making this a method on flag instead of on Value
   195	// (and embedding flag in Value) means that we can write
   196	// the very clear v.mustBe(Bool) and have it compile into
   197	// v.flag.mustBe(Bool), which will only bother to copy the
   198	// single important word for the receiver.
   199	func (f flag) mustBe(expected Kind) {
   200		if f.kind() != expected {
   201			panic(&ValueError{methodName(), f.kind()})
   202		}
   203	}
   204	
   205	// mustBeExported panics if f records that the value was obtained using
   206	// an unexported field.
   207	func (f flag) mustBeExported() {
   208		if f == 0 {
   209			panic(&ValueError{methodName(), 0})
   210		}
   211		if f&flagRO != 0 {
   212			panic("reflect: " + methodName() + " using value obtained using unexported field")
   213		}
   214	}
   215	
   216	// mustBeAssignable panics if f records that the value is not assignable,
   217	// which is to say that either it was obtained using an unexported field
   218	// or it is not addressable.
   219	func (f flag) mustBeAssignable() {
   220		if f == 0 {
   221			panic(&ValueError{methodName(), Invalid})
   222		}
   223		// Assignable if addressable and not read-only.
   224		if f&flagRO != 0 {
   225			panic("reflect: " + methodName() + " using value obtained using unexported field")
   226		}
   227		if f&flagAddr == 0 {
   228			panic("reflect: " + methodName() + " using unaddressable value")
   229		}
   230	}
   231	
   232	// Addr returns a pointer value representing the address of v.
   233	// It panics if CanAddr() returns false.
   234	// Addr is typically used to obtain a pointer to a struct field
   235	// or slice element in order to call a method that requires a
   236	// pointer receiver.
   237	func (v Value) Addr() Value {
   238		if v.flag&flagAddr == 0 {
   239			panic("reflect.Value.Addr of unaddressable value")
   240		}
   241		return Value{v.typ.ptrTo(), v.ptr, (v.flag & flagRO) | flag(Ptr)}
   242	}
   243	
   244	// Bool returns v's underlying value.
   245	// It panics if v's kind is not Bool.
   246	func (v Value) Bool() bool {
   247		v.mustBe(Bool)
   248		return *(*bool)(v.ptr)
   249	}
   250	
   251	// Bytes returns v's underlying value.
   252	// It panics if v's underlying value is not a slice of bytes.
   253	func (v Value) Bytes() []byte {
   254		v.mustBe(Slice)
   255		if v.typ.Elem().Kind() != Uint8 {
   256			panic("reflect.Value.Bytes of non-byte slice")
   257		}
   258		// Slice is always bigger than a word; assume flagIndir.
   259		return *(*[]byte)(v.ptr)
   260	}
   261	
   262	// runes returns v's underlying value.
   263	// It panics if v's underlying value is not a slice of runes (int32s).
   264	func (v Value) runes() []rune {
   265		v.mustBe(Slice)
   266		if v.typ.Elem().Kind() != Int32 {
   267			panic("reflect.Value.Bytes of non-rune slice")
   268		}
   269		// Slice is always bigger than a word; assume flagIndir.
   270		return *(*[]rune)(v.ptr)
   271	}
   272	
   273	// CanAddr reports whether the value's address can be obtained with Addr.
   274	// Such values are called addressable. A value is addressable if it is
   275	// an element of a slice, an element of an addressable array,
   276	// a field of an addressable struct, or the result of dereferencing a pointer.
   277	// If CanAddr returns false, calling Addr will panic.
   278	func (v Value) CanAddr() bool {
   279		return v.flag&flagAddr != 0
   280	}
   281	
   282	// CanSet reports whether the value of v can be changed.
   283	// A Value can be changed only if it is addressable and was not
   284	// obtained by the use of unexported struct fields.
   285	// If CanSet returns false, calling Set or any type-specific
   286	// setter (e.g., SetBool, SetInt) will panic.
   287	func (v Value) CanSet() bool {
   288		return v.flag&(flagAddr|flagRO) == flagAddr
   289	}
   290	
   291	// Call calls the function v with the input arguments in.
   292	// For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]).
   293	// Call panics if v's Kind is not Func.
   294	// It returns the output results as Values.
   295	// As in Go, each input argument must be assignable to the
   296	// type of the function's corresponding input parameter.
   297	// If v is a variadic function, Call creates the variadic slice parameter
   298	// itself, copying in the corresponding values.
   299	func (v Value) Call(in []Value) []Value {
   300		v.mustBe(Func)
   301		v.mustBeExported()
   302		return v.call("Call", in)
   303	}
   304	
   305	// CallSlice calls the variadic function v with the input arguments in,
   306	// assigning the slice in[len(in)-1] to v's final variadic argument.
   307	// For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
   308	// CallSlice panics if v's Kind is not Func or if v is not variadic.
   309	// It returns the output results as Values.
   310	// As in Go, each input argument must be assignable to the
   311	// type of the function's corresponding input parameter.
   312	func (v Value) CallSlice(in []Value) []Value {
   313		v.mustBe(Func)
   314		v.mustBeExported()
   315		return v.call("CallSlice", in)
   316	}
   317	
   318	var callGC bool // for testing; see TestCallMethodJump
   319	
   320	func (v Value) call(op string, in []Value) []Value {
   321		// Get function pointer, type.
   322		t := v.typ
   323		var (
   324			fn       unsafe.Pointer
   325			rcvr     Value
   326			rcvrtype *rtype
   327		)
   328		if v.flag&flagMethod != 0 {
   329			rcvr = v
   330			rcvrtype, t, fn = methodReceiver(op, v, int(v.flag)>>flagMethodShift)
   331		} else if v.flag&flagIndir != 0 {
   332			fn = *(*unsafe.Pointer)(v.ptr)
   333		} else {
   334			fn = v.ptr
   335		}
   336	
   337		if fn == nil {
   338			panic("reflect.Value.Call: call of nil function")
   339		}
   340	
   341		isSlice := op == "CallSlice"
   342		n := t.NumIn()
   343		if isSlice {
   344			if !t.IsVariadic() {
   345				panic("reflect: CallSlice of non-variadic function")
   346			}
   347			if len(in) < n {
   348				panic("reflect: CallSlice with too few input arguments")
   349			}
   350			if len(in) > n {
   351				panic("reflect: CallSlice with too many input arguments")
   352			}
   353		} else {
   354			if t.IsVariadic() {
   355				n--
   356			}
   357			if len(in) < n {
   358				panic("reflect: Call with too few input arguments")
   359			}
   360			if !t.IsVariadic() && len(in) > n {
   361				panic("reflect: Call with too many input arguments")
   362			}
   363		}
   364		for _, x := range in {
   365			if x.Kind() == Invalid {
   366				panic("reflect: " + op + " using zero Value argument")
   367			}
   368		}
   369		for i := 0; i < n; i++ {
   370			if xt, targ := in[i].Type(), t.In(i); !xt.AssignableTo(targ) {
   371				panic("reflect: " + op + " using " + xt.String() + " as type " + targ.String())
   372			}
   373		}
   374		if !isSlice && t.IsVariadic() {
   375			// prepare slice for remaining values
   376			m := len(in) - n
   377			slice := MakeSlice(t.In(n), m, m)
   378			elem := t.In(n).Elem()
   379			for i := 0; i < m; i++ {
   380				x := in[n+i]
   381				if xt := x.Type(); !xt.AssignableTo(elem) {
   382					panic("reflect: cannot use " + xt.String() + " as type " + elem.String() + " in " + op)
   383				}
   384				slice.Index(i).Set(x)
   385			}
   386			origIn := in
   387			in = make([]Value, n+1)
   388			copy(in[:n], origIn)
   389			in[n] = slice
   390		}
   391	
   392		nin := len(in)
   393		if nin != t.NumIn() {
   394			panic("reflect.Value.Call: wrong argument count")
   395		}
   396		nout := t.NumOut()
   397	
   398		// Compute frame type.
   399		frametype, _, retOffset, _, framePool := funcLayout(t, rcvrtype)
   400	
   401		// Allocate a chunk of memory for frame.
   402		var args unsafe.Pointer
   403		if nout == 0 {
   404			args = framePool.Get().(unsafe.Pointer)
   405		} else {
   406			// Can't use pool if the function has return values.
   407			// We will leak pointer to args in ret, so its lifetime is not scoped.
   408			args = unsafe_New(frametype)
   409		}
   410		off := uintptr(0)
   411	
   412		// Copy inputs into args.
   413		if rcvrtype != nil {
   414			storeRcvr(rcvr, args)
   415			off = ptrSize
   416		}
   417		for i, v := range in {
   418			v.mustBeExported()
   419			targ := t.In(i).(*rtype)
   420			a := uintptr(targ.align)
   421			off = (off + a - 1) &^ (a - 1)
   422			n := targ.size
   423			addr := unsafe.Pointer(uintptr(args) + off)
   424			v = v.assignTo("reflect.Value.Call", targ, addr)
   425			if v.flag&flagIndir != 0 {
   426				typedmemmove(targ, addr, v.ptr)
   427			} else {
   428				*(*unsafe.Pointer)(addr) = v.ptr
   429			}
   430			off += n
   431		}
   432	
   433		// Call.
   434		call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))
   435	
   436		// For testing; see TestCallMethodJump.
   437		if callGC {
   438			runtime.GC()
   439		}
   440	
   441		var ret []Value
   442		if nout == 0 {
   443			// This is untyped because the frame is really a
   444			// stack, even though it's a heap object.
   445			memclrNoHeapPointers(args, frametype.size)
   446			framePool.Put(args)
   447		} else {
   448			// Zero the now unused input area of args,
   449			// because the Values returned by this function contain pointers to the args object,
   450			// and will thus keep the args object alive indefinitely.
   451			memclrNoHeapPointers(args, retOffset)
   452			// Wrap Values around return values in args.
   453			ret = make([]Value, nout)
   454			off = retOffset
   455			for i := 0; i < nout; i++ {
   456				tv := t.Out(i)
   457				a := uintptr(tv.Align())
   458				off = (off + a - 1) &^ (a - 1)
   459				fl := flagIndir | flag(tv.Kind())
   460				ret[i] = Value{tv.common(), unsafe.Pointer(uintptr(args) + off), fl}
   461				off += tv.Size()
   462			}
   463		}
   464	
   465		return ret
   466	}
   467	
   468	// callReflect is the call implementation used by a function
   469	// returned by MakeFunc. In many ways it is the opposite of the
   470	// method Value.call above. The method above converts a call using Values
   471	// into a call of a function with a concrete argument frame, while
   472	// callReflect converts a call of a function with a concrete argument
   473	// frame into a call using Values.
   474	// It is in this file so that it can be next to the call method above.
   475	// The remainder of the MakeFunc implementation is in makefunc.go.
   476	//
   477	// NOTE: This function must be marked as a "wrapper" in the generated code,
   478	// so that the linker can make it work correctly for panic and recover.
   479	// The gc compilers know to do that for the name "reflect.callReflect".
   480	func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer) {
   481		ftyp := ctxt.typ
   482		f := ctxt.fn
   483	
   484		// Copy argument frame into Values.
   485		ptr := frame
   486		off := uintptr(0)
   487		in := make([]Value, 0, int(ftyp.inCount))
   488		for _, typ := range ftyp.in() {
   489			off += -off & uintptr(typ.align-1)
   490			addr := unsafe.Pointer(uintptr(ptr) + off)
   491			v := Value{typ, nil, flag(typ.Kind())}
   492			if ifaceIndir(typ) {
   493				// value cannot be inlined in interface data.
   494				// Must make a copy, because f might keep a reference to it,
   495				// and we cannot let f keep a reference to the stack frame
   496				// after this function returns, not even a read-only reference.
   497				v.ptr = unsafe_New(typ)
   498				typedmemmove(typ, v.ptr, addr)
   499				v.flag |= flagIndir
   500			} else {
   501				v.ptr = *(*unsafe.Pointer)(addr)
   502			}
   503			in = append(in, v)
   504			off += typ.size
   505		}
   506	
   507		// Call underlying function.
   508		out := f(in)
   509		numOut := ftyp.NumOut()
   510		if len(out) != numOut {
   511			panic("reflect: wrong return count from function created by MakeFunc")
   512		}
   513	
   514		// Copy results back into argument frame.
   515		if numOut > 0 {
   516			off += -off & (ptrSize - 1)
   517			if runtime.GOARCH == "amd64p32" {
   518				off = align(off, 8)
   519			}
   520			for i, typ := range ftyp.out() {
   521				v := out[i]
   522				if v.typ != typ {
   523					panic("reflect: function created by MakeFunc using " + funcName(f) +
   524						" returned wrong type: have " +
   525						out[i].typ.String() + " for " + typ.String())
   526				}
   527				if v.flag&flagRO != 0 {
   528					panic("reflect: function created by MakeFunc using " + funcName(f) +
   529						" returned value obtained from unexported field")
   530				}
   531				off += -off & uintptr(typ.align-1)
   532				addr := unsafe.Pointer(uintptr(ptr) + off)
   533				if v.flag&flagIndir != 0 {
   534					typedmemmove(typ, addr, v.ptr)
   535				} else {
   536					*(*unsafe.Pointer)(addr) = v.ptr
   537				}
   538				off += typ.size
   539			}
   540		}
   541	
   542		// runtime.getArgInfo expects to be able to find ctxt on the
   543		// stack when it finds our caller, makeFuncStub. Make sure it
   544		// doesn't get garbage collected.
   545		runtime.KeepAlive(ctxt)
   546	}
   547	
   548	// methodReceiver returns information about the receiver
   549	// described by v. The Value v may or may not have the
   550	// flagMethod bit set, so the kind cached in v.flag should
   551	// not be used.
   552	// The return value rcvrtype gives the method's actual receiver type.
   553	// The return value t gives the method type signature (without the receiver).
   554	// The return value fn is a pointer to the method code.
   555	func methodReceiver(op string, v Value, methodIndex int) (rcvrtype, t *rtype, fn unsafe.Pointer) {
   556		i := methodIndex
   557		if v.typ.Kind() == Interface {
   558			tt := (*interfaceType)(unsafe.Pointer(v.typ))
   559			if uint(i) >= uint(len(tt.methods)) {
   560				panic("reflect: internal error: invalid method index")
   561			}
   562			m := &tt.methods[i]
   563			if !tt.nameOff(m.name).isExported() {
   564				panic("reflect: " + op + " of unexported method")
   565			}
   566			iface := (*nonEmptyInterface)(v.ptr)
   567			if iface.itab == nil {
   568				panic("reflect: " + op + " of method on nil interface value")
   569			}
   570			rcvrtype = iface.itab.typ
   571			fn = unsafe.Pointer(&iface.itab.fun[i])
   572			t = tt.typeOff(m.typ)
   573		} else {
   574			rcvrtype = v.typ
   575			ut := v.typ.uncommon()
   576			if ut == nil || uint(i) >= uint(ut.mcount) {
   577				panic("reflect: internal error: invalid method index")
   578			}
   579			m := ut.methods()[i]
   580			if !v.typ.nameOff(m.name).isExported() {
   581				panic("reflect: " + op + " of unexported method")
   582			}
   583			ifn := v.typ.textOff(m.ifn)
   584			fn = unsafe.Pointer(&ifn)
   585			t = v.typ.typeOff(m.mtyp)
   586		}
   587		return
   588	}
   589	
   590	// v is a method receiver. Store at p the word which is used to
   591	// encode that receiver at the start of the argument list.
   592	// Reflect uses the "interface" calling convention for
   593	// methods, which always uses one word to record the receiver.
   594	func storeRcvr(v Value, p unsafe.Pointer) {
   595		t := v.typ
   596		if t.Kind() == Interface {
   597			// the interface data word becomes the receiver word
   598			iface := (*nonEmptyInterface)(v.ptr)
   599			*(*unsafe.Pointer)(p) = iface.word
   600		} else if v.flag&flagIndir != 0 && !ifaceIndir(t) {
   601			*(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(v.ptr)
   602		} else {
   603			*(*unsafe.Pointer)(p) = v.ptr
   604		}
   605	}
   606	
   607	// align returns the result of rounding x up to a multiple of n.
   608	// n must be a power of two.
   609	func align(x, n uintptr) uintptr {
   610		return (x + n - 1) &^ (n - 1)
   611	}
   612	
   613	// callMethod is the call implementation used by a function returned
   614	// by makeMethodValue (used by v.Method(i).Interface()).
   615	// It is a streamlined version of the usual reflect call: the caller has
   616	// already laid out the argument frame for us, so we don't have
   617	// to deal with individual Values for each argument.
   618	// It is in this file so that it can be next to the two similar functions above.
   619	// The remainder of the makeMethodValue implementation is in makefunc.go.
   620	//
   621	// NOTE: This function must be marked as a "wrapper" in the generated code,
   622	// so that the linker can make it work correctly for panic and recover.
   623	// The gc compilers know to do that for the name "reflect.callMethod".
   624	func callMethod(ctxt *methodValue, frame unsafe.Pointer) {
   625		rcvr := ctxt.rcvr
   626		rcvrtype, t, fn := methodReceiver("call", rcvr, ctxt.method)
   627		frametype, argSize, retOffset, _, framePool := funcLayout(t, rcvrtype)
   628	
   629		// Make a new frame that is one word bigger so we can store the receiver.
   630		args := framePool.Get().(unsafe.Pointer)
   631	
   632		// Copy in receiver and rest of args.
   633		// Avoid constructing out-of-bounds pointers if there are no args.
   634		storeRcvr(rcvr, args)
   635		if argSize-ptrSize > 0 {
   636			typedmemmovepartial(frametype, unsafe.Pointer(uintptr(args)+ptrSize), frame, ptrSize, argSize-ptrSize)
   637		}
   638	
   639		// Call.
   640		call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))
   641	
   642		// Copy return values. On amd64p32, the beginning of return values
   643		// is 64-bit aligned, so the caller's frame layout (which doesn't have
   644		// a receiver) is different from the layout of the fn call, which has
   645		// a receiver.
   646		// Ignore any changes to args and just copy return values.
   647		// Avoid constructing out-of-bounds pointers if there are no return values.
   648		if frametype.size-retOffset > 0 {
   649			callerRetOffset := retOffset - ptrSize
   650			if runtime.GOARCH == "amd64p32" {
   651				callerRetOffset = align(argSize-ptrSize, 8)
   652			}
   653			typedmemmovepartial(frametype,
   654				unsafe.Pointer(uintptr(frame)+callerRetOffset),
   655				unsafe.Pointer(uintptr(args)+retOffset),
   656				retOffset,
   657				frametype.size-retOffset)
   658		}
   659	
   660		// This is untyped because the frame is really a stack, even
   661		// though it's a heap object.
   662		memclrNoHeapPointers(args, frametype.size)
   663		framePool.Put(args)
   664	
   665		// See the comment in callReflect.
   666		runtime.KeepAlive(ctxt)
   667	}
   668	
   669	// funcName returns the name of f, for use in error messages.
   670	func funcName(f func([]Value) []Value) string {
   671		pc := *(*uintptr)(unsafe.Pointer(&f))
   672		rf := runtime.FuncForPC(pc)
   673		if rf != nil {
   674			return rf.Name()
   675		}
   676		return "closure"
   677	}
   678	
   679	// Cap returns v's capacity.
   680	// It panics if v's Kind is not Array, Chan, or Slice.
   681	func (v Value) Cap() int {
   682		k := v.kind()
   683		switch k {
   684		case Array:
   685			return v.typ.Len()
   686		case Chan:
   687			return chancap(v.pointer())
   688		case Slice:
   689			// Slice is always bigger than a word; assume flagIndir.
   690			return (*sliceHeader)(v.ptr).Cap
   691		}
   692		panic(&ValueError{"reflect.Value.Cap", v.kind()})
   693	}
   694	
   695	// Close closes the channel v.
   696	// It panics if v's Kind is not Chan.
   697	func (v Value) Close() {
   698		v.mustBe(Chan)
   699		v.mustBeExported()
   700		chanclose(v.pointer())
   701	}
   702	
   703	// Complex returns v's underlying value, as a complex128.
   704	// It panics if v's Kind is not Complex64 or Complex128
   705	func (v Value) Complex() complex128 {
   706		k := v.kind()
   707		switch k {
   708		case Complex64:
   709			return complex128(*(*complex64)(v.ptr))
   710		case Complex128:
   711			return *(*complex128)(v.ptr)
   712		}
   713		panic(&ValueError{"reflect.Value.Complex", v.kind()})
   714	}
   715	
   716	// Elem returns the value that the interface v contains
   717	// or that the pointer v points to.
   718	// It panics if v's Kind is not Interface or Ptr.
   719	// It returns the zero Value if v is nil.
   720	func (v Value) Elem() Value {
   721		k := v.kind()
   722		switch k {
   723		case Interface:
   724			var eface interface{}
   725			if v.typ.NumMethod() == 0 {
   726				eface = *(*interface{})(v.ptr)
   727			} else {
   728				eface = (interface{})(*(*interface {
   729					M()
   730				})(v.ptr))
   731			}
   732			x := unpackEface(eface)
   733			if x.flag != 0 {
   734				x.flag |= v.flag & flagRO
   735			}
   736			return x
   737		case Ptr:
   738			ptr := v.ptr
   739			if v.flag&flagIndir != 0 {
   740				ptr = *(*unsafe.Pointer)(ptr)
   741			}
   742			// The returned value's address is v's value.
   743			if ptr == nil {
   744				return Value{}
   745			}
   746			tt := (*ptrType)(unsafe.Pointer(v.typ))
   747			typ := tt.elem
   748			fl := v.flag&flagRO | flagIndir | flagAddr
   749			fl |= flag(typ.Kind())
   750			return Value{typ, ptr, fl}
   751		}
   752		panic(&ValueError{"reflect.Value.Elem", v.kind()})
   753	}
   754	
   755	// Field returns the i'th field of the struct v.
   756	// It panics if v's Kind is not Struct or i is out of range.
   757	func (v Value) Field(i int) Value {
   758		if v.kind() != Struct {
   759			panic(&ValueError{"reflect.Value.Field", v.kind()})
   760		}
   761		tt := (*structType)(unsafe.Pointer(v.typ))
   762		if uint(i) >= uint(len(tt.fields)) {
   763			panic("reflect: Field index out of range")
   764		}
   765		field := &tt.fields[i]
   766		typ := field.typ
   767	
   768		// Inherit permission bits from v, but clear flagEmbedRO.
   769		fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind())
   770		// Using an unexported field forces flagRO.
   771		if !field.name.isExported() {
   772			if field.name.name() == "" {
   773				fl |= flagEmbedRO
   774			} else {
   775				fl |= flagStickyRO
   776			}
   777		}
   778		// Either flagIndir is set and v.ptr points at struct,
   779		// or flagIndir is not set and v.ptr is the actual struct data.
   780		// In the former case, we want v.ptr + offset.
   781		// In the latter case, we must have field.offset = 0,
   782		// so v.ptr + field.offset is still okay.
   783		ptr := unsafe.Pointer(uintptr(v.ptr) + field.offset)
   784		return Value{typ, ptr, fl}
   785	}
   786	
   787	// FieldByIndex returns the nested field corresponding to index.
   788	// It panics if v's Kind is not struct.
   789	func (v Value) FieldByIndex(index []int) Value {
   790		if len(index) == 1 {
   791			return v.Field(index[0])
   792		}
   793		v.mustBe(Struct)
   794		for i, x := range index {
   795			if i > 0 {
   796				if v.Kind() == Ptr && v.typ.Elem().Kind() == Struct {
   797					if v.IsNil() {
   798						panic("reflect: indirection through nil pointer to embedded struct")
   799					}
   800					v = v.Elem()
   801				}
   802			}
   803			v = v.Field(x)
   804		}
   805		return v
   806	}
   807	
   808	// FieldByName returns the struct field with the given name.
   809	// It returns the zero Value if no field was found.
   810	// It panics if v's Kind is not struct.
   811	func (v Value) FieldByName(name string) Value {
   812		v.mustBe(Struct)
   813		if f, ok := v.typ.FieldByName(name); ok {
   814			return v.FieldByIndex(f.Index)
   815		}
   816		return Value{}
   817	}
   818	
   819	// FieldByNameFunc returns the struct field with a name
   820	// that satisfies the match function.
   821	// It panics if v's Kind is not struct.
   822	// It returns the zero Value if no field was found.
   823	func (v Value) FieldByNameFunc(match func(string) bool) Value {
   824		if f, ok := v.typ.FieldByNameFunc(match); ok {
   825			return v.FieldByIndex(f.Index)
   826		}
   827		return Value{}
   828	}
   829	
   830	// Float returns v's underlying value, as a float64.
   831	// It panics if v's Kind is not Float32 or Float64
   832	func (v Value) Float() float64 {
   833		k := v.kind()
   834		switch k {
   835		case Float32:
   836			return float64(*(*float32)(v.ptr))
   837		case Float64:
   838			return *(*float64)(v.ptr)
   839		}
   840		panic(&ValueError{"reflect.Value.Float", v.kind()})
   841	}
   842	
   843	var uint8Type = TypeOf(uint8(0)).(*rtype)
   844	
   845	// Index returns v's i'th element.
   846	// It panics if v's Kind is not Array, Slice, or String or i is out of range.
   847	func (v Value) Index(i int) Value {
   848		switch v.kind() {
   849		case Array:
   850			tt := (*arrayType)(unsafe.Pointer(v.typ))
   851			if uint(i) >= uint(tt.len) {
   852				panic("reflect: array index out of range")
   853			}
   854			typ := tt.elem
   855			offset := uintptr(i) * typ.size
   856	
   857			// Either flagIndir is set and v.ptr points at array,
   858			// or flagIndir is not set and v.ptr is the actual array data.
   859			// In the former case, we want v.ptr + offset.
   860			// In the latter case, we must be doing Index(0), so offset = 0,
   861			// so v.ptr + offset is still okay.
   862			val := unsafe.Pointer(uintptr(v.ptr) + offset)
   863			fl := v.flag&(flagRO|flagIndir|flagAddr) | flag(typ.Kind()) // bits same as overall array
   864			return Value{typ, val, fl}
   865	
   866		case Slice:
   867			// Element flag same as Elem of Ptr.
   868			// Addressable, indirect, possibly read-only.
   869			s := (*sliceHeader)(v.ptr)
   870			if uint(i) >= uint(s.Len) {
   871				panic("reflect: slice index out of range")
   872			}
   873			tt := (*sliceType)(unsafe.Pointer(v.typ))
   874			typ := tt.elem
   875			val := arrayAt(s.Data, i, typ.size)
   876			fl := flagAddr | flagIndir | v.flag&flagRO | flag(typ.Kind())
   877			return Value{typ, val, fl}
   878	
   879		case String:
   880			s := (*stringHeader)(v.ptr)
   881			if uint(i) >= uint(s.Len) {
   882				panic("reflect: string index out of range")
   883			}
   884			p := arrayAt(s.Data, i, 1)
   885			fl := v.flag&flagRO | flag(Uint8) | flagIndir
   886			return Value{uint8Type, p, fl}
   887		}
   888		panic(&ValueError{"reflect.Value.Index", v.kind()})
   889	}
   890	
   891	// Int returns v's underlying value, as an int64.
   892	// It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
   893	func (v Value) Int() int64 {
   894		k := v.kind()
   895		p := v.ptr
   896		switch k {
   897		case Int:
   898			return int64(*(*int)(p))
   899		case Int8:
   900			return int64(*(*int8)(p))
   901		case Int16:
   902			return int64(*(*int16)(p))
   903		case Int32:
   904			return int64(*(*int32)(p))
   905		case Int64:
   906			return *(*int64)(p)
   907		}
   908		panic(&ValueError{"reflect.Value.Int", v.kind()})
   909	}
   910	
   911	// CanInterface reports whether Interface can be used without panicking.
   912	func (v Value) CanInterface() bool {
   913		if v.flag == 0 {
   914			panic(&ValueError{"reflect.Value.CanInterface", Invalid})
   915		}
   916		return v.flag&flagRO == 0
   917	}
   918	
   919	// Interface returns v's current value as an interface{}.
   920	// It is equivalent to:
   921	//	var i interface{} = (v's underlying value)
   922	// It panics if the Value was obtained by accessing
   923	// unexported struct fields.
   924	func (v Value) Interface() (i interface{}) {
   925		return valueInterface(v, true)
   926	}
   927	
   928	func valueInterface(v Value, safe bool) interface{} {
   929		if v.flag == 0 {
   930			panic(&ValueError{"reflect.Value.Interface", 0})
   931		}
   932		if safe && v.flag&flagRO != 0 {
   933			// Do not allow access to unexported values via Interface,
   934			// because they might be pointers that should not be
   935			// writable or methods or function that should not be callable.
   936			panic("reflect.Value.Interface: cannot return value obtained from unexported field or method")
   937		}
   938		if v.flag&flagMethod != 0 {
   939			v = makeMethodValue("Interface", v)
   940		}
   941	
   942		if v.kind() == Interface {
   943			// Special case: return the element inside the interface.
   944			// Empty interface has one layout, all interfaces with
   945			// methods have a second layout.
   946			if v.NumMethod() == 0 {
   947				return *(*interface{})(v.ptr)
   948			}
   949			return *(*interface {
   950				M()
   951			})(v.ptr)
   952		}
   953	
   954		// TODO: pass safe to packEface so we don't need to copy if safe==true?
   955		return packEface(v)
   956	}
   957	
   958	// InterfaceData returns the interface v's value as a uintptr pair.
   959	// It panics if v's Kind is not Interface.
   960	func (v Value) InterfaceData() [2]uintptr {
   961		// TODO: deprecate this
   962		v.mustBe(Interface)
   963		// We treat this as a read operation, so we allow
   964		// it even for unexported data, because the caller
   965		// has to import "unsafe" to turn it into something
   966		// that can be abused.
   967		// Interface value is always bigger than a word; assume flagIndir.
   968		return *(*[2]uintptr)(v.ptr)
   969	}
   970	
   971	// IsNil reports whether its argument v is nil. The argument must be
   972	// a chan, func, interface, map, pointer, or slice value; if it is
   973	// not, IsNil panics. Note that IsNil is not always equivalent to a
   974	// regular comparison with nil in Go. For example, if v was created
   975	// by calling ValueOf with an uninitialized interface variable i,
   976	// i==nil will be true but v.IsNil will panic as v will be the zero
   977	// Value.
   978	func (v Value) IsNil() bool {
   979		k := v.kind()
   980		switch k {
   981		case Chan, Func, Map, Ptr:
   982			if v.flag&flagMethod != 0 {
   983				return false
   984			}
   985			ptr := v.ptr
   986			if v.flag&flagIndir != 0 {
   987				ptr = *(*unsafe.Pointer)(ptr)
   988			}
   989			return ptr == nil
   990		case Interface, Slice:
   991			// Both interface and slice are nil if first word is 0.
   992			// Both are always bigger than a word; assume flagIndir.
   993			return *(*unsafe.Pointer)(v.ptr) == nil
   994		}
   995		panic(&ValueError{"reflect.Value.IsNil", v.kind()})
   996	}
   997	
   998	// IsValid reports whether v represents a value.
   999	// It returns false if v is the zero Value.
  1000	// If IsValid returns false, all other methods except String panic.
  1001	// Most functions and methods never return an invalid value.
  1002	// If one does, its documentation states the conditions explicitly.
  1003	func (v Value) IsValid() bool {
  1004		return v.flag != 0
  1005	}
  1006	
  1007	// Kind returns v's Kind.
  1008	// If v is the zero Value (IsValid returns false), Kind returns Invalid.
  1009	func (v Value) Kind() Kind {
  1010		return v.kind()
  1011	}
  1012	
  1013	// Len returns v's length.
  1014	// It panics if v's Kind is not Array, Chan, Map, Slice, or String.
  1015	func (v Value) Len() int {
  1016		k := v.kind()
  1017		switch k {
  1018		case Array:
  1019			tt := (*arrayType)(unsafe.Pointer(v.typ))
  1020			return int(tt.len)
  1021		case Chan:
  1022			return chanlen(v.pointer())
  1023		case Map:
  1024			return maplen(v.pointer())
  1025		case Slice:
  1026			// Slice is bigger than a word; assume flagIndir.
  1027			return (*sliceHeader)(v.ptr).Len
  1028		case String:
  1029			// String is bigger than a word; assume flagIndir.
  1030			return (*stringHeader)(v.ptr).Len
  1031		}
  1032		panic(&ValueError{"reflect.Value.Len", v.kind()})
  1033	}
  1034	
  1035	// MapIndex returns the value associated with key in the map v.
  1036	// It panics if v's Kind is not Map.
  1037	// It returns the zero Value if key is not found in the map or if v represents a nil map.
  1038	// As in Go, the key's value must be assignable to the map's key type.
  1039	func (v Value) MapIndex(key Value) Value {
  1040		v.mustBe(Map)
  1041		tt := (*mapType)(unsafe.Pointer(v.typ))
  1042	
  1043		// Do not require key to be exported, so that DeepEqual
  1044		// and other programs can use all the keys returned by
  1045		// MapKeys as arguments to MapIndex. If either the map
  1046		// or the key is unexported, though, the result will be
  1047		// considered unexported. This is consistent with the
  1048		// behavior for structs, which allow read but not write
  1049		// of unexported fields.
  1050		key = key.assignTo("reflect.Value.MapIndex", tt.key, nil)
  1051	
  1052		var k unsafe.Pointer
  1053		if key.flag&flagIndir != 0 {
  1054			k = key.ptr
  1055		} else {
  1056			k = unsafe.Pointer(&key.ptr)
  1057		}
  1058		e := mapaccess(v.typ, v.pointer(), k)
  1059		if e == nil {
  1060			return Value{}
  1061		}
  1062		typ := tt.elem
  1063		fl := (v.flag | key.flag) & flagRO
  1064		fl |= flag(typ.Kind())
  1065		if ifaceIndir(typ) {
  1066			// Copy result so future changes to the map
  1067			// won't change the underlying value.
  1068			c := unsafe_New(typ)
  1069			typedmemmove(typ, c, e)
  1070			return Value{typ, c, fl | flagIndir}
  1071		} else {
  1072			return Value{typ, *(*unsafe.Pointer)(e), fl}
  1073		}
  1074	}
  1075	
  1076	// MapKeys returns a slice containing all the keys present in the map,
  1077	// in unspecified order.
  1078	// It panics if v's Kind is not Map.
  1079	// It returns an empty slice if v represents a nil map.
  1080	func (v Value) MapKeys() []Value {
  1081		v.mustBe(Map)
  1082		tt := (*mapType)(unsafe.Pointer(v.typ))
  1083		keyType := tt.key
  1084	
  1085		fl := v.flag&flagRO | flag(keyType.Kind())
  1086	
  1087		m := v.pointer()
  1088		mlen := int(0)
  1089		if m != nil {
  1090			mlen = maplen(m)
  1091		}
  1092		it := mapiterinit(v.typ, m)
  1093		a := make([]Value, mlen)
  1094		var i int
  1095		for i = 0; i < len(a); i++ {
  1096			key := mapiterkey(it)
  1097			if key == nil {
  1098				// Someone deleted an entry from the map since we
  1099				// called maplen above. It's a data race, but nothing
  1100				// we can do about it.
  1101				break
  1102			}
  1103			if ifaceIndir(keyType) {
  1104				// Copy result so future changes to the map
  1105				// won't change the underlying value.
  1106				c := unsafe_New(keyType)
  1107				typedmemmove(keyType, c, key)
  1108				a[i] = Value{keyType, c, fl | flagIndir}
  1109			} else {
  1110				a[i] = Value{keyType, *(*unsafe.Pointer)(key), fl}
  1111			}
  1112			mapiternext(it)
  1113		}
  1114		return a[:i]
  1115	}
  1116	
  1117	// Method returns a function value corresponding to v's i'th method.
  1118	// The arguments to a Call on the returned function should not include
  1119	// a receiver; the returned function will always use v as the receiver.
  1120	// Method panics if i is out of range or if v is a nil interface value.
  1121	func (v Value) Method(i int) Value {
  1122		if v.typ == nil {
  1123			panic(&ValueError{"reflect.Value.Method", Invalid})
  1124		}
  1125		if v.flag&flagMethod != 0 || uint(i) >= uint(v.typ.NumMethod()) {
  1126			panic("reflect: Method index out of range")
  1127		}
  1128		if v.typ.Kind() == Interface && v.IsNil() {
  1129			panic("reflect: Method on nil interface value")
  1130		}
  1131		fl := v.flag & (flagStickyRO | flagIndir) // Clear flagEmbedRO
  1132		fl |= flag(Func)
  1133		fl |= flag(i)<<flagMethodShift | flagMethod
  1134		return Value{v.typ, v.ptr, fl}
  1135	}
  1136	
  1137	// NumMethod returns the number of methods in the value's method set.
  1138	func (v Value) NumMethod() int {
  1139		if v.typ == nil {
  1140			panic(&ValueError{"reflect.Value.NumMethod", Invalid})
  1141		}
  1142		if v.flag&flagMethod != 0 {
  1143			return 0
  1144		}
  1145		return v.typ.NumMethod()
  1146	}
  1147	
  1148	// MethodByName returns a function value corresponding to the method
  1149	// of v with the given name.
  1150	// The arguments to a Call on the returned function should not include
  1151	// a receiver; the returned function will always use v as the receiver.
  1152	// It returns the zero Value if no method was found.
  1153	func (v Value) MethodByName(name string) Value {
  1154		if v.typ == nil {
  1155			panic(&ValueError{"reflect.Value.MethodByName", Invalid})
  1156		}
  1157		if v.flag&flagMethod != 0 {
  1158			return Value{}
  1159		}
  1160		m, ok := v.typ.MethodByName(name)
  1161		if !ok {
  1162			return Value{}
  1163		}
  1164		return v.Method(m.Index)
  1165	}
  1166	
  1167	// NumField returns the number of fields in the struct v.
  1168	// It panics if v's Kind is not Struct.
  1169	func (v Value) NumField() int {
  1170		v.mustBe(Struct)
  1171		tt := (*structType)(unsafe.Pointer(v.typ))
  1172		return len(tt.fields)
  1173	}
  1174	
  1175	// OverflowComplex reports whether the complex128 x cannot be represented by v's type.
  1176	// It panics if v's Kind is not Complex64 or Complex128.
  1177	func (v Value) OverflowComplex(x complex128) bool {
  1178		k := v.kind()
  1179		switch k {
  1180		case Complex64:
  1181			return overflowFloat32(real(x)) || overflowFloat32(imag(x))
  1182		case Complex128:
  1183			return false
  1184		}
  1185		panic(&ValueError{"reflect.Value.OverflowComplex", v.kind()})
  1186	}
  1187	
  1188	// OverflowFloat reports whether the float64 x cannot be represented by v's type.
  1189	// It panics if v's Kind is not Float32 or Float64.
  1190	func (v Value) OverflowFloat(x float64) bool {
  1191		k := v.kind()
  1192		switch k {
  1193		case Float32:
  1194			return overflowFloat32(x)
  1195		case Float64:
  1196			return false
  1197		}
  1198		panic(&ValueError{"reflect.Value.OverflowFloat", v.kind()})
  1199	}
  1200	
  1201	func overflowFloat32(x float64) bool {
  1202		if x < 0 {
  1203			x = -x
  1204		}
  1205		return math.MaxFloat32 < x && x <= math.MaxFloat64
  1206	}
  1207	
  1208	// OverflowInt reports whether the int64 x cannot be represented by v's type.
  1209	// It panics if v's Kind is not Int, Int8, int16, Int32, or Int64.
  1210	func (v Value) OverflowInt(x int64) bool {
  1211		k := v.kind()
  1212		switch k {
  1213		case Int, Int8, Int16, Int32, Int64:
  1214			bitSize := v.typ.size * 8
  1215			trunc := (x << (64 - bitSize)) >> (64 - bitSize)
  1216			return x != trunc
  1217		}
  1218		panic(&ValueError{"reflect.Value.OverflowInt", v.kind()})
  1219	}
  1220	
  1221	// OverflowUint reports whether the uint64 x cannot be represented by v's type.
  1222	// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
  1223	func (v Value) OverflowUint(x uint64) bool {
  1224		k := v.kind()
  1225		switch k {
  1226		case Uint, Uintptr, Uint8, Uint16, Uint32, Uint64:
  1227			bitSize := v.typ.size * 8
  1228			trunc := (x << (64 - bitSize)) >> (64 - bitSize)
  1229			return x != trunc
  1230		}
  1231		panic(&ValueError{"reflect.Value.OverflowUint", v.kind()})
  1232	}
  1233	
  1234	// Pointer returns v's value as a uintptr.
  1235	// It returns uintptr instead of unsafe.Pointer so that
  1236	// code using reflect cannot obtain unsafe.Pointers
  1237	// without importing the unsafe package explicitly.
  1238	// It panics if v's Kind is not Chan, Func, Map, Ptr, Slice, or UnsafePointer.
  1239	//
  1240	// If v's Kind is Func, the returned pointer is an underlying
  1241	// code pointer, but not necessarily enough to identify a
  1242	// single function uniquely. The only guarantee is that the
  1243	// result is zero if and only if v is a nil func Value.
  1244	//
  1245	// If v's Kind is Slice, the returned pointer is to the first
  1246	// element of the slice. If the slice is nil the returned value
  1247	// is 0.  If the slice is empty but non-nil the return value is non-zero.
  1248	func (v Value) Pointer() uintptr {
  1249		// TODO: deprecate
  1250		k := v.kind()
  1251		switch k {
  1252		case Chan, Map, Ptr, UnsafePointer:
  1253			return uintptr(v.pointer())
  1254		case Func:
  1255			if v.flag&flagMethod != 0 {
  1256				// As the doc comment says, the returned pointer is an
  1257				// underlying code pointer but not necessarily enough to
  1258				// identify a single function uniquely. All method expressions
  1259				// created via reflect have the same underlying code pointer,
  1260				// so their Pointers are equal. The function used here must
  1261				// match the one used in makeMethodValue.
  1262				f := methodValueCall
  1263				return **(**uintptr)(unsafe.Pointer(&f))
  1264			}
  1265			p := v.pointer()
  1266			// Non-nil func value points at data block.
  1267			// First word of data block is actual code.
  1268			if p != nil {
  1269				p = *(*unsafe.Pointer)(p)
  1270			}
  1271			return uintptr(p)
  1272	
  1273		case Slice:
  1274			return (*SliceHeader)(v.ptr).Data
  1275		}
  1276		panic(&ValueError{"reflect.Value.Pointer", v.kind()})
  1277	}
  1278	
  1279	// Recv receives and returns a value from the channel v.
  1280	// It panics if v's Kind is not Chan.
  1281	// The receive blocks until a value is ready.
  1282	// The boolean value ok is true if the value x corresponds to a send
  1283	// on the channel, false if it is a zero value received because the channel is closed.
  1284	func (v Value) Recv() (x Value, ok bool) {
  1285		v.mustBe(Chan)
  1286		v.mustBeExported()
  1287		return v.recv(false)
  1288	}
  1289	
  1290	// internal recv, possibly non-blocking (nb).
  1291	// v is known to be a channel.
  1292	func (v Value) recv(nb bool) (val Value, ok bool) {
  1293		tt := (*chanType)(unsafe.Pointer(v.typ))
  1294		if ChanDir(tt.dir)&RecvDir == 0 {
  1295			panic("reflect: recv on send-only channel")
  1296		}
  1297		t := tt.elem
  1298		val = Value{t, nil, flag(t.Kind())}
  1299		var p unsafe.Pointer
  1300		if ifaceIndir(t) {
  1301			p = unsafe_New(t)
  1302			val.ptr = p
  1303			val.flag |= flagIndir
  1304		} else {
  1305			p = unsafe.Pointer(&val.ptr)
  1306		}
  1307		selected, ok := chanrecv(v.typ, v.pointer(), nb, p)
  1308		if !selected {
  1309			val = Value{}
  1310		}
  1311		return
  1312	}
  1313	
  1314	// Send sends x on the channel v.
  1315	// It panics if v's kind is not Chan or if x's type is not the same type as v's element type.
  1316	// As in Go, x's value must be assignable to the channel's element type.
  1317	func (v Value) Send(x Value) {
  1318		v.mustBe(Chan)
  1319		v.mustBeExported()
  1320		v.send(x, false)
  1321	}
  1322	
  1323	// internal send, possibly non-blocking.
  1324	// v is known to be a channel.
  1325	func (v Value) send(x Value, nb bool) (selected bool) {
  1326		tt := (*chanType)(unsafe.Pointer(v.typ))
  1327		if ChanDir(tt.dir)&SendDir == 0 {
  1328			panic("reflect: send on recv-only channel")
  1329		}
  1330		x.mustBeExported()
  1331		x = x.assignTo("reflect.Value.Send", tt.elem, nil)
  1332		var p unsafe.Pointer
  1333		if x.flag&flagIndir != 0 {
  1334			p = x.ptr
  1335		} else {
  1336			p = unsafe.Pointer(&x.ptr)
  1337		}
  1338		return chansend(v.typ, v.pointer(), p, nb)
  1339	}
  1340	
  1341	// Set assigns x to the value v.
  1342	// It panics if CanSet returns false.
  1343	// As in Go, x's value must be assignable to v's type.
  1344	func (v Value) Set(x Value) {
  1345		v.mustBeAssignable()
  1346		x.mustBeExported() // do not let unexported x leak
  1347		var target unsafe.Pointer
  1348		if v.kind() == Interface {
  1349			target = v.ptr
  1350		}
  1351		x = x.assignTo("reflect.Set", v.typ, target)
  1352		if x.flag&flagIndir != 0 {
  1353			typedmemmove(v.typ, v.ptr, x.ptr)
  1354		} else {
  1355			*(*unsafe.Pointer)(v.ptr) = x.ptr
  1356		}
  1357	}
  1358	
  1359	// SetBool sets v's underlying value.
  1360	// It panics if v's Kind is not Bool or if CanSet() is false.
  1361	func (v Value) SetBool(x bool) {
  1362		v.mustBeAssignable()
  1363		v.mustBe(Bool)
  1364		*(*bool)(v.ptr) = x
  1365	}
  1366	
  1367	// SetBytes sets v's underlying value.
  1368	// It panics if v's underlying value is not a slice of bytes.
  1369	func (v Value) SetBytes(x []byte) {
  1370		v.mustBeAssignable()
  1371		v.mustBe(Slice)
  1372		if v.typ.Elem().Kind() != Uint8 {
  1373			panic("reflect.Value.SetBytes of non-byte slice")
  1374		}
  1375		*(*[]byte)(v.ptr) = x
  1376	}
  1377	
  1378	// setRunes sets v's underlying value.
  1379	// It panics if v's underlying value is not a slice of runes (int32s).
  1380	func (v Value) setRunes(x []rune) {
  1381		v.mustBeAssignable()
  1382		v.mustBe(Slice)
  1383		if v.typ.Elem().Kind() != Int32 {
  1384			panic("reflect.Value.setRunes of non-rune slice")
  1385		}
  1386		*(*[]rune)(v.ptr) = x
  1387	}
  1388	
  1389	// SetComplex sets v's underlying value to x.
  1390	// It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false.
  1391	func (v Value) SetComplex(x complex128) {
  1392		v.mustBeAssignable()
  1393		switch k := v.kind(); k {
  1394		default:
  1395			panic(&ValueError{"reflect.Value.SetComplex", v.kind()})
  1396		case Complex64:
  1397			*(*complex64)(v.ptr) = complex64(x)
  1398		case Complex128:
  1399			*(*complex128)(v.ptr) = x
  1400		}
  1401	}
  1402	
  1403	// SetFloat sets v's underlying value to x.
  1404	// It panics if v's Kind is not Float32 or Float64, or if CanSet() is false.
  1405	func (v Value) SetFloat(x float64) {
  1406		v.mustBeAssignable()
  1407		switch k := v.kind(); k {
  1408		default:
  1409			panic(&ValueError{"reflect.Value.SetFloat", v.kind()})
  1410		case Float32:
  1411			*(*float32)(v.ptr) = float32(x)
  1412		case Float64:
  1413			*(*float64)(v.ptr) = x
  1414		}
  1415	}
  1416	
  1417	// SetInt sets v's underlying value to x.
  1418	// It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false.
  1419	func (v Value) SetInt(x int64) {
  1420		v.mustBeAssignable()
  1421		switch k := v.kind(); k {
  1422		default:
  1423			panic(&ValueError{"reflect.Value.SetInt", v.kind()})
  1424		case Int:
  1425			*(*int)(v.ptr) = int(x)
  1426		case Int8:
  1427			*(*int8)(v.ptr) = int8(x)
  1428		case Int16:
  1429			*(*int16)(v.ptr) = int16(x)
  1430		case Int32:
  1431			*(*int32)(v.ptr) = int32(x)
  1432		case Int64:
  1433			*(*int64)(v.ptr) = x
  1434		}
  1435	}
  1436	
  1437	// SetLen sets v's length to n.
  1438	// It panics if v's Kind is not Slice or if n is negative or
  1439	// greater than the capacity of the slice.
  1440	func (v Value) SetLen(n int) {
  1441		v.mustBeAssignable()
  1442		v.mustBe(Slice)
  1443		s := (*sliceHeader)(v.ptr)
  1444		if uint(n) > uint(s.Cap) {
  1445			panic("reflect: slice length out of range in SetLen")
  1446		}
  1447		s.Len = n
  1448	}
  1449	
  1450	// SetCap sets v's capacity to n.
  1451	// It panics if v's Kind is not Slice or if n is smaller than the length or
  1452	// greater than the capacity of the slice.
  1453	func (v Value) SetCap(n int) {
  1454		v.mustBeAssignable()
  1455		v.mustBe(Slice)
  1456		s := (*sliceHeader)(v.ptr)
  1457		if n < s.Len || n > s.Cap {
  1458			panic("reflect: slice capacity out of range in SetCap")
  1459		}
  1460		s.Cap = n
  1461	}
  1462	
  1463	// SetMapIndex sets the value associated with key in the map v to val.
  1464	// It panics if v's Kind is not Map.
  1465	// If val is the zero Value, SetMapIndex deletes the key from the map.
  1466	// Otherwise if v holds a nil map, SetMapIndex will panic.
  1467	// As in Go, key's value must be assignable to the map's key type,
  1468	// and val's value must be assignable to the map's value type.
  1469	func (v Value) SetMapIndex(key, val Value) {
  1470		v.mustBe(Map)
  1471		v.mustBeExported()
  1472		key.mustBeExported()
  1473		tt := (*mapType)(unsafe.Pointer(v.typ))
  1474		key = key.assignTo("reflect.Value.SetMapIndex", tt.key, nil)
  1475		var k unsafe.Pointer
  1476		if key.flag&flagIndir != 0 {
  1477			k = key.ptr
  1478		} else {
  1479			k = unsafe.Pointer(&key.ptr)
  1480		}
  1481		if val.typ == nil {
  1482			mapdelete(v.typ, v.pointer(), k)
  1483			return
  1484		}
  1485		val.mustBeExported()
  1486		val = val.assignTo("reflect.Value.SetMapIndex", tt.elem, nil)
  1487		var e unsafe.Pointer
  1488		if val.flag&flagIndir != 0 {
  1489			e = val.ptr
  1490		} else {
  1491			e = unsafe.Pointer(&val.ptr)
  1492		}
  1493		mapassign(v.typ, v.pointer(), k, e)
  1494	}
  1495	
  1496	// SetUint sets v's underlying value to x.
  1497	// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64, or if CanSet() is false.
  1498	func (v Value) SetUint(x uint64) {
  1499		v.mustBeAssignable()
  1500		switch k := v.kind(); k {
  1501		default:
  1502			panic(&ValueError{"reflect.Value.SetUint", v.kind()})
  1503		case Uint:
  1504			*(*uint)(v.ptr) = uint(x)
  1505		case Uint8:
  1506			*(*uint8)(v.ptr) = uint8(x)
  1507		case Uint16:
  1508			*(*uint16)(v.ptr) = uint16(x)
  1509		case Uint32:
  1510			*(*uint32)(v.ptr) = uint32(x)
  1511		case Uint64:
  1512			*(*uint64)(v.ptr) = x
  1513		case Uintptr:
  1514			*(*uintptr)(v.ptr) = uintptr(x)
  1515		}
  1516	}
  1517	
  1518	// SetPointer sets the unsafe.Pointer value v to x.
  1519	// It panics if v's Kind is not UnsafePointer.
  1520	func (v Value) SetPointer(x unsafe.Pointer) {
  1521		v.mustBeAssignable()
  1522		v.mustBe(UnsafePointer)
  1523		*(*unsafe.Pointer)(v.ptr) = x
  1524	}
  1525	
  1526	// SetString sets v's underlying value to x.
  1527	// It panics if v's Kind is not String or if CanSet() is false.
  1528	func (v Value) SetString(x string) {
  1529		v.mustBeAssignable()
  1530		v.mustBe(String)
  1531		*(*string)(v.ptr) = x
  1532	}
  1533	
  1534	// Slice returns v[i:j].
  1535	// It panics if v's Kind is not Array, Slice or String, or if v is an unaddressable array,
  1536	// or if the indexes are out of bounds.
  1537	func (v Value) Slice(i, j int) Value {
  1538		var (
  1539			cap  int
  1540			typ  *sliceType
  1541			base unsafe.Pointer
  1542		)
  1543		switch kind := v.kind(); kind {
  1544		default:
  1545			panic(&ValueError{"reflect.Value.Slice", v.kind()})
  1546	
  1547		case Array:
  1548			if v.flag&flagAddr == 0 {
  1549				panic("reflect.Value.Slice: slice of unaddressable array")
  1550			}
  1551			tt := (*arrayType)(unsafe.Pointer(v.typ))
  1552			cap = int(tt.len)
  1553			typ = (*sliceType)(unsafe.Pointer(tt.slice))
  1554			base = v.ptr
  1555	
  1556		case Slice:
  1557			typ = (*sliceType)(unsafe.Pointer(v.typ))
  1558			s := (*sliceHeader)(v.ptr)
  1559			base = s.Data
  1560			cap = s.Cap
  1561	
  1562		case String:
  1563			s := (*stringHeader)(v.ptr)
  1564			if i < 0 || j < i || j > s.Len {
  1565				panic("reflect.Value.Slice: string slice index out of bounds")
  1566			}
  1567			t := stringHeader{arrayAt(s.Data, i, 1), j - i}
  1568			return Value{v.typ, unsafe.Pointer(&t), v.flag}
  1569		}
  1570	
  1571		if i < 0 || j < i || j > cap {
  1572			panic("reflect.Value.Slice: slice index out of bounds")
  1573		}
  1574	
  1575		// Declare slice so that gc can see the base pointer in it.
  1576		var x []unsafe.Pointer
  1577	
  1578		// Reinterpret as *sliceHeader to edit.
  1579		s := (*sliceHeader)(unsafe.Pointer(&x))
  1580		s.Len = j - i
  1581		s.Cap = cap - i
  1582		if cap-i > 0 {
  1583			s.Data = arrayAt(base, i, typ.elem.Size())
  1584		} else {
  1585			// do not advance pointer, to avoid pointing beyond end of slice
  1586			s.Data = base
  1587		}
  1588	
  1589		fl := v.flag&flagRO | flagIndir | flag(Slice)
  1590		return Value{typ.common(), unsafe.Pointer(&x), fl}
  1591	}
  1592	
  1593	// Slice3 is the 3-index form of the slice operation: it returns v[i:j:k].
  1594	// It panics if v's Kind is not Array or Slice, or if v is an unaddressable array,
  1595	// or if the indexes are out of bounds.
  1596	func (v Value) Slice3(i, j, k int) Value {
  1597		var (
  1598			cap  int
  1599			typ  *sliceType
  1600			base unsafe.Pointer
  1601		)
  1602		switch kind := v.kind(); kind {
  1603		default:
  1604			panic(&ValueError{"reflect.Value.Slice3", v.kind()})
  1605	
  1606		case Array:
  1607			if v.flag&flagAddr == 0 {
  1608				panic("reflect.Value.Slice3: slice of unaddressable array")
  1609			}
  1610			tt := (*arrayType)(unsafe.Pointer(v.typ))
  1611			cap = int(tt.len)
  1612			typ = (*sliceType)(unsafe.Pointer(tt.slice))
  1613			base = v.ptr
  1614	
  1615		case Slice:
  1616			typ = (*sliceType)(unsafe.Pointer(v.typ))
  1617			s := (*sliceHeader)(v.ptr)
  1618			base = s.Data
  1619			cap = s.Cap
  1620		}
  1621	
  1622		if i < 0 || j < i || k < j || k > cap {
  1623			panic("reflect.Value.Slice3: slice index out of bounds")
  1624		}
  1625	
  1626		// Declare slice so that the garbage collector
  1627		// can see the base pointer in it.
  1628		var x []unsafe.Pointer
  1629	
  1630		// Reinterpret as *sliceHeader to edit.
  1631		s := (*sliceHeader)(unsafe.Pointer(&x))
  1632		s.Len = j - i
  1633		s.Cap = k - i
  1634		if k-i > 0 {
  1635			s.Data = arrayAt(base, i, typ.elem.Size())
  1636		} else {
  1637			// do not advance pointer, to avoid pointing beyond end of slice
  1638			s.Data = base
  1639		}
  1640	
  1641		fl := v.flag&flagRO | flagIndir | flag(Slice)
  1642		return Value{typ.common(), unsafe.Pointer(&x), fl}
  1643	}
  1644	
  1645	// String returns the string v's underlying value, as a string.
  1646	// String is a special case because of Go's String method convention.
  1647	// Unlike the other getters, it does not panic if v's Kind is not String.
  1648	// Instead, it returns a string of the form "<T value>" where T is v's type.
  1649	// The fmt package treats Values specially. It does not call their String
  1650	// method implicitly but instead prints the concrete values they hold.
  1651	func (v Value) String() string {
  1652		switch k := v.kind(); k {
  1653		case Invalid:
  1654			return "<invalid Value>"
  1655		case String:
  1656			return *(*string)(v.ptr)
  1657		}
  1658		// If you call String on a reflect.Value of other type, it's better to
  1659		// print something than to panic. Useful in debugging.
  1660		return "<" + v.Type().String() + " Value>"
  1661	}
  1662	
  1663	// TryRecv attempts to receive a value from the channel v but will not block.
  1664	// It panics if v's Kind is not Chan.
  1665	// If the receive delivers a value, x is the transferred value and ok is true.
  1666	// If the receive cannot finish without blocking, x is the zero Value and ok is false.
  1667	// If the channel is closed, x is the zero value for the channel's element type and ok is false.
  1668	func (v Value) TryRecv() (x Value, ok bool) {
  1669		v.mustBe(Chan)
  1670		v.mustBeExported()
  1671		return v.recv(true)
  1672	}
  1673	
  1674	// TrySend attempts to send x on the channel v but will not block.
  1675	// It panics if v's Kind is not Chan.
  1676	// It reports whether the value was sent.
  1677	// As in Go, x's value must be assignable to the channel's element type.
  1678	func (v Value) TrySend(x Value) bool {
  1679		v.mustBe(Chan)
  1680		v.mustBeExported()
  1681		return v.send(x, true)
  1682	}
  1683	
  1684	// Type returns v's type.
  1685	func (v Value) Type() Type {
  1686		f := v.flag
  1687		if f == 0 {
  1688			panic(&ValueError{"reflect.Value.Type", Invalid})
  1689		}
  1690		if f&flagMethod == 0 {
  1691			// Easy case
  1692			return v.typ
  1693		}
  1694	
  1695		// Method value.
  1696		// v.typ describes the receiver, not the method type.
  1697		i := int(v.flag) >> flagMethodShift
  1698		if v.typ.Kind() == Interface {
  1699			// Method on interface.
  1700			tt := (*interfaceType)(unsafe.Pointer(v.typ))
  1701			if uint(i) >= uint(len(tt.methods)) {
  1702				panic("reflect: internal error: invalid method index")
  1703			}
  1704			m := &tt.methods[i]
  1705			return v.typ.typeOff(m.typ)
  1706		}
  1707		// Method on concrete type.
  1708		ut := v.typ.uncommon()
  1709		if ut == nil || uint(i) >= uint(ut.mcount) {
  1710			panic("reflect: internal error: invalid method index")
  1711		}
  1712		m := ut.methods()[i]
  1713		return v.typ.typeOff(m.mtyp)
  1714	}
  1715	
  1716	// Uint returns v's underlying value, as a uint64.
  1717	// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
  1718	func (v Value) Uint() uint64 {
  1719		k := v.kind()
  1720		p := v.ptr
  1721		switch k {
  1722		case Uint:
  1723			return uint64(*(*uint)(p))
  1724		case Uint8:
  1725			return uint64(*(*uint8)(p))
  1726		case Uint16:
  1727			return uint64(*(*uint16)(p))
  1728		case Uint32:
  1729			return uint64(*(*uint32)(p))
  1730		case Uint64:
  1731			return *(*uint64)(p)
  1732		case Uintptr:
  1733			return uint64(*(*uintptr)(p))
  1734		}
  1735		panic(&ValueError{"reflect.Value.Uint", v.kind()})
  1736	}
  1737	
  1738	// UnsafeAddr returns a pointer to v's data.
  1739	// It is for advanced clients that also import the "unsafe" package.
  1740	// It panics if v is not addressable.
  1741	func (v Value) UnsafeAddr() uintptr {
  1742		// TODO: deprecate
  1743		if v.typ == nil {
  1744			panic(&ValueError{"reflect.Value.UnsafeAddr", Invalid})
  1745		}
  1746		if v.flag&flagAddr == 0 {
  1747			panic("reflect.Value.UnsafeAddr of unaddressable value")
  1748		}
  1749		return uintptr(v.ptr)
  1750	}
  1751	
  1752	// StringHeader is the runtime representation of a string.
  1753	// It cannot be used safely or portably and its representation may
  1754	// change in a later release.
  1755	// Moreover, the Data field is not sufficient to guarantee the data
  1756	// it references will not be garbage collected, so programs must keep
  1757	// a separate, correctly typed pointer to the underlying data.
  1758	type StringHeader struct {
  1759		Data uintptr
  1760		Len  int
  1761	}
  1762	
  1763	// stringHeader is a safe version of StringHeader used within this package.
  1764	type stringHeader struct {
  1765		Data unsafe.Pointer
  1766		Len  int
  1767	}
  1768	
  1769	// SliceHeader is the runtime representation of a slice.
  1770	// It cannot be used safely or portably and its representation may
  1771	// change in a later release.
  1772	// Moreover, the Data field is not sufficient to guarantee the data
  1773	// it references will not be garbage collected, so programs must keep
  1774	// a separate, correctly typed pointer to the underlying data.
  1775	type SliceHeader struct {
  1776		Data uintptr
  1777		Len  int
  1778		Cap  int
  1779	}
  1780	
  1781	// sliceHeader is a safe version of SliceHeader used within this package.
  1782	type sliceHeader struct {
  1783		Data unsafe.Pointer
  1784		Len  int
  1785		Cap  int
  1786	}
  1787	
  1788	func typesMustMatch(what string, t1, t2 Type) {
  1789		if t1 != t2 {
  1790			panic(what + ": " + t1.String() + " != " + t2.String())
  1791		}
  1792	}
  1793	
  1794	// arrayAt returns the i-th element of p, a C-array whose elements are
  1795	// eltSize wide (in bytes).
  1796	func arrayAt(p unsafe.Pointer, i int, eltSize uintptr) unsafe.Pointer {
  1797		return unsafe.Pointer(uintptr(p) + uintptr(i)*eltSize)
  1798	}
  1799	
  1800	// grow grows the slice s so that it can hold extra more values, allocating
  1801	// more capacity if needed. It also returns the old and new slice lengths.
  1802	func grow(s Value, extra int) (Value, int, int) {
  1803		i0 := s.Len()
  1804		i1 := i0 + extra
  1805		if i1 < i0 {
  1806			panic("reflect.Append: slice overflow")
  1807		}
  1808		m := s.Cap()
  1809		if i1 <= m {
  1810			return s.Slice(0, i1), i0, i1
  1811		}
  1812		if m == 0 {
  1813			m = extra
  1814		} else {
  1815			for m < i1 {
  1816				if i0 < 1024 {
  1817					m += m
  1818				} else {
  1819					m += m / 4
  1820				}
  1821			}
  1822		}
  1823		t := MakeSlice(s.Type(), i1, m)
  1824		Copy(t, s)
  1825		return t, i0, i1
  1826	}
  1827	
  1828	// Append appends the values x to a slice s and returns the resulting slice.
  1829	// As in Go, each x's value must be assignable to the slice's element type.
  1830	func Append(s Value, x ...Value) Value {
  1831		s.mustBe(Slice)
  1832		s, i0, i1 := grow(s, len(x))
  1833		for i, j := i0, 0; i < i1; i, j = i+1, j+1 {
  1834			s.Index(i).Set(x[j])
  1835		}
  1836		return s
  1837	}
  1838	
  1839	// AppendSlice appends a slice t to a slice s and returns the resulting slice.
  1840	// The slices s and t must have the same element type.
  1841	func AppendSlice(s, t Value) Value {
  1842		s.mustBe(Slice)
  1843		t.mustBe(Slice)
  1844		typesMustMatch("reflect.AppendSlice", s.Type().Elem(), t.Type().Elem())
  1845		s, i0, i1 := grow(s, t.Len())
  1846		Copy(s.Slice(i0, i1), t)
  1847		return s
  1848	}
  1849	
  1850	// Copy copies the contents of src into dst until either
  1851	// dst has been filled or src has been exhausted.
  1852	// It returns the number of elements copied.
  1853	// Dst and src each must have kind Slice or Array, and
  1854	// dst and src must have the same element type.
  1855	func Copy(dst, src Value) int {
  1856		dk := dst.kind()
  1857		if dk != Array && dk != Slice {
  1858			panic(&ValueError{"reflect.Copy", dk})
  1859		}
  1860		if dk == Array {
  1861			dst.mustBeAssignable()
  1862		}
  1863		dst.mustBeExported()
  1864	
  1865		sk := src.kind()
  1866		if sk != Array && sk != Slice {
  1867			panic(&ValueError{"reflect.Copy", sk})
  1868		}
  1869		src.mustBeExported()
  1870	
  1871		de := dst.typ.Elem()
  1872		se := src.typ.Elem()
  1873		typesMustMatch("reflect.Copy", de, se)
  1874	
  1875		var ds, ss sliceHeader
  1876		if dk == Array {
  1877			ds.Data = dst.ptr
  1878			ds.Len = dst.Len()
  1879			ds.Cap = ds.Len
  1880		} else {
  1881			ds = *(*sliceHeader)(dst.ptr)
  1882		}
  1883		if sk == Array {
  1884			ss.Data = src.ptr
  1885			ss.Len = src.Len()
  1886			ss.Cap = ss.Len
  1887		} else {
  1888			ss = *(*sliceHeader)(src.ptr)
  1889		}
  1890	
  1891		return typedslicecopy(de.common(), ds, ss)
  1892	}
  1893	
  1894	// A runtimeSelect is a single case passed to rselect.
  1895	// This must match ../runtime/select.go:/runtimeSelect
  1896	type runtimeSelect struct {
  1897		dir SelectDir      // SelectSend, SelectRecv or SelectDefault
  1898		typ *rtype         // channel type
  1899		ch  unsafe.Pointer // channel
  1900		val unsafe.Pointer // ptr to data (SendDir) or ptr to receive buffer (RecvDir)
  1901	}
  1902	
  1903	// rselect runs a select. It returns the index of the chosen case.
  1904	// If the case was a receive, val is filled in with the received value.
  1905	// The conventional OK bool indicates whether the receive corresponds
  1906	// to a sent value.
  1907	//go:noescape
  1908	func rselect([]runtimeSelect) (chosen int, recvOK bool)
  1909	
  1910	// A SelectDir describes the communication direction of a select case.
  1911	type SelectDir int
  1912	
  1913	// NOTE: These values must match ../runtime/select.go:/selectDir.
  1914	
  1915	const (
  1916		_             SelectDir = iota
  1917		SelectSend              // case Chan <- Send
  1918		SelectRecv              // case <-Chan:
  1919		SelectDefault           // default
  1920	)
  1921	
  1922	// A SelectCase describes a single case in a select operation.
  1923	// The kind of case depends on Dir, the communication direction.
  1924	//
  1925	// If Dir is SelectDefault, the case represents a default case.
  1926	// Chan and Send must be zero Values.
  1927	//
  1928	// If Dir is SelectSend, the case represents a send operation.
  1929	// Normally Chan's underlying value must be a channel, and Send's underlying value must be
  1930	// assignable to the channel's element type. As a special case, if Chan is a zero Value,
  1931	// then the case is ignored, and the field Send will also be ignored and may be either zero
  1932	// or non-zero.
  1933	//
  1934	// If Dir is SelectRecv, the case represents a receive operation.
  1935	// Normally Chan's underlying value must be a channel and Send must be a zero Value.
  1936	// If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
  1937	// When a receive operation is selected, the received Value is returned by Select.
  1938	//
  1939	type SelectCase struct {
  1940		Dir  SelectDir // direction of case
  1941		Chan Value     // channel to use (for send or receive)
  1942		Send Value     // value to send (for send)
  1943	}
  1944	
  1945	// Select executes a select operation described by the list of cases.
  1946	// Like the Go select statement, it blocks until at least one of the cases
  1947	// can proceed, makes a uniform pseudo-random choice,
  1948	// and then executes that case. It returns the index of the chosen case
  1949	// and, if that case was a receive operation, the value received and a
  1950	// boolean indicating whether the value corresponds to a send on the channel
  1951	// (as opposed to a zero value received because the channel is closed).
  1952	func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool) {
  1953		// NOTE: Do not trust that caller is not modifying cases data underfoot.
  1954		// The range is safe because the caller cannot modify our copy of the len
  1955		// and each iteration makes its own copy of the value c.
  1956		runcases := make([]runtimeSelect, len(cases))
  1957		haveDefault := false
  1958		for i, c := range cases {
  1959			rc := &runcases[i]
  1960			rc.dir = c.Dir
  1961			switch c.Dir {
  1962			default:
  1963				panic("reflect.Select: invalid Dir")
  1964	
  1965			case SelectDefault: // default
  1966				if haveDefault {
  1967					panic("reflect.Select: multiple default cases")
  1968				}
  1969				haveDefault = true
  1970				if c.Chan.IsValid() {
  1971					panic("reflect.Select: default case has Chan value")
  1972				}
  1973				if c.Send.IsValid() {
  1974					panic("reflect.Select: default case has Send value")
  1975				}
  1976	
  1977			case SelectSend:
  1978				ch := c.Chan
  1979				if !ch.IsValid() {
  1980					break
  1981				}
  1982				ch.mustBe(Chan)
  1983				ch.mustBeExported()
  1984				tt := (*chanType)(unsafe.Pointer(ch.typ))
  1985				if ChanDir(tt.dir)&SendDir == 0 {
  1986					panic("reflect.Select: SendDir case using recv-only channel")
  1987				}
  1988				rc.ch = ch.pointer()
  1989				rc.typ = &tt.rtype
  1990				v := c.Send
  1991				if !v.IsValid() {
  1992					panic("reflect.Select: SendDir case missing Send value")
  1993				}
  1994				v.mustBeExported()
  1995				v = v.assignTo("reflect.Select", tt.elem, nil)
  1996				if v.flag&flagIndir != 0 {
  1997					rc.val = v.ptr
  1998				} else {
  1999					rc.val = unsafe.Pointer(&v.ptr)
  2000				}
  2001	
  2002			case SelectRecv:
  2003				if c.Send.IsValid() {
  2004					panic("reflect.Select: RecvDir case has Send value")
  2005				}
  2006				ch := c.Chan
  2007				if !ch.IsValid() {
  2008					break
  2009				}
  2010				ch.mustBe(Chan)
  2011				ch.mustBeExported()
  2012				tt := (*chanType)(unsafe.Pointer(ch.typ))
  2013				if ChanDir(tt.dir)&RecvDir == 0 {
  2014					panic("reflect.Select: RecvDir case using send-only channel")
  2015				}
  2016				rc.ch = ch.pointer()
  2017				rc.typ = &tt.rtype
  2018				rc.val = unsafe_New(tt.elem)
  2019			}
  2020		}
  2021	
  2022		chosen, recvOK = rselect(runcases)
  2023		if runcases[chosen].dir == SelectRecv {
  2024			tt := (*chanType)(unsafe.Pointer(runcases[chosen].typ))
  2025			t := tt.elem
  2026			p := runcases[chosen].val
  2027			fl := flag(t.Kind())
  2028			if ifaceIndir(t) {
  2029				recv = Value{t, p, fl | flagIndir}
  2030			} else {
  2031				recv = Value{t, *(*unsafe.Pointer)(p), fl}
  2032			}
  2033		}
  2034		return chosen, recv, recvOK
  2035	}
  2036	
  2037	/*
  2038	 * constructors
  2039	 */
  2040	
  2041	// implemented in package runtime
  2042	func unsafe_New(*rtype) unsafe.Pointer
  2043	func unsafe_NewArray(*rtype, int) unsafe.Pointer
  2044	
  2045	// MakeSlice creates a new zero-initialized slice value
  2046	// for the specified slice type, length, and capacity.
  2047	func MakeSlice(typ Type, len, cap int) Value {
  2048		if typ.Kind() != Slice {
  2049			panic("reflect.MakeSlice of non-slice type")
  2050		}
  2051		if len < 0 {
  2052			panic("reflect.MakeSlice: negative len")
  2053		}
  2054		if cap < 0 {
  2055			panic("reflect.MakeSlice: negative cap")
  2056		}
  2057		if len > cap {
  2058			panic("reflect.MakeSlice: len > cap")
  2059		}
  2060	
  2061		s := sliceHeader{unsafe_NewArray(typ.Elem().(*rtype), cap), len, cap}
  2062		return Value{typ.common(), unsafe.Pointer(&s), flagIndir | flag(Slice)}
  2063	}
  2064	
  2065	// MakeChan creates a new channel with the specified type and buffer size.
  2066	func MakeChan(typ Type, buffer int) Value {
  2067		if typ.Kind() != Chan {
  2068			panic("reflect.MakeChan of non-chan type")
  2069		}
  2070		if buffer < 0 {
  2071			panic("reflect.MakeChan: negative buffer size")
  2072		}
  2073		if typ.ChanDir() != BothDir {
  2074			panic("reflect.MakeChan: unidirectional channel type")
  2075		}
  2076		ch := makechan(typ.(*rtype), uint64(buffer))
  2077		return Value{typ.common(), ch, flag(Chan)}
  2078	}
  2079	
  2080	// MakeMap creates a new map of the specified type.
  2081	func MakeMap(typ Type) Value {
  2082		if typ.Kind() != Map {
  2083			panic("reflect.MakeMap of non-map type")
  2084		}
  2085		m := makemap(typ.(*rtype))
  2086		return Value{typ.common(), m, flag(Map)}
  2087	}
  2088	
  2089	// Indirect returns the value that v points to.
  2090	// If v is a nil pointer, Indirect returns a zero Value.
  2091	// If v is not a pointer, Indirect returns v.
  2092	func Indirect(v Value) Value {
  2093		if v.Kind() != Ptr {
  2094			return v
  2095		}
  2096		return v.Elem()
  2097	}
  2098	
  2099	// ValueOf returns a new Value initialized to the concrete value
  2100	// stored in the interface i. ValueOf(nil) returns the zero Value.
  2101	func ValueOf(i interface{}) Value {
  2102		if i == nil {
  2103			return Value{}
  2104		}
  2105	
  2106		// TODO: Maybe allow contents of a Value to live on the stack.
  2107		// For now we make the contents always escape to the heap. It
  2108		// makes life easier in a few places (see chanrecv/mapassign
  2109		// comment below).
  2110		escapes(i)
  2111	
  2112		return unpackEface(i)
  2113	}
  2114	
  2115	// Zero returns a Value representing the zero value for the specified type.
  2116	// The result is different from the zero value of the Value struct,
  2117	// which represents no value at all.
  2118	// For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0.
  2119	// The returned value is neither addressable nor settable.
  2120	func Zero(typ Type) Value {
  2121		if typ == nil {
  2122			panic("reflect: Zero(nil)")
  2123		}
  2124		t := typ.common()
  2125		fl := flag(t.Kind())
  2126		if ifaceIndir(t) {
  2127			return Value{t, unsafe_New(typ.(*rtype)), fl | flagIndir}
  2128		}
  2129		return Value{t, nil, fl}
  2130	}
  2131	
  2132	// New returns a Value representing a pointer to a new zero value
  2133	// for the specified type. That is, the returned Value's Type is PtrTo(typ).
  2134	func New(typ Type) Value {
  2135		if typ == nil {
  2136			panic("reflect: New(nil)")
  2137		}
  2138		ptr := unsafe_New(typ.(*rtype))
  2139		fl := flag(Ptr)
  2140		return Value{typ.common().ptrTo(), ptr, fl}
  2141	}
  2142	
  2143	// NewAt returns a Value representing a pointer to a value of the
  2144	// specified type, using p as that pointer.
  2145	func NewAt(typ Type, p unsafe.Pointer) Value {
  2146		fl := flag(Ptr)
  2147		return Value{typ.common().ptrTo(), p, fl}
  2148	}
  2149	
  2150	// assignTo returns a value v that can be assigned directly to typ.
  2151	// It panics if v is not assignable to typ.
  2152	// For a conversion to an interface type, target is a suggested scratch space to use.
  2153	func (v Value) assignTo(context string, dst *rtype, target unsafe.Pointer) Value {
  2154		if v.flag&flagMethod != 0 {
  2155			v = makeMethodValue(context, v)
  2156		}
  2157	
  2158		switch {
  2159		case directlyAssignable(dst, v.typ):
  2160			// Overwrite type so that they match.
  2161			// Same memory layout, so no harm done.
  2162			v.typ = dst
  2163			fl := v.flag & (flagRO | flagAddr | flagIndir)
  2164			fl |= flag(dst.Kind())
  2165			return Value{dst, v.ptr, fl}
  2166	
  2167		case implements(dst, v.typ):
  2168			if target == nil {
  2169				target = unsafe_New(dst)
  2170			}
  2171			x := valueInterface(v, false)
  2172			if dst.NumMethod() == 0 {
  2173				*(*interface{})(target) = x
  2174			} else {
  2175				ifaceE2I(dst, x, target)
  2176			}
  2177			return Value{dst, target, flagIndir | flag(Interface)}
  2178		}
  2179	
  2180		// Failed.
  2181		panic(context + ": value of type " + v.typ.String() + " is not assignable to type " + dst.String())
  2182	}
  2183	
  2184	// Convert returns the value v converted to type t.
  2185	// If the usual Go conversion rules do not allow conversion
  2186	// of the value v to type t, Convert panics.
  2187	func (v Value) Convert(t Type) Value {
  2188		if v.flag&flagMethod != 0 {
  2189			v = makeMethodValue("Convert", v)
  2190		}
  2191		op := convertOp(t.common(), v.typ)
  2192		if op == nil {
  2193			panic("reflect.Value.Convert: value of type " + v.typ.String() + " cannot be converted to type " + t.String())
  2194		}
  2195		return op(v, t)
  2196	}
  2197	
  2198	// convertOp returns the function to convert a value of type src
  2199	// to a value of type dst. If the conversion is illegal, convertOp returns nil.
  2200	func convertOp(dst, src *rtype) func(Value, Type) Value {
  2201		switch src.Kind() {
  2202		case Int, Int8, Int16, Int32, Int64:
  2203			switch dst.Kind() {
  2204			case Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
  2205				return cvtInt
  2206			case Float32, Float64:
  2207				return cvtIntFloat
  2208			case String:
  2209				return cvtIntString
  2210			}
  2211	
  2212		case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
  2213			switch dst.Kind() {
  2214			case Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
  2215				return cvtUint
  2216			case Float32, Float64:
  2217				return cvtUintFloat
  2218			case String:
  2219				return cvtUintString
  2220			}
  2221	
  2222		case Float32, Float64:
  2223			switch dst.Kind() {
  2224			case Int, Int8, Int16, Int32, Int64:
  2225				return cvtFloatInt
  2226			case Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
  2227				return cvtFloatUint
  2228			case Float32, Float64:
  2229				return cvtFloat
  2230			}
  2231	
  2232		case Complex64, Complex128:
  2233			switch dst.Kind() {
  2234			case Complex64, Complex128:
  2235				return cvtComplex
  2236			}
  2237	
  2238		case String:
  2239			if dst.Kind() == Slice && dst.Elem().PkgPath() == "" {
  2240				switch dst.Elem().Kind() {
  2241				case Uint8:
  2242					return cvtStringBytes
  2243				case Int32:
  2244					return cvtStringRunes
  2245				}
  2246			}
  2247	
  2248		case Slice:
  2249			if dst.Kind() == String && src.Elem().PkgPath() == "" {
  2250				switch src.Elem().Kind() {
  2251				case Uint8:
  2252					return cvtBytesString
  2253				case Int32:
  2254					return cvtRunesString
  2255				}
  2256			}
  2257		}
  2258	
  2259		// dst and src have same underlying type.
  2260		if haveIdenticalUnderlyingType(dst, src, false) {
  2261			return cvtDirect
  2262		}
  2263	
  2264		// dst and src are unnamed pointer types with same underlying base type.
  2265		if dst.Kind() == Ptr && dst.Name() == "" &&
  2266			src.Kind() == Ptr && src.Name() == "" &&
  2267			haveIdenticalUnderlyingType(dst.Elem().common(), src.Elem().common(), false) {
  2268			return cvtDirect
  2269		}
  2270	
  2271		if implements(dst, src) {
  2272			if src.Kind() == Interface {
  2273				return cvtI2I
  2274			}
  2275			return cvtT2I
  2276		}
  2277	
  2278		return nil
  2279	}
  2280	
  2281	// makeInt returns a Value of type t equal to bits (possibly truncated),
  2282	// where t is a signed or unsigned int type.
  2283	func makeInt(f flag, bits uint64, t Type) Value {
  2284		typ := t.common()
  2285		ptr := unsafe_New(typ)
  2286		switch typ.size {
  2287		case 1:
  2288			*(*uint8)(ptr) = uint8(bits)
  2289		case 2:
  2290			*(*uint16)(ptr) = uint16(bits)
  2291		case 4:
  2292			*(*uint32)(ptr) = uint32(bits)
  2293		case 8:
  2294			*(*uint64)(ptr) = bits
  2295		}
  2296		return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
  2297	}
  2298	
  2299	// makeFloat returns a Value of type t equal to v (possibly truncated to float32),
  2300	// where t is a float32 or float64 type.
  2301	func makeFloat(f flag, v float64, t Type) Value {
  2302		typ := t.common()
  2303		ptr := unsafe_New(typ)
  2304		switch typ.size {
  2305		case 4:
  2306			*(*float32)(ptr) = float32(v)
  2307		case 8:
  2308			*(*float64)(ptr) = v
  2309		}
  2310		return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
  2311	}
  2312	
  2313	// makeComplex returns a Value of type t equal to v (possibly truncated to complex64),
  2314	// where t is a complex64 or complex128 type.
  2315	func makeComplex(f flag, v complex128, t Type) Value {
  2316		typ := t.common()
  2317		ptr := unsafe_New(typ)
  2318		switch typ.size {
  2319		case 8:
  2320			*(*complex64)(ptr) = complex64(v)
  2321		case 16:
  2322			*(*complex128)(ptr) = v
  2323		}
  2324		return Value{typ, ptr, f | flagIndir | flag(typ.Kind())}
  2325	}
  2326	
  2327	func makeString(f flag, v string, t Type) Value {
  2328		ret := New(t).Elem()
  2329		ret.SetString(v)
  2330		ret.flag = ret.flag&^flagAddr | f
  2331		return ret
  2332	}
  2333	
  2334	func makeBytes(f flag, v []byte, t Type) Value {
  2335		ret := New(t).Elem()
  2336		ret.SetBytes(v)
  2337		ret.flag = ret.flag&^flagAddr | f
  2338		return ret
  2339	}
  2340	
  2341	func makeRunes(f flag, v []rune, t Type) Value {
  2342		ret := New(t).Elem()
  2343		ret.setRunes(v)
  2344		ret.flag = ret.flag&^flagAddr | f
  2345		return ret
  2346	}
  2347	
  2348	// These conversion functions are returned by convertOp
  2349	// for classes of conversions. For example, the first function, cvtInt,
  2350	// takes any value v of signed int type and returns the value converted
  2351	// to type t, where t is any signed or unsigned int type.
  2352	
  2353	// convertOp: intXX -> [u]intXX
  2354	func cvtInt(v Value, t Type) Value {
  2355		return makeInt(v.flag&flagRO, uint64(v.Int()), t)
  2356	}
  2357	
  2358	// convertOp: uintXX -> [u]intXX
  2359	func cvtUint(v Value, t Type) Value {
  2360		return makeInt(v.flag&flagRO, v.Uint(), t)
  2361	}
  2362	
  2363	// convertOp: floatXX -> intXX
  2364	func cvtFloatInt(v Value, t Type) Value {
  2365		return makeInt(v.flag&flagRO, uint64(int64(v.Float())), t)
  2366	}
  2367	
  2368	// convertOp: floatXX -> uintXX
  2369	func cvtFloatUint(v Value, t Type) Value {
  2370		return makeInt(v.flag&flagRO, uint64(v.Float()), t)
  2371	}
  2372	
  2373	// convertOp: intXX -> floatXX
  2374	func cvtIntFloat(v Value, t Type) Value {
  2375		return makeFloat(v.flag&flagRO, float64(v.Int()), t)
  2376	}
  2377	
  2378	// convertOp: uintXX -> floatXX
  2379	func cvtUintFloat(v Value, t Type) Value {
  2380		return makeFloat(v.flag&flagRO, float64(v.Uint()), t)
  2381	}
  2382	
  2383	// convertOp: floatXX -> floatXX
  2384	func cvtFloat(v Value, t Type) Value {
  2385		return makeFloat(v.flag&flagRO, v.Float(), t)
  2386	}
  2387	
  2388	// convertOp: complexXX -> complexXX
  2389	func cvtComplex(v Value, t Type) Value {
  2390		return makeComplex(v.flag&flagRO, v.Complex(), t)
  2391	}
  2392	
  2393	// convertOp: intXX -> string
  2394	func cvtIntString(v Value, t Type) Value {
  2395		return makeString(v.flag&flagRO, string(v.Int()), t)
  2396	}
  2397	
  2398	// convertOp: uintXX -> string
  2399	func cvtUintString(v Value, t Type) Value {
  2400		return makeString(v.flag&flagRO, string(v.Uint()), t)
  2401	}
  2402	
  2403	// convertOp: []byte -> string
  2404	func cvtBytesString(v Value, t Type) Value {
  2405		return makeString(v.flag&flagRO, string(v.Bytes()), t)
  2406	}
  2407	
  2408	// convertOp: string -> []byte
  2409	func cvtStringBytes(v Value, t Type) Value {
  2410		return makeBytes(v.flag&flagRO, []byte(v.String()), t)
  2411	}
  2412	
  2413	// convertOp: []rune -> string
  2414	func cvtRunesString(v Value, t Type) Value {
  2415		return makeString(v.flag&flagRO, string(v.runes()), t)
  2416	}
  2417	
  2418	// convertOp: string -> []rune
  2419	func cvtStringRunes(v Value, t Type) Value {
  2420		return makeRunes(v.flag&flagRO, []rune(v.String()), t)
  2421	}
  2422	
  2423	// convertOp: direct copy
  2424	func cvtDirect(v Value, typ Type) Value {
  2425		f := v.flag
  2426		t := typ.common()
  2427		ptr := v.ptr
  2428		if f&flagAddr != 0 {
  2429			// indirect, mutable word - make a copy
  2430			c := unsafe_New(t)
  2431			typedmemmove(t, c, ptr)
  2432			ptr = c
  2433			f &^= flagAddr
  2434		}
  2435		return Value{t, ptr, v.flag&flagRO | f} // v.flag&flagRO|f == f?
  2436	}
  2437	
  2438	// convertOp: concrete -> interface
  2439	func cvtT2I(v Value, typ Type) Value {
  2440		target := unsafe_New(typ.common())
  2441		x := valueInterface(v, false)
  2442		if typ.NumMethod() == 0 {
  2443			*(*interface{})(target) = x
  2444		} else {
  2445			ifaceE2I(typ.(*rtype), x, target)
  2446		}
  2447		return Value{typ.common(), target, v.flag&flagRO | flagIndir | flag(Interface)}
  2448	}
  2449	
  2450	// convertOp: interface -> interface
  2451	func cvtI2I(v Value, typ Type) Value {
  2452		if v.IsNil() {
  2453			ret := Zero(typ)
  2454			ret.flag |= v.flag & flagRO
  2455			return ret
  2456		}
  2457		return cvtT2I(v.Elem(), typ)
  2458	}
  2459	
  2460	// implemented in ../runtime
  2461	func chancap(ch unsafe.Pointer) int
  2462	func chanclose(ch unsafe.Pointer)
  2463	func chanlen(ch unsafe.Pointer) int
  2464	
  2465	// Note: some of the noescape annotations below are technically a lie,
  2466	// but safe in the context of this package. Functions like chansend
  2467	// and mapassign don't escape the referent, but may escape anything
  2468	// the referent points to (they do shallow copies of the referent).
  2469	// It is safe in this package because the referent may only point
  2470	// to something a Value may point to, and that is always in the heap
  2471	// (due to the escapes() call in ValueOf).
  2472	
  2473	//go:noescape
  2474	func chanrecv(t *rtype, ch unsafe.Pointer, nb bool, val unsafe.Pointer) (selected, received bool)
  2475	
  2476	//go:noescape
  2477	func chansend(t *rtype, ch unsafe.Pointer, val unsafe.Pointer, nb bool) bool
  2478	
  2479	func makechan(typ *rtype, size uint64) (ch unsafe.Pointer)
  2480	func makemap(t *rtype) (m unsafe.Pointer)
  2481	
  2482	//go:noescape
  2483	func mapaccess(t *rtype, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer)
  2484	
  2485	//go:noescape
  2486	func mapassign(t *rtype, m unsafe.Pointer, key, val unsafe.Pointer)
  2487	
  2488	//go:noescape
  2489	func mapdelete(t *rtype, m unsafe.Pointer, key unsafe.Pointer)
  2490	
  2491	// m escapes into the return value, but the caller of mapiterinit
  2492	// doesn't let the return value escape.
  2493	//go:noescape
  2494	func mapiterinit(t *rtype, m unsafe.Pointer) unsafe.Pointer
  2495	
  2496	//go:noescape
  2497	func mapiterkey(it unsafe.Pointer) (key unsafe.Pointer)
  2498	
  2499	//go:noescape
  2500	func mapiternext(it unsafe.Pointer)
  2501	
  2502	//go:noescape
  2503	func maplen(m unsafe.Pointer) int
  2504	
  2505	// call calls fn with a copy of the n argument bytes pointed at by arg.
  2506	// After fn returns, reflectcall copies n-retoffset result bytes
  2507	// back into arg+retoffset before returning. If copying result bytes back,
  2508	// the caller must pass the argument frame type as argtype, so that
  2509	// call can execute appropriate write barriers during the copy.
  2510	func call(argtype *rtype, fn, arg unsafe.Pointer, n uint32, retoffset uint32)
  2511	
  2512	func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer)
  2513	
  2514	// typedmemmove copies a value of type t to dst from src.
  2515	//go:noescape
  2516	func typedmemmove(t *rtype, dst, src unsafe.Pointer)
  2517	
  2518	// typedmemmovepartial is like typedmemmove but assumes that
  2519	// dst and src point off bytes into the value and only copies size bytes.
  2520	//go:noescape
  2521	func typedmemmovepartial(t *rtype, dst, src unsafe.Pointer, off, size uintptr)
  2522	
  2523	// typedslicecopy copies a slice of elemType values from src to dst,
  2524	// returning the number of elements copied.
  2525	//go:noescape
  2526	func typedslicecopy(elemType *rtype, dst, src sliceHeader) int
  2527	
  2528	//go:noescape
  2529	func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
  2530	
  2531	// Dummy annotation marking that the value x escapes,
  2532	// for use in cases where the reflect code is so clever that
  2533	// the compiler cannot follow.
  2534	func escapes(x interface{}) {
  2535		if dummy.b {
  2536			dummy.x = x
  2537		}
  2538	}
  2539	
  2540	var dummy struct {
  2541		b bool
  2542		x interface{}
  2543	}
  2544	

View as plain text