mirror of
https://github.com/golang/go
synced 2024-11-12 05:40:22 -07:00
undo CL 8363045 / a3ce42f9748b
It changes an exported API, and breaks the build. ««« original CL description reflect: use unsafe.Pointer in StringHeader and SliceHeader Relates to issue 5193. R=r CC=golang-dev https://golang.org/cl/8363045 »»» R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/8357051
This commit is contained in:
parent
487721fd0d
commit
2be84a8c2b
@ -910,7 +910,7 @@ func (v Value) Index(i int) Value {
|
|||||||
tt := (*sliceType)(unsafe.Pointer(v.typ))
|
tt := (*sliceType)(unsafe.Pointer(v.typ))
|
||||||
typ := tt.elem
|
typ := tt.elem
|
||||||
fl |= flag(typ.Kind()) << flagKindShift
|
fl |= flag(typ.Kind()) << flagKindShift
|
||||||
val := unsafe.Pointer(uintptr(s.Data) + uintptr(i)*typ.size)
|
val := unsafe.Pointer(s.Data + uintptr(i)*typ.size)
|
||||||
return Value{typ, val, fl}
|
return Value{typ, val, fl}
|
||||||
|
|
||||||
case String:
|
case String:
|
||||||
@ -919,7 +919,7 @@ func (v Value) Index(i int) Value {
|
|||||||
if i < 0 || i >= s.Len {
|
if i < 0 || i >= s.Len {
|
||||||
panic("reflect: string index out of range")
|
panic("reflect: string index out of range")
|
||||||
}
|
}
|
||||||
val := *(*byte)(unsafe.Pointer(uintptr(s.Data) + uintptr(i)))
|
val := *(*byte)(unsafe.Pointer(s.Data + uintptr(i)))
|
||||||
return Value{uint8Type, unsafe.Pointer(uintptr(val)), fl}
|
return Value{uint8Type, unsafe.Pointer(uintptr(val)), fl}
|
||||||
}
|
}
|
||||||
panic(&ValueError{"reflect.Value.Index", k})
|
panic(&ValueError{"reflect.Value.Index", k})
|
||||||
@ -1310,7 +1310,7 @@ func (v Value) Pointer() uintptr {
|
|||||||
return uintptr(p)
|
return uintptr(p)
|
||||||
|
|
||||||
case Slice:
|
case Slice:
|
||||||
return uintptr((*SliceHeader)(v.val).Data)
|
return (*SliceHeader)(v.val).Data
|
||||||
}
|
}
|
||||||
panic(&ValueError{"reflect.Value.Pointer", k})
|
panic(&ValueError{"reflect.Value.Pointer", k})
|
||||||
}
|
}
|
||||||
@ -1565,7 +1565,7 @@ func (v Value) Slice(beg, end int) Value {
|
|||||||
}
|
}
|
||||||
var x string
|
var x string
|
||||||
val := (*StringHeader)(unsafe.Pointer(&x))
|
val := (*StringHeader)(unsafe.Pointer(&x))
|
||||||
val.Data = unsafe.Pointer(uintptr(s.Data) + uintptr(beg))
|
val.Data = s.Data + uintptr(beg)
|
||||||
val.Len = end - beg
|
val.Len = end - beg
|
||||||
return Value{v.typ, unsafe.Pointer(&x), v.flag}
|
return Value{v.typ, unsafe.Pointer(&x), v.flag}
|
||||||
}
|
}
|
||||||
@ -1579,7 +1579,7 @@ func (v Value) Slice(beg, end int) Value {
|
|||||||
|
|
||||||
// Reinterpret as *SliceHeader to edit.
|
// Reinterpret as *SliceHeader to edit.
|
||||||
s := (*SliceHeader)(unsafe.Pointer(&x))
|
s := (*SliceHeader)(unsafe.Pointer(&x))
|
||||||
s.Data = unsafe.Pointer(uintptr(base) + uintptr(beg)*typ.elem.Size())
|
s.Data = uintptr(base) + uintptr(beg)*typ.elem.Size()
|
||||||
s.Len = end - beg
|
s.Len = end - beg
|
||||||
s.Cap = cap - beg
|
s.Cap = cap - beg
|
||||||
|
|
||||||
@ -1701,14 +1701,14 @@ func (v Value) UnsafeAddr() uintptr {
|
|||||||
// StringHeader is the runtime representation of a string.
|
// StringHeader is the runtime representation of a string.
|
||||||
// It cannot be used safely or portably.
|
// It cannot be used safely or portably.
|
||||||
type StringHeader struct {
|
type StringHeader struct {
|
||||||
Data unsafe.Pointer
|
Data uintptr
|
||||||
Len int
|
Len int
|
||||||
}
|
}
|
||||||
|
|
||||||
// SliceHeader is the runtime representation of a slice.
|
// SliceHeader is the runtime representation of a slice.
|
||||||
// It cannot be used safely or portably.
|
// It cannot be used safely or portably.
|
||||||
type SliceHeader struct {
|
type SliceHeader struct {
|
||||||
Data unsafe.Pointer
|
Data uintptr
|
||||||
Len int
|
Len int
|
||||||
Cap int
|
Cap int
|
||||||
}
|
}
|
||||||
@ -1988,7 +1988,7 @@ func MakeSlice(typ Type, len, cap int) Value {
|
|||||||
|
|
||||||
// Reinterpret as *SliceHeader to edit.
|
// Reinterpret as *SliceHeader to edit.
|
||||||
s := (*SliceHeader)(unsafe.Pointer(&x))
|
s := (*SliceHeader)(unsafe.Pointer(&x))
|
||||||
s.Data = unsafe_NewArray(typ.Elem().(*rtype), cap)
|
s.Data = uintptr(unsafe_NewArray(typ.Elem().(*rtype), cap))
|
||||||
s.Len = len
|
s.Len = len
|
||||||
s.Cap = cap
|
s.Cap = cap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user