aboutsummaryrefslogtreecommitdiff
path: root/util/util.go
diff options
context:
space:
mode:
authorJoseph Richey <joerichey@google.com>2017-08-15 13:46:04 -0700
committerGitHub <noreply@github.com>2017-08-15 13:46:04 -0700
commit1281987135c92ca6187e48bc24a824a7a2efa4e5 (patch)
treecfbcfd0ecb6f5d945253ad7d9b03ab602fa5eb3c /util/util.go
parent8e234ec2cbbb4214ca493ddff18257f0c7605ee1 (diff)
parent778a9e762cba5ebb6e03b12018e354ac1b38023b (diff)
Merge pull request #36 from google/memory
util: Slice/Pointer conversion fits in MatInt32
Diffstat (limited to 'util/util.go')
-rw-r--r--util/util.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/util/util.go b/util/util.go
index 792b66c..14d23e2 100644
--- a/util/util.go
+++ b/util/util.go
@@ -25,6 +25,7 @@ package util
import (
"bufio"
+ "math"
"os"
"unsafe"
)
@@ -40,13 +41,15 @@ func Ptr(slice []byte) unsafe.Pointer {
// ByteSlice takes a pointer to some data and views it as a slice of bytes.
// Note, indexing into this slice is unsafe.
func ByteSlice(ptr unsafe.Pointer) []byte {
- return (*[1 << 30]byte)(ptr)[:]
+ // Silce must fix in 32-bit address space to build on 32-bit platforms.
+ return (*[math.MaxInt32]byte)(ptr)[:]
}
// PointerSlice takes a pointer to an array of pointers and views it as a slice
// of pointers. Note, indexing into this slice is unsafe.
func PointerSlice(ptr unsafe.Pointer) []unsafe.Pointer {
- return (*[1 << 30]unsafe.Pointer)(ptr)[:]
+ // Silce must fix in 32-bit address space to build on 32-bit platforms.
+ return (*[math.MaxInt32 / 4]unsafe.Pointer)(ptr)[:]
}
// Index returns the first index i such that inVal == inArray[i].