package runtime
import (
"internal/runtime/math"
"internal/runtime/sys"
"unsafe"
)
func unsafestring(ptr unsafe .Pointer , len int ) {
if len < 0 {
panicunsafestringlen ()
}
if uintptr (len ) > -uintptr (ptr ) {
if ptr == nil {
panicunsafestringnilptr ()
}
panicunsafestringlen ()
}
}
func unsafestring64(ptr unsafe .Pointer , len64 int64 ) {
len := int (len64 )
if int64 (len ) != len64 {
panicunsafestringlen ()
}
unsafestring (ptr , len )
}
func unsafestringcheckptr(ptr unsafe .Pointer , len64 int64 ) {
unsafestring64 (ptr , len64 )
if checkptrStraddles (ptr , uintptr (len64 )) {
throw ("checkptr: unsafe.String result straddles multiple allocations" )
}
}
func panicunsafestringlen() {
panic (errorString ("unsafe.String: len out of range" ))
}
func panicunsafestringnilptr() {
panic (errorString ("unsafe.String: ptr is nil and len is not zero" ))
}
func unsafeslice(et *_type , ptr unsafe .Pointer , len int ) {
if len < 0 {
panicunsafeslicelen1 (sys .GetCallerPC ())
}
if et .Size_ == 0 {
if ptr == nil && len > 0 {
panicunsafeslicenilptr1 (sys .GetCallerPC ())
}
}
mem , overflow := math .MulUintptr (et .Size_ , uintptr (len ))
if overflow || mem > -uintptr (ptr ) {
if ptr == nil {
panicunsafeslicenilptr1 (sys .GetCallerPC ())
}
panicunsafeslicelen1 (sys .GetCallerPC ())
}
}
func unsafeslice64(et *_type , ptr unsafe .Pointer , len64 int64 ) {
len := int (len64 )
if int64 (len ) != len64 {
panicunsafeslicelen1 (sys .GetCallerPC ())
}
unsafeslice (et , ptr , len )
}
func unsafeslicecheckptr(et *_type , ptr unsafe .Pointer , len64 int64 ) {
unsafeslice64 (et , ptr , len64 )
if checkptrStraddles (ptr , uintptr (len64 )*et .Size_ ) {
throw ("checkptr: unsafe.Slice result straddles multiple allocations" )
}
}
func panicunsafeslicelen() {
panicunsafeslicelen1 (sys .GetCallerPC ())
}
func panicunsafeslicelen1(pc uintptr ) {
panicCheck1 (pc , "unsafe.Slice: len out of range" )
panic (errorString ("unsafe.Slice: len out of range" ))
}
func panicunsafeslicenilptr() {
panicunsafeslicenilptr1 (sys .GetCallerPC ())
}
func panicunsafeslicenilptr1(pc uintptr ) {
panicCheck1 (pc , "unsafe.Slice: ptr is nil and len is not zero" )
panic (errorString ("unsafe.Slice: ptr is nil and len is not zero" ))
}
func reflect_unsafeslice(et *_type , ptr unsafe .Pointer , len int ) {
unsafeslice (et , ptr , len )
}
The pages are generated with Golds v0.7.3-preview . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .