1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00

syscall: use unsafe.Slice instead of unsafeheader package

Change-Id: I9de5aafb36d05bdc90bbdba516367eb2b200a7e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/428777
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Tobias Klauser 2022-09-07 09:51:35 +02:00 committed by Gopher Robot
parent 1b196988d4
commit f53b2111e4
2 changed files with 2 additions and 12 deletions

View File

@ -11,7 +11,6 @@ import (
"internal/itoa"
"internal/oserror"
"internal/race"
"internal/unsafeheader"
"runtime"
"sync"
"unsafe"
@ -57,11 +56,7 @@ func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (d
}
// Use unsafe to turn addr into a []byte.
var b []byte
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
hdr.Data = unsafe.Pointer(addr)
hdr.Cap = length
hdr.Len = length
b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), length)
// Register mapping in m and return it.
p := &b[cap(b)-1]

View File

@ -12,7 +12,6 @@ import (
"internal/itoa"
"internal/oserror"
"internal/race"
"internal/unsafeheader"
"runtime"
"sync"
"unicode/utf16"
@ -78,11 +77,7 @@ func utf16PtrToString(p *uint16) string {
n++
}
// Turn *uint16 into []uint16.
var s []uint16
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&s))
hdr.Data = unsafe.Pointer(p)
hdr.Cap = n
hdr.Len = n
s := unsafe.Slice((*uint16)(unsafe.Pointer(p)), n)
// Decode []uint16 into string.
return string(utf16.Decode(s))
}