]> Cypherpunks repositories - gostls13.git/commitdiff
all: transfer reflect.{SliceHeader, StringHeader} to unsafeheader.{Slice, String}
authorhopehook <hopehook.com@gmail.com>
Fri, 9 Sep 2022 00:48:34 +0000 (08:48 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 9 Sep 2022 01:59:25 +0000 (01:59 +0000)
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>

src/cmd/compile/internal/base/mapfile_mmap.go
src/cmd/link/internal/ld/outbuf_windows.go
src/reflect/value.go

index e154a3f9e0a33a728c8985887dfeb3d3cb817eed..3a5f4cfe21d889d98f722a64cf46c5498116bcf5 100644 (file)
@@ -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
index a568a17011db3152680795000388877167dfe8be..95937e781c6a0a54cae90356c15e2aa3fbf5a3e0 100644 (file)
@@ -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)
 
index 917a5a69c9c488e6fe3119a65e8ca877d247f445..4e5d3977ec8e4167436a6d24e094a376f2f80ff5 100644 (file)
@@ -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()})
 }