Skip to content

Commit

Permalink
fix(arm): grow slice not clear mem
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Jul 16, 2024
1 parent 456a3b9 commit a19ed7f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 83 deletions.
4 changes: 2 additions & 2 deletions internal/rt/growslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package rt

import "unsafe"

func GrowSlice(et *GoType, old GoSlice, cap int) GoSlice {
s := growslice(old.Ptr, cap, old.Cap, cap - old.Len, et)
func GrowSlice(et *GoType, old GoSlice, newLen int) GoSlice {
s := growslice(old.Ptr, newLen, old.Cap, newLen - old.Len, et)
s.Len = old.Len
return s
}
Expand Down
45 changes: 0 additions & 45 deletions internal/rt/rt_stubs_go116.go

This file was deleted.

36 changes: 0 additions & 36 deletions internal/rt/rt_stubs_go120.go

This file was deleted.

36 changes: 36 additions & 0 deletions internal/rt/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,39 @@ func GetMap64Assign(vt reflect.Type) Map64Assign {

var emptyBytes = make([]byte, 0, 0)
var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes))

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
return &GoSlice{
Ptr: makeslice(et, newLen, newLen),
Len: newLen,
Cap: newLen,
}
}

old := (*GoSlice)(oldPtr)
if old.Cap >= newLen {
old.Len = newLen
return old
}

new := GrowSlice(et, *old, newLen)

// we sould clear the memory from [oldLen:newLen]
if et.PtrData == 0 {
oldlenmem := uintptr(old.Len) * et.Size
newlenmem := uintptr(newLen) * et.Size
MemclrNoHeapPointers(add(new.Ptr, oldlenmem), newlenmem-oldlenmem)
}

new.Len = newLen
return &new
}

0 comments on commit a19ed7f

Please sign in to comment.