@@ -2184,7 +2184,7 @@ func (v Value) OverflowUint(x uint64) bool {
2184
2184
// and make an exception.
2185
2185
2186
2186
// Pointer returns v's value as a uintptr.
2187
- // It panics if v's Kind is not [Chan], [Func], [Map], [Pointer], [Slice], or [UnsafePointer].
2187
+ // It panics if v's Kind is not [Chan], [Func], [Map], [Pointer], [Slice], [String], or [UnsafePointer].
2188
2188
//
2189
2189
// If v's Kind is [Func], the returned pointer is an underlying
2190
2190
// code pointer, but not necessarily enough to identify a
@@ -2195,6 +2195,9 @@ func (v Value) OverflowUint(x uint64) bool {
2195
2195
// element of the slice. If the slice is nil the returned value
2196
2196
// is 0. If the slice is empty but non-nil the return value is non-zero.
2197
2197
//
2198
+ // If v's Kind is [String], the returned pointer is to the first
2199
+ // element of the underlying bytes of string.
2200
+ //
2198
2201
// It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result.
2199
2202
func (v Value ) Pointer () uintptr {
2200
2203
// The compiler loses track as it converts to uintptr. Force escape.
@@ -2232,9 +2235,10 @@ func (v Value) Pointer() uintptr {
2232
2235
p = * (* unsafe .Pointer )(p )
2233
2236
}
2234
2237
return uintptr (p )
2235
-
2236
2238
case Slice :
2237
2239
return uintptr ((* unsafeheader .Slice )(v .ptr ).Data )
2240
+ case String :
2241
+ return uintptr ((* unsafeheader .String )(v .ptr ).Data )
2238
2242
}
2239
2243
panic (& ValueError {"reflect.Value.Pointer" , v .kind ()})
2240
2244
}
@@ -2779,6 +2783,9 @@ func (v Value) UnsafeAddr() uintptr {
2779
2783
// If v's Kind is [Slice], the returned pointer is to the first
2780
2784
// element of the slice. If the slice is nil the returned value
2781
2785
// is nil. If the slice is empty but non-nil the return value is non-nil.
2786
+ //
2787
+ // If v's Kind is [String], the returned pointer is to the first
2788
+ // element of the underlying bytes of string.
2782
2789
func (v Value ) UnsafePointer () unsafe.Pointer {
2783
2790
k := v .kind ()
2784
2791
switch k {
@@ -2812,9 +2819,10 @@ func (v Value) UnsafePointer() unsafe.Pointer {
2812
2819
p = * (* unsafe .Pointer )(p )
2813
2820
}
2814
2821
return p
2815
-
2816
2822
case Slice :
2817
2823
return (* unsafeheader .Slice )(v .ptr ).Data
2824
+ case String :
2825
+ return (* unsafeheader .String )(v .ptr ).Data
2818
2826
}
2819
2827
panic (& ValueError {"reflect.Value.UnsafePointer" , v .kind ()})
2820
2828
}
0 commit comments