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>
package base
import (
+ "internal/unsafeheader"
"os"
- "reflect"
"runtime"
"syscall"
"unsafe"
}
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
package ld
import (
- "reflect"
+ "internal/unsafeheader"
"syscall"
"unsafe"
)
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)
return uintptr(p)
case Slice:
- return (*SliceHeader)(v.ptr).Data
+ return uintptr((*unsafeheader.Slice)(v.ptr).Data)
}
panic(&ValueError{"reflect.Value.Pointer", v.kind()})
}