all: replace unsafe slice operations with unsafe.Slice

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-03-02 15:37:34 +01:00
parent af8ca96414
commit fea2f888bb
6 changed files with 13 additions and 38 deletions
+1 -1
View File
@@ -1172,7 +1172,7 @@ func newUniformBuffer(b driver.Device, uniformBlock interface{}) *uniformBuffer
// Determine the size of the uniforms structure, *uniforms.
size := ref.Elem().Type().Size()
// Map the uniforms structure as a byte slice.
ptr := (*[1 << 30]byte)(unsafe.Pointer(ref.Pointer()))[:size:size]
ptr := unsafe.Slice((*byte)(unsafe.Pointer(ref.Pointer())), size)
ubuf, err := b.NewBuffer(driver.BufferBindingUniforms, len(ptr))
if err != nil {
panic(err)
+1 -7
View File
@@ -7,7 +7,6 @@ import (
"fmt"
"image"
"math"
"reflect"
"unsafe"
"golang.org/x/sys/windows"
@@ -850,10 +849,5 @@ func toBlendFactor(f driver.BlendFactor) (uint32, uint32) {
// sliceOf returns a slice from a (native) pointer.
func sliceOf(ptr uintptr, cap int) []byte {
var data []byte
h := (*reflect.SliceHeader)(unsafe.Pointer(&data))
h.Data = ptr
h.Cap = cap
h.Len = cap
return data
return unsafe.Slice((*byte)(unsafe.Pointer(ptr)), cap)
}