mirror of https://github.com/golang/go.git
all: transfer reflect.{SliceHeader, StringHeader} to unsafeheader.{Slice, String}
After we deprecated reflect.{SliceHeader, StringHeader}, it is recommended
to use unsafe.{Slice, String} to replace its work. However, the compiler
and linker cannot be migrated for the time being.
As a temporary strategy, using the "internal/unsafeheader" package like
other code is the most suitable choice at present.
For #53003.
Change-Id: I69d0ef72e2d95caabd0706bbb247a719d225c758
Reviewed-on: https://go-review.googlesource.com/c/go/+/429755
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
This commit is contained in:
parent
d734203e39
commit
41089704dd
|
|
@ -8,8 +8,8 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"internal/unsafeheader"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
|
@ -34,10 +34,10 @@ func MapFile(f *os.File, offset, length int64) (string, error) {
|
|||
}
|
||||
|
||||
buf = buf[x:]
|
||||
pSlice := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
|
||||
pSlice := (*unsafeheader.Slice)(unsafe.Pointer(&buf))
|
||||
|
||||
var res string
|
||||
pString := (*reflect.StringHeader)(unsafe.Pointer(&res))
|
||||
pString := (*unsafeheader.String)(unsafe.Pointer(&res))
|
||||
|
||||
pString.Data = pSlice.Data
|
||||
pString.Len = pSlice.Len
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
package ld
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"internal/unsafeheader"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
|
@ -35,8 +35,8 @@ func (out *OutBuf) Mmap(filesize uint64) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&out.buf))
|
||||
bufHdr.Data = ptr
|
||||
bufHdr := (*unsafeheader.Slice)(unsafe.Pointer(&out.buf))
|
||||
bufHdr.Data = unsafe.Pointer(ptr)
|
||||
bufHdr.Len = int(filesize)
|
||||
bufHdr.Cap = int(filesize)
|
||||
|
||||
|
|
|
|||
|
|
@ -2155,7 +2155,7 @@ func (v Value) Pointer() uintptr {
|
|||
return uintptr(p)
|
||||
|
||||
case Slice:
|
||||
return (*SliceHeader)(v.ptr).Data
|
||||
return uintptr((*unsafeheader.Slice)(v.ptr).Data)
|
||||
}
|
||||
panic(&ValueError{"reflect.Value.Pointer", v.kind()})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue