mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-02-02 15:30:36 +01:00
Use the modern unsafe replacement of reflect
As of Go1.20, “safer” versions of pointer casting are available to point to the same address. Use them.
This commit is contained in:
parent
d8d85b3536
commit
951bf2c8bd
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
||||||
module github.com/stianeikeland/go-rpio/v4
|
module github.com/stianeikeland/go-rpio/v4
|
||||||
|
|
||||||
go 1.15
|
go 1.21
|
||||||
|
|
6
rpio.go
6
rpio.go
|
@ -73,7 +73,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -803,10 +802,7 @@ func memMap(fd uintptr, base int64) (mem []uint32, mem8 []byte, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Convert mapped byte memory to unsafe []uint32 pointer, adjust length as needed
|
// Convert mapped byte memory to unsafe []uint32 pointer, adjust length as needed
|
||||||
header := *(*reflect.SliceHeader)(unsafe.Pointer(&mem8))
|
mem = unsafe.Slice((*uint32)(unsafe.Pointer(unsafe.SliceData(mem8))), len(mem8)/4)
|
||||||
header.Len /= (32 / 8) // (32 bit = 4 bytes)
|
|
||||||
header.Cap /= (32 / 8)
|
|
||||||
mem = *(*[]uint32)(unsafe.Pointer(&header))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user