2014-06-17 00:03:03 -06:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2016-09-06 02:38:16 -06:00
|
|
|
import "unsafe"
|
2014-06-17 00:03:03 -06:00
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
// The constant is known to the compiler.
|
|
|
|
// There is no fundamental theory behind this number.
|
|
|
|
const tmpStringBufSize = 32
|
|
|
|
|
|
|
|
type tmpBuf [tmpStringBufSize]byte
|
|
|
|
|
|
|
|
// concatstrings implements a Go string concatenation x+y+z+...
|
|
|
|
// The operands are passed in the slice a.
|
|
|
|
// If buf != nil, the compiler has determined that the result does not
|
|
|
|
// escape the calling function, so the string data can be stored in buf
|
|
|
|
// if small enough.
|
|
|
|
func concatstrings(buf *tmpBuf, a []string) string {
|
2014-06-17 00:03:03 -06:00
|
|
|
idx := 0
|
|
|
|
l := 0
|
|
|
|
count := 0
|
|
|
|
for i, x := range a {
|
|
|
|
n := len(x)
|
|
|
|
if n == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if l+n < l {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("string concatenation too long")
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
l += n
|
|
|
|
count++
|
|
|
|
idx = i
|
|
|
|
}
|
|
|
|
if count == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
2015-01-21 07:37:59 -07:00
|
|
|
|
|
|
|
// If there is just one string and either it is not on the stack
|
|
|
|
// or our result does not escape the calling frame (buf != nil),
|
|
|
|
// then we can return that string directly.
|
|
|
|
if count == 1 && (buf != nil || !stringDataOnStack(a[idx])) {
|
2014-06-17 00:03:03 -06:00
|
|
|
return a[idx]
|
|
|
|
}
|
2015-01-21 07:37:59 -07:00
|
|
|
s, b := rawstringtmp(buf, l)
|
2014-06-17 00:03:03 -06:00
|
|
|
for _, x := range a {
|
2016-08-13 19:12:21 -06:00
|
|
|
copy(b, x)
|
|
|
|
b = b[len(x):]
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
func concatstring2(buf *tmpBuf, a [2]string) string {
|
|
|
|
return concatstrings(buf, a[:])
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
func concatstring3(buf *tmpBuf, a [3]string) string {
|
|
|
|
return concatstrings(buf, a[:])
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
func concatstring4(buf *tmpBuf, a [4]string) string {
|
|
|
|
return concatstrings(buf, a[:])
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
func concatstring5(buf *tmpBuf, a [5]string) string {
|
|
|
|
return concatstrings(buf, a[:])
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
// Buf is a fixed-size buffer for the result,
|
|
|
|
// it is not nil if the result does not escape.
|
2017-03-04 17:54:50 -07:00
|
|
|
func slicebytetostring(buf *tmpBuf, b []byte) (str string) {
|
2015-01-21 07:37:59 -07:00
|
|
|
l := len(b)
|
|
|
|
if l == 0 {
|
|
|
|
// Turns out to be a relatively common case.
|
|
|
|
// Consider that you want to parse out data between parens in "foo()bar",
|
|
|
|
// you find the indices and convert the subslice to string.
|
|
|
|
return ""
|
|
|
|
}
|
2017-03-04 17:54:50 -07:00
|
|
|
if raceenabled {
|
2014-06-17 00:03:03 -06:00
|
|
|
racereadrangepc(unsafe.Pointer(&b[0]),
|
2015-01-21 07:37:59 -07:00
|
|
|
uintptr(l),
|
2016-02-25 11:16:18 -07:00
|
|
|
getcallerpc(unsafe.Pointer(&buf)),
|
2014-09-03 09:10:38 -06:00
|
|
|
funcPC(slicebytetostring))
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
2017-03-04 17:54:50 -07:00
|
|
|
if msanenabled {
|
2015-10-21 12:04:42 -06:00
|
|
|
msanread(unsafe.Pointer(&b[0]), uintptr(l))
|
|
|
|
}
|
2017-03-04 17:54:50 -07:00
|
|
|
|
|
|
|
var p unsafe.Pointer
|
|
|
|
if buf != nil && len(b) <= len(buf) {
|
|
|
|
p = unsafe.Pointer(buf)
|
|
|
|
} else {
|
|
|
|
p = mallocgc(uintptr(len(b)), nil, false)
|
|
|
|
}
|
|
|
|
stringStructOf(&str).str = p
|
|
|
|
stringStructOf(&str).len = len(b)
|
|
|
|
memmove(p, (*(*slice)(unsafe.Pointer(&b))).array, uintptr(len(b)))
|
|
|
|
return
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:37:59 -07:00
|
|
|
// stringDataOnStack reports whether the string's data is
|
|
|
|
// stored on the current goroutine's stack.
|
|
|
|
func stringDataOnStack(s string) bool {
|
2015-10-20 01:35:12 -06:00
|
|
|
ptr := uintptr(stringStructOf(&s).str)
|
2015-01-21 07:37:59 -07:00
|
|
|
stk := getg().stack
|
|
|
|
return stk.lo <= ptr && ptr < stk.hi
|
|
|
|
}
|
|
|
|
|
|
|
|
func rawstringtmp(buf *tmpBuf, l int) (s string, b []byte) {
|
|
|
|
if buf != nil && l <= len(buf) {
|
|
|
|
b = buf[:l]
|
|
|
|
s = slicebytetostringtmp(b)
|
|
|
|
} else {
|
|
|
|
s, b = rawstring(l)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-10 14:44:00 -06:00
|
|
|
// slicebytetostringtmp returns a "string" referring to the actual []byte bytes.
|
|
|
|
//
|
|
|
|
// Callers need to ensure that the returned string will not be used after
|
|
|
|
// the calling goroutine modifies the original slice or synchronizes with
|
|
|
|
// another goroutine.
|
|
|
|
//
|
|
|
|
// The function is only called when instrumenting
|
|
|
|
// and otherwise intrinsified by the compiler.
|
|
|
|
//
|
|
|
|
// Some internal compiler optimizations use this function.
|
|
|
|
// - Used for m[string(k)] lookup where m is a string-keyed map and k is a []byte.
|
|
|
|
// - Used for "<"+string(b)+">" concatenation where b is []byte.
|
|
|
|
// - Used for string(b)=="foo" comparison where b is []byte.
|
2014-06-17 00:03:03 -06:00
|
|
|
func slicebytetostringtmp(b []byte) string {
|
|
|
|
if raceenabled && len(b) > 0 {
|
|
|
|
racereadrangepc(unsafe.Pointer(&b[0]),
|
2014-09-04 13:53:45 -06:00
|
|
|
uintptr(len(b)),
|
cmd/cc, runtime: preserve C runtime type names in generated Go
uintptr or uint64 in the runtime C were turning into uint in the Go,
bool was turning into uint8, and so on. Fix that.
Also delete Go wrappers for C functions.
The C functions can be called directly now
(but still eventually need to be converted to Go).
LGTM=bradfitz, minux, iant
R=golang-codereviews, bradfitz, iant, minux
CC=golang-codereviews, khr, r
https://golang.org/cl/138740043
2014-08-27 19:59:49 -06:00
|
|
|
getcallerpc(unsafe.Pointer(&b)),
|
2014-09-03 09:10:38 -06:00
|
|
|
funcPC(slicebytetostringtmp))
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
2015-10-21 12:04:42 -06:00
|
|
|
if msanenabled && len(b) > 0 {
|
|
|
|
msanread(unsafe.Pointer(&b[0]), uintptr(len(b)))
|
|
|
|
}
|
2014-06-17 00:03:03 -06:00
|
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
|
|
}
|
|
|
|
|
2015-01-29 23:14:13 -07:00
|
|
|
func stringtoslicebyte(buf *tmpBuf, s string) []byte {
|
|
|
|
var b []byte
|
|
|
|
if buf != nil && len(s) <= len(buf) {
|
2016-04-24 18:04:32 -06:00
|
|
|
*buf = tmpBuf{}
|
|
|
|
b = buf[:len(s)]
|
2015-01-29 23:14:13 -07:00
|
|
|
} else {
|
|
|
|
b = rawbyteslice(len(s))
|
|
|
|
}
|
2014-06-17 00:03:03 -06:00
|
|
|
copy(b, s)
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2015-01-29 23:14:13 -07:00
|
|
|
func stringtoslicerune(buf *[tmpStringBufSize]rune, s string) []rune {
|
2014-06-17 00:03:03 -06:00
|
|
|
// two passes.
|
|
|
|
// unlike slicerunetostring, no race because strings are immutable.
|
|
|
|
n := 0
|
2016-08-26 07:00:46 -06:00
|
|
|
for range s {
|
2014-06-17 00:03:03 -06:00
|
|
|
n++
|
|
|
|
}
|
2016-08-26 07:00:46 -06:00
|
|
|
|
2015-01-29 23:14:13 -07:00
|
|
|
var a []rune
|
|
|
|
if buf != nil && n <= len(buf) {
|
2016-04-24 18:04:32 -06:00
|
|
|
*buf = [tmpStringBufSize]rune{}
|
|
|
|
a = buf[:n]
|
2015-01-29 23:14:13 -07:00
|
|
|
} else {
|
|
|
|
a = rawruneslice(n)
|
|
|
|
}
|
2016-08-26 07:00:46 -06:00
|
|
|
|
2014-06-17 00:03:03 -06:00
|
|
|
n = 0
|
2016-08-26 07:00:46 -06:00
|
|
|
for _, r := range s {
|
2014-06-17 00:03:03 -06:00
|
|
|
a[n] = r
|
|
|
|
n++
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2015-01-29 23:14:13 -07:00
|
|
|
func slicerunetostring(buf *tmpBuf, a []rune) string {
|
2014-06-17 00:03:03 -06:00
|
|
|
if raceenabled && len(a) > 0 {
|
|
|
|
racereadrangepc(unsafe.Pointer(&a[0]),
|
2014-09-04 13:53:45 -06:00
|
|
|
uintptr(len(a))*unsafe.Sizeof(a[0]),
|
2016-02-25 11:16:18 -07:00
|
|
|
getcallerpc(unsafe.Pointer(&buf)),
|
2014-09-03 09:10:38 -06:00
|
|
|
funcPC(slicerunetostring))
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
2015-10-21 12:04:42 -06:00
|
|
|
if msanenabled && len(a) > 0 {
|
|
|
|
msanread(unsafe.Pointer(&a[0]), uintptr(len(a))*unsafe.Sizeof(a[0]))
|
|
|
|
}
|
2014-06-17 00:03:03 -06:00
|
|
|
var dum [4]byte
|
|
|
|
size1 := 0
|
|
|
|
for _, r := range a {
|
2016-09-02 09:04:41 -06:00
|
|
|
size1 += encoderune(dum[:], r)
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
2015-01-29 23:14:13 -07:00
|
|
|
s, b := rawstringtmp(buf, size1+3)
|
2014-06-17 00:03:03 -06:00
|
|
|
size2 := 0
|
|
|
|
for _, r := range a {
|
|
|
|
// check for race
|
|
|
|
if size2 >= size1 {
|
|
|
|
break
|
|
|
|
}
|
2016-09-02 09:04:41 -06:00
|
|
|
size2 += encoderune(b[size2:], r)
|
2014-06-17 00:03:03 -06:00
|
|
|
}
|
|
|
|
return s[:size2]
|
|
|
|
}
|
|
|
|
|
2014-06-17 22:59:50 -06:00
|
|
|
type stringStruct struct {
|
2014-07-16 15:16:19 -06:00
|
|
|
str unsafe.Pointer
|
2014-06-17 22:59:50 -06:00
|
|
|
len int
|
|
|
|
}
|
|
|
|
|
2015-10-20 01:35:12 -06:00
|
|
|
// Variant with *byte pointer type for DWARF debugging.
|
|
|
|
type stringStructDWARF struct {
|
|
|
|
str *byte
|
|
|
|
len int
|
|
|
|
}
|
|
|
|
|
|
|
|
func stringStructOf(sp *string) *stringStruct {
|
|
|
|
return (*stringStruct)(unsafe.Pointer(sp))
|
|
|
|
}
|
|
|
|
|
2015-01-27 22:42:20 -07:00
|
|
|
func intstring(buf *[4]byte, v int64) string {
|
|
|
|
var s string
|
|
|
|
var b []byte
|
|
|
|
if buf != nil {
|
|
|
|
b = buf[:]
|
|
|
|
s = slicebytetostringtmp(b)
|
|
|
|
} else {
|
|
|
|
s, b = rawstring(4)
|
|
|
|
}
|
2016-03-31 03:04:12 -06:00
|
|
|
if int64(rune(v)) != v {
|
2016-09-02 09:04:41 -06:00
|
|
|
v = runeError
|
2016-03-31 03:04:12 -06:00
|
|
|
}
|
2016-09-02 09:04:41 -06:00
|
|
|
n := encoderune(b, rune(v))
|
2014-06-17 00:03:03 -06:00
|
|
|
return s[:n]
|
|
|
|
}
|
|
|
|
|
2014-07-30 10:01:52 -06:00
|
|
|
// rawstring allocates storage for a new string. The returned
|
|
|
|
// string and byte slice both refer to the same storage.
|
|
|
|
// The storage is not zeroed. Callers should use
|
|
|
|
// b to set the string contents and then drop b.
|
|
|
|
func rawstring(size int) (s string, b []byte) {
|
2016-04-19 20:35:10 -06:00
|
|
|
p := mallocgc(uintptr(size), nil, false)
|
2014-07-30 10:01:52 -06:00
|
|
|
|
2015-10-20 01:35:12 -06:00
|
|
|
stringStructOf(&s).str = p
|
|
|
|
stringStructOf(&s).len = size
|
2014-07-30 10:01:52 -06:00
|
|
|
|
2015-04-10 16:01:54 -06:00
|
|
|
*(*slice)(unsafe.Pointer(&b)) = slice{p, size, size}
|
2014-07-30 10:01:52 -06:00
|
|
|
|
2016-09-06 02:38:16 -06:00
|
|
|
return
|
2014-07-30 10:01:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// rawbyteslice allocates a new byte slice. The byte slice is not zeroed.
|
|
|
|
func rawbyteslice(size int) (b []byte) {
|
2014-12-29 00:16:32 -07:00
|
|
|
cap := roundupsize(uintptr(size))
|
2016-04-19 20:35:10 -06:00
|
|
|
p := mallocgc(cap, nil, false)
|
2014-07-30 10:01:52 -06:00
|
|
|
if cap != uintptr(size) {
|
2016-10-17 16:41:56 -06:00
|
|
|
memclrNoHeapPointers(add(p, uintptr(size)), cap-uintptr(size))
|
2014-07-30 10:01:52 -06:00
|
|
|
}
|
|
|
|
|
2015-04-10 16:01:54 -06:00
|
|
|
*(*slice)(unsafe.Pointer(&b)) = slice{p, size, int(cap)}
|
2014-07-30 10:01:52 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// rawruneslice allocates a new rune slice. The rune slice is not zeroed.
|
|
|
|
func rawruneslice(size int) (b []rune) {
|
2014-11-11 15:05:02 -07:00
|
|
|
if uintptr(size) > _MaxMem/4 {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("out of memory")
|
2014-07-30 10:01:52 -06:00
|
|
|
}
|
2014-12-29 00:16:32 -07:00
|
|
|
mem := roundupsize(uintptr(size) * 4)
|
2016-04-19 20:35:10 -06:00
|
|
|
p := mallocgc(mem, nil, false)
|
2014-07-30 10:01:52 -06:00
|
|
|
if mem != uintptr(size)*4 {
|
2016-10-17 16:41:56 -06:00
|
|
|
memclrNoHeapPointers(add(p, uintptr(size)*4), mem-uintptr(size)*4)
|
2014-07-30 10:01:52 -06:00
|
|
|
}
|
|
|
|
|
2015-04-10 16:01:54 -06:00
|
|
|
*(*slice)(unsafe.Pointer(&b)) = slice{p, size, int(mem / 4)}
|
2014-07-30 10:01:52 -06:00
|
|
|
return
|
|
|
|
}
|
liblink, runtime: diagnose and fix C code running on Go stack
This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.
The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.
This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.
Fixes #8667.
LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043
2014-09-08 12:05:23 -06:00
|
|
|
|
|
|
|
// used by cmd/cgo
|
|
|
|
func gobytes(p *byte, n int) []byte {
|
|
|
|
if n == 0 {
|
|
|
|
return make([]byte, 0)
|
|
|
|
}
|
|
|
|
x := make([]byte, n)
|
|
|
|
memmove(unsafe.Pointer(&x[0]), unsafe.Pointer(p), uintptr(n))
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
func gostring(p *byte) string {
|
|
|
|
l := findnull(p)
|
|
|
|
if l == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
s, b := rawstring(l)
|
|
|
|
memmove(unsafe.Pointer(&b[0]), unsafe.Pointer(p), uintptr(l))
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func gostringn(p *byte, l int) string {
|
|
|
|
if l == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
s, b := rawstring(l)
|
|
|
|
memmove(unsafe.Pointer(&b[0]), unsafe.Pointer(p), uintptr(l))
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func index(s, t string) int {
|
|
|
|
if len(t) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
if s[i] == t[0] && hasprefix(s[i:], t) {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func contains(s, t string) bool {
|
|
|
|
return index(s, t) >= 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasprefix(s, t string) bool {
|
|
|
|
return len(s) >= len(t) && s[:len(t)] == t
|
|
|
|
}
|
2014-11-11 15:05:02 -07:00
|
|
|
|
2016-10-29 17:54:19 -06:00
|
|
|
const (
|
|
|
|
maxUint = ^uint(0)
|
|
|
|
maxInt = int(maxUint >> 1)
|
|
|
|
)
|
|
|
|
|
|
|
|
// atoi parses an int from a string s.
|
|
|
|
// The bool result reports whether s is a number
|
|
|
|
// representable by a value of type int.
|
|
|
|
func atoi(s string) (int, bool) {
|
|
|
|
if s == "" {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
|
|
|
|
neg := false
|
|
|
|
if s[0] == '-' {
|
|
|
|
neg = true
|
2014-11-11 15:05:02 -07:00
|
|
|
s = s[1:]
|
|
|
|
}
|
2016-10-29 17:54:19 -06:00
|
|
|
|
|
|
|
un := uint(0)
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
c := s[i]
|
|
|
|
if c < '0' || c > '9' {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
if un > maxUint/10 {
|
|
|
|
// overflow
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
un *= 10
|
|
|
|
un1 := un + uint(c) - '0'
|
|
|
|
if un1 < un {
|
|
|
|
// overflow
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
un = un1
|
|
|
|
}
|
|
|
|
|
|
|
|
if !neg && un > uint(maxInt) {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
if neg && un > uint(maxInt)+1 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
|
|
|
|
n := int(un)
|
|
|
|
if neg {
|
|
|
|
n = -n
|
|
|
|
}
|
|
|
|
|
|
|
|
return n, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// atoi32 is like atoi but for integers
|
|
|
|
// that fit into an int32.
|
|
|
|
func atoi32(s string) (int32, bool) {
|
|
|
|
if n, ok := atoi(s); n == int(int32(n)) {
|
|
|
|
return int32(n), ok
|
|
|
|
}
|
|
|
|
return 0, false
|
2014-11-11 15:05:02 -07:00
|
|
|
}
|
2015-10-16 00:34:56 -06:00
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func findnull(s *byte) int {
|
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
p := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s))
|
|
|
|
l := 0
|
|
|
|
for p[l] != 0 {
|
|
|
|
l++
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func findnullw(s *uint16) int {
|
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
p := (*[_MaxMem/2/2 - 1]uint16)(unsafe.Pointer(s))
|
|
|
|
l := 0
|
|
|
|
for p[l] != 0 {
|
|
|
|
l++
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func gostringnocopy(str *byte) string {
|
|
|
|
ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)}
|
|
|
|
s := *(*string)(unsafe.Pointer(&ss))
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func gostringw(strw *uint16) string {
|
|
|
|
var buf [8]byte
|
|
|
|
str := (*[_MaxMem/2/2 - 1]uint16)(unsafe.Pointer(strw))
|
|
|
|
n1 := 0
|
|
|
|
for i := 0; str[i] != 0; i++ {
|
2016-09-02 09:04:41 -06:00
|
|
|
n1 += encoderune(buf[:], rune(str[i]))
|
2015-10-16 00:34:56 -06:00
|
|
|
}
|
|
|
|
s, b := rawstring(n1 + 4)
|
|
|
|
n2 := 0
|
|
|
|
for i := 0; str[i] != 0; i++ {
|
|
|
|
// check for race
|
|
|
|
if n2 >= n1 {
|
|
|
|
break
|
|
|
|
}
|
2016-09-02 09:04:41 -06:00
|
|
|
n2 += encoderune(b[n2:], rune(str[i]))
|
2015-10-16 00:34:56 -06:00
|
|
|
}
|
|
|
|
b[n2] = 0 // for luck
|
|
|
|
return s[:n2]
|
|
|
|
}
|