File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -8512,3 +8512,19 @@ func TestClear(t *testing.T) {
8512
8512
})
8513
8513
}
8514
8514
}
8515
+
8516
+ func TestSliceAt (t * testing.T ) {
8517
+ s := make ([]string , 10 )
8518
+ et := TypeOf (s ).Elem ()
8519
+ len := 5
8520
+ v := SliceAt (et , unsafe .Pointer (unsafe .SliceData (s )), len )
8521
+ if v .Len () != len {
8522
+ t .Fatalf ("Value.Len() got %d, want %d" , v .Len (), len )
8523
+ }
8524
+ if v .Cap () != len {
8525
+ t .Fatalf ("Value.Cap() got %d, want %d" , v .Cap (), len )
8526
+ }
8527
+ if v .UnsafePointer () != unsafe .Pointer (unsafe .SliceData (s )) {
8528
+ t .Fatalf ("v.UnsafePointer(%p) != unsafe.SliceData(%p)" , v .UnsafePointer (), unsafe .SliceData (s ))
8529
+ }
8530
+ }
Original file line number Diff line number Diff line change @@ -3297,6 +3297,18 @@ func New(typ Type) Value {
3297
3297
return Value {pt , ptr , fl }
3298
3298
}
3299
3299
3300
+ // SliceAt returns a Value representing
3301
+ // a slice whose underlying data starts at p,
3302
+ // with length and capacity equal to len.
3303
+ // This is like unsafe.Slice.
3304
+ func SliceAt (typ Type , p unsafe.Pointer , len int ) Value {
3305
+ fl := flag (Slice )
3306
+ st := SliceOf (typ )
3307
+ s := & unsafeheader.Slice {Data : p , Len : len , Cap : len }
3308
+ t := & st .(* rtype ).t
3309
+ return Value {t , unsafe .Pointer (s ), fl }
3310
+ }
3311
+
3300
3312
// NewAt returns a Value representing a pointer to a value of the
3301
3313
// specified type, using p as that pointer.
3302
3314
func NewAt (typ Type , p unsafe.Pointer ) Value {
You can’t perform that action at this time.
0 commit comments