Skip to content

Commit f53b211

Browse files
tklausergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 1b19698 commit f53b211

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/syscall/syscall_unix.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"internal/itoa"
1212
"internal/oserror"
1313
"internal/race"
14-
"internal/unsafeheader"
1514
"runtime"
1615
"sync"
1716
"unsafe"
@@ -57,11 +56,7 @@ func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (d
5756
}
5857

5958
// Use unsafe to turn addr into a []byte.
60-
var b []byte
61-
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
62-
hdr.Data = unsafe.Pointer(addr)
63-
hdr.Cap = length
64-
hdr.Len = length
59+
b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), length)
6560

6661
// Register mapping in m and return it.
6762
p := &b[cap(b)-1]

src/syscall/syscall_windows.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"internal/itoa"
1313
"internal/oserror"
1414
"internal/race"
15-
"internal/unsafeheader"
1615
"runtime"
1716
"sync"
1817
"unicode/utf16"
@@ -78,11 +77,7 @@ func utf16PtrToString(p *uint16) string {
7877
n++
7978
}
8079
// Turn *uint16 into []uint16.
81-
var s []uint16
82-
hdr := (*unsafeheader.Slice)(unsafe.Pointer(&s))
83-
hdr.Data = unsafe.Pointer(p)
84-
hdr.Cap = n
85-
hdr.Len = n
80+
s := unsafe.Slice((*uint16)(unsafe.Pointer(p)), n)
8681
// Decode []uint16 into string.
8782
return string(utf16.Decode(s))
8883
}

0 commit comments

Comments
 (0)