]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/x509/internal/macos: simplify code using unsafe.{SliceData,StringData}
authorcuiweixie <cuiweixie@gmail.com>
Sat, 3 Sep 2022 06:18:13 +0000 (14:18 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 7 Sep 2022 01:27:54 +0000 (01:27 +0000)
Updates #54854

Change-Id: I8a64a1176cbe16489e1fd21c66a7abc7d8b8e9b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/428154
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/crypto/x509/internal/macos/corefoundation.go

index 2677ff706ae33acd6e904fa4d8375518191c3d13..d1295daee1c99307520ec80b0e0d59dd9526786b 100644 (file)
@@ -12,7 +12,6 @@ package macOS
 import (
        "errors"
        "internal/abi"
-       "reflect"
        "runtime"
        "time"
        "unsafe"
@@ -64,7 +63,7 @@ const kCFStringEncodingUTF8 = 0x08000100
 //go:cgo_import_dynamic x509_CFDataCreate CFDataCreate "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
 
 func BytesToCFData(b []byte) CFRef {
-       p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&b)).Data)
+       p := unsafe.Pointer(unsafe.SliceData(b))
        ret := syscall(abi.FuncPCABI0(x509_CFDataCreate_trampoline), kCFAllocatorDefault, uintptr(p), uintptr(len(b)), 0, 0, 0)
        runtime.KeepAlive(p)
        return CFRef(ret)
@@ -75,7 +74,7 @@ func x509_CFDataCreate_trampoline()
 
 // StringToCFString returns a copy of the UTF-8 contents of s as a new CFString.
 func StringToCFString(s string) CFString {
-       p := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data)
+       p := unsafe.Pointer(unsafe.StringData(s))
        ret := syscall(abi.FuncPCABI0(x509_CFStringCreateWithBytes_trampoline), kCFAllocatorDefault, uintptr(p),
                uintptr(len(s)), uintptr(kCFStringEncodingUTF8), 0 /* isExternalRepresentation */, 0)
        runtime.KeepAlive(p)