2014-08-07 14:58:42 -06:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
hashSize = 1009
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-08-27 21:32:49 -06:00
|
|
|
ifaceLock mutex // lock for accessing hash
|
2014-08-07 14:58:42 -06:00
|
|
|
hash [hashSize]*itab
|
|
|
|
)
|
|
|
|
|
|
|
|
// fInterface is our standard non-empty interface. We use it instead
|
|
|
|
// of interface{f()} in function prototypes because gofmt insists on
|
|
|
|
// putting lots of newlines in the otherwise concise interface{f()}.
|
|
|
|
type fInterface interface {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
|
|
|
|
func getitab(inter *interfacetype, typ *_type, canfail bool) *itab {
|
|
|
|
if len(inter.mhdr) == 0 {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("internal error - misuse of itab")
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// easy case
|
|
|
|
x := typ.x
|
|
|
|
if x == nil {
|
|
|
|
if canfail {
|
|
|
|
return nil
|
|
|
|
}
|
2015-01-06 21:38:44 -07:00
|
|
|
panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *inter.mhdr[0].name})
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// compiler has provided some good hash codes for us.
|
|
|
|
h := inter.typ.hash
|
|
|
|
h += 17 * typ.hash
|
|
|
|
// TODO(rsc): h += 23 * x.mhash ?
|
|
|
|
h %= hashSize
|
|
|
|
|
|
|
|
// look twice - once without lock, once with.
|
|
|
|
// common case will be no lock contention.
|
|
|
|
var m *itab
|
|
|
|
var locked int
|
|
|
|
for locked = 0; locked < 2; locked++ {
|
|
|
|
if locked != 0 {
|
2014-08-27 21:32:49 -06:00
|
|
|
lock(&ifaceLock)
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
for m = (*itab)(atomicloadp(unsafe.Pointer(&hash[h]))); m != nil; m = m.link {
|
2014-08-07 14:58:42 -06:00
|
|
|
if m.inter == inter && m._type == typ {
|
|
|
|
if m.bad != 0 {
|
|
|
|
m = nil
|
|
|
|
if !canfail {
|
|
|
|
// this can only happen if the conversion
|
|
|
|
// was already done once using the , ok form
|
|
|
|
// and we have a cached negative result.
|
|
|
|
// the cached result doesn't record which
|
|
|
|
// interface function was missing, so jump
|
|
|
|
// down to the interface check, which will
|
|
|
|
// do more work but give a better error.
|
|
|
|
goto search
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if locked != 0 {
|
2014-08-27 21:32:49 -06:00
|
|
|
unlock(&ifaceLock)
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:38:44 -07:00
|
|
|
m = (*itab)(persistentalloc(unsafe.Sizeof(itab{})+uintptr(len(inter.mhdr)-1)*ptrSize, 0, &memstats.other_sys))
|
2014-08-07 14:58:42 -06:00
|
|
|
m.inter = inter
|
|
|
|
m._type = typ
|
|
|
|
|
|
|
|
search:
|
|
|
|
// both inter and typ have method sorted by name,
|
|
|
|
// and interface names are unique,
|
|
|
|
// so can iterate over both in lock step;
|
|
|
|
// the loop is O(ni+nt) not O(ni*nt).
|
|
|
|
ni := len(inter.mhdr)
|
|
|
|
nt := len(x.mhdr)
|
|
|
|
j := 0
|
|
|
|
for k := 0; k < ni; k++ {
|
2015-01-06 21:38:44 -07:00
|
|
|
i := &inter.mhdr[k]
|
2014-08-07 14:58:42 -06:00
|
|
|
iname := i.name
|
|
|
|
ipkgpath := i.pkgpath
|
|
|
|
itype := i._type
|
|
|
|
for ; j < nt; j++ {
|
2015-01-06 21:38:44 -07:00
|
|
|
t := &x.mhdr[j]
|
2014-08-07 14:58:42 -06:00
|
|
|
if t.mtyp == itype && t.name == iname && t.pkgpath == ipkgpath {
|
|
|
|
if m != nil {
|
2015-01-06 21:38:44 -07:00
|
|
|
*(*unsafe.Pointer)(add(unsafe.Pointer(&m.fun[0]), uintptr(k)*ptrSize)) = t.ifn
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
goto nextimethod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// didn't find method
|
|
|
|
if !canfail {
|
|
|
|
if locked != 0 {
|
2014-08-27 21:32:49 -06:00
|
|
|
unlock(&ifaceLock)
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
panic(&TypeAssertionError{"", *typ._string, *inter.typ._string, *iname})
|
|
|
|
}
|
|
|
|
m.bad = 1
|
|
|
|
break
|
|
|
|
nextimethod:
|
|
|
|
}
|
|
|
|
if locked == 0 {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("invalid itab locking")
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
m.link = hash[h]
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
atomicstorep(unsafe.Pointer(&hash[h]), unsafe.Pointer(m))
|
2014-08-27 21:32:49 -06:00
|
|
|
unlock(&ifaceLock)
|
2014-08-07 14:58:42 -06:00
|
|
|
if m.bad != 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func typ2Itab(t *_type, inter *interfacetype, cache **itab) *itab {
|
|
|
|
tab := getitab(inter, t, false)
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
atomicstorep(unsafe.Pointer(cache), unsafe.Pointer(tab))
|
2014-08-07 14:58:42 -06:00
|
|
|
return tab
|
|
|
|
}
|
|
|
|
|
|
|
|
func convT2E(t *_type, elem unsafe.Pointer) (e interface{}) {
|
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
2014-08-18 19:13:11 -06:00
|
|
|
if isDirectIface(t) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep._type = t
|
2014-12-29 08:07:47 -07:00
|
|
|
typedmemmove(t, unsafe.Pointer(&ep.data), elem)
|
2014-08-07 14:58:42 -06:00
|
|
|
} else {
|
|
|
|
x := newobject(t)
|
|
|
|
// TODO: We allocate a zeroed object only to overwrite it with
|
|
|
|
// actual data. Figure out how to avoid zeroing. Also below in convT2I.
|
2014-12-29 08:07:47 -07:00
|
|
|
typedmemmove(t, x, elem)
|
2014-08-07 14:58:42 -06:00
|
|
|
ep._type = t
|
|
|
|
ep.data = x
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func convT2I(t *_type, inter *interfacetype, cache **itab, elem unsafe.Pointer) (i fInterface) {
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
tab := (*itab)(atomicloadp(unsafe.Pointer(cache)))
|
2014-08-07 14:58:42 -06:00
|
|
|
if tab == nil {
|
|
|
|
tab = getitab(inter, t, false)
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
atomicstorep(unsafe.Pointer(cache), unsafe.Pointer(tab))
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
pi := (*iface)(unsafe.Pointer(&i))
|
2014-08-18 19:13:11 -06:00
|
|
|
if isDirectIface(t) {
|
2014-08-07 14:58:42 -06:00
|
|
|
pi.tab = tab
|
2014-12-29 08:07:47 -07:00
|
|
|
typedmemmove(t, unsafe.Pointer(&pi.data), elem)
|
2014-08-07 14:58:42 -06:00
|
|
|
} else {
|
|
|
|
x := newobject(t)
|
2014-12-29 08:07:47 -07:00
|
|
|
typedmemmove(t, x, elem)
|
2014-08-07 14:58:42 -06:00
|
|
|
pi.tab = tab
|
|
|
|
pi.data = x
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2T(t *_type, i fInterface, r unsafe.Pointer) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
panic(&TypeAssertionError{"", "", *t._string, ""})
|
|
|
|
}
|
|
|
|
if tab._type != t {
|
|
|
|
panic(&TypeAssertionError{*tab.inter.typ._string, *tab._type._string, *t._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
if isDirectIface(t) {
|
|
|
|
writebarrierptr((*uintptr)(r), uintptr(ip.data))
|
|
|
|
} else {
|
|
|
|
typedmemmove(t, r, ip.data)
|
|
|
|
}
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2T2(t *_type, i fInterface, r unsafe.Pointer) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil || tab._type != t {
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
memclr(r, uintptr(t.size))
|
|
|
|
}
|
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
if isDirectIface(t) {
|
|
|
|
writebarrierptr((*uintptr)(r), uintptr(ip.data))
|
|
|
|
} else {
|
|
|
|
typedmemmove(t, r, ip.data)
|
|
|
|
}
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2T(t *_type, e interface{}, r unsafe.Pointer) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
if ep._type == nil {
|
|
|
|
panic(&TypeAssertionError{"", "", *t._string, ""})
|
|
|
|
}
|
|
|
|
if ep._type != t {
|
|
|
|
panic(&TypeAssertionError{"", *ep._type._string, *t._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
if isDirectIface(t) {
|
|
|
|
writebarrierptr((*uintptr)(r), uintptr(ep.data))
|
|
|
|
} else {
|
|
|
|
typedmemmove(t, r, ep.data)
|
|
|
|
}
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 16:14:31 -06:00
|
|
|
// The compiler ensures that r is non-nil.
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2T2(t *_type, e interface{}, r unsafe.Pointer) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
if ep._type != t {
|
2015-03-17 16:14:31 -06:00
|
|
|
memclr(r, uintptr(t.size))
|
2014-12-29 14:15:05 -07:00
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2015-03-17 16:14:31 -06:00
|
|
|
if isDirectIface(t) {
|
|
|
|
writebarrierptr((*uintptr)(r), uintptr(ep.data))
|
|
|
|
} else {
|
|
|
|
typedmemmove(t, r, ep.data)
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func convI2E(i fInterface) (r interface{}) {
|
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rp := (*eface)(unsafe.Pointer(&r))
|
|
|
|
rp._type = tab._type
|
|
|
|
rp.data = ip.data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2E(inter *interfacetype, i fInterface, r *interface{}) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
// explicit conversions require non-nil interface value.
|
|
|
|
panic(&TypeAssertionError{"", "", *inter.typ._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
rp := (*eface)(unsafe.Pointer(r))
|
2014-08-07 14:58:42 -06:00
|
|
|
rp._type = tab._type
|
|
|
|
rp.data = ip.data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-17 16:14:31 -06:00
|
|
|
// The compiler ensures that r is non-nil.
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2E2(inter *interfacetype, i fInterface, r *interface{}) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
2014-12-29 14:15:05 -07:00
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2015-03-17 16:14:31 -06:00
|
|
|
rp := (*eface)(unsafe.Pointer(r))
|
|
|
|
rp._type = tab._type
|
|
|
|
rp.data = ip.data
|
2014-12-29 14:15:05 -07:00
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func convI2I(inter *interfacetype, i fInterface) (r fInterface) {
|
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rp := (*iface)(unsafe.Pointer(&r))
|
|
|
|
if tab.inter == inter {
|
|
|
|
rp.tab = tab
|
|
|
|
rp.data = ip.data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rp.tab = getitab(inter, tab._type, false)
|
|
|
|
rp.data = ip.data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2I(inter *interfacetype, i fInterface, r *fInterface) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
// explicit conversions require non-nil interface value.
|
|
|
|
panic(&TypeAssertionError{"", "", *inter.typ._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
rp := (*iface)(unsafe.Pointer(r))
|
2014-08-07 14:58:42 -06:00
|
|
|
if tab.inter == inter {
|
|
|
|
rp.tab = tab
|
|
|
|
rp.data = ip.data
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rp.tab = getitab(inter, tab._type, false)
|
|
|
|
rp.data = ip.data
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertI2I2(inter *interfacetype, i fInterface, r *fInterface) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
*r = nil
|
|
|
|
}
|
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
if tab.inter != inter {
|
|
|
|
tab = getitab(inter, tab._type, true)
|
|
|
|
if tab == nil {
|
|
|
|
if r != nil {
|
|
|
|
*r = nil
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if r != nil {
|
|
|
|
rp := (*iface)(unsafe.Pointer(r))
|
2014-08-07 14:58:42 -06:00
|
|
|
rp.tab = tab
|
|
|
|
rp.data = ip.data
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2I(inter *interfacetype, e interface{}, r *fInterface) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
t := ep._type
|
|
|
|
if t == nil {
|
|
|
|
// explicit conversions require non-nil interface value.
|
|
|
|
panic(&TypeAssertionError{"", "", *inter.typ._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
rp := (*iface)(unsafe.Pointer(r))
|
2014-08-07 14:58:42 -06:00
|
|
|
rp.tab = getitab(inter, t, false)
|
|
|
|
rp.data = ep.data
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2I2(inter *interfacetype, e interface{}, r *fInterface) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
t := ep._type
|
|
|
|
if t == nil {
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
*r = nil
|
|
|
|
}
|
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
tab := getitab(inter, t, true)
|
|
|
|
if tab == nil {
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
*r = nil
|
|
|
|
}
|
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
if r != nil {
|
|
|
|
rp := (*iface)(unsafe.Pointer(r))
|
|
|
|
rp.tab = tab
|
|
|
|
rp.data = ep.data
|
|
|
|
}
|
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
2014-12-22 11:27:53 -07:00
|
|
|
//go:linkname reflect_ifaceE2I reflect.ifaceE2I
|
2014-08-07 14:58:42 -06:00
|
|
|
func reflect_ifaceE2I(inter *interfacetype, e interface{}, dst *fInterface) {
|
2014-12-29 14:15:05 -07:00
|
|
|
assertE2I(inter, e, dst)
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2E(inter *interfacetype, e interface{}, r *interface{}) {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
if ep._type == nil {
|
|
|
|
// explicit conversions require non-nil interface value.
|
|
|
|
panic(&TypeAssertionError{"", "", *inter.typ._string, ""})
|
|
|
|
}
|
2014-12-29 14:15:05 -07:00
|
|
|
*r = e
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
2015-03-17 16:14:31 -06:00
|
|
|
// The compiler ensures that r is non-nil.
|
2014-12-29 14:15:05 -07:00
|
|
|
func assertE2E2(inter *interfacetype, e interface{}, r *interface{}) bool {
|
2014-08-07 14:58:42 -06:00
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
if ep._type == nil {
|
2015-03-17 16:14:31 -06:00
|
|
|
*r = nil
|
2014-12-29 14:15:05 -07:00
|
|
|
return false
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
2015-03-17 16:14:31 -06:00
|
|
|
*r = e
|
2014-12-29 14:15:05 -07:00
|
|
|
return true
|
2014-08-07 14:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func ifacethash(i fInterface) uint32 {
|
|
|
|
ip := (*iface)(unsafe.Pointer(&i))
|
|
|
|
tab := ip.tab
|
|
|
|
if tab == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return tab._type.hash
|
|
|
|
}
|
|
|
|
|
|
|
|
func efacethash(e interface{}) uint32 {
|
|
|
|
ep := (*eface)(unsafe.Pointer(&e))
|
|
|
|
t := ep._type
|
|
|
|
if t == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return t.hash
|
|
|
|
}
|
2014-08-28 08:36:48 -06:00
|
|
|
|
|
|
|
func iterate_itabs(fn func(*itab)) {
|
2014-08-28 09:45:30 -06:00
|
|
|
for _, h := range &hash {
|
2014-08-28 08:36:48 -06:00
|
|
|
for ; h != nil; h = h.link {
|
|
|
|
fn(h)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|