]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use type int to specify size for newarray
authorMartin Möhrmann <martisch@uos.de>
Wed, 20 Apr 2016 16:00:52 +0000 (18:00 +0200)
committerMartin Möhrmann <martisch@uos.de>
Thu, 21 Apr 2016 04:15:14 +0000 (04:15 +0000)
Consistently use type int for the size argument of
runtime.newarray, runtime.reflect_unsafe_NewArray
and reflect.unsafe_NewArray.

Change-Id: Ic77bf2dde216c92ca8c49462f8eedc0385b6314e
Reviewed-on: https://go-review.googlesource.com/22311
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/chan.go
src/runtime/hashmap.go
src/runtime/malloc.go

index 3fb0236785206c3e8106c842c50dcdb6a8d21303..712ad8cef95a29e5184874c1ed5249f4df255abe 100644 (file)
@@ -84,7 +84,7 @@ func makechan(t *chantype, size int64) *hchan {
                }
        } else {
                c = new(hchan)
-               c.buf = newarray(elem, uintptr(size))
+               c.buf = newarray(elem, int(size))
        }
        c.elemsize = uint16(elem.size)
        c.elemtype = elem
index ff59faab5d92bbb9f2d3fbe88b96f5e91e6b5c4e..509cab2f0f0565b683369216fa0f74bbb434af39 100644 (file)
@@ -246,7 +246,7 @@ func makemap(t *maptype, hint int64, h *hmap, bucket unsafe.Pointer) *hmap {
        // If hint is large zeroing this memory could take a while.
        buckets := bucket
        if B != 0 {
-               buckets = newarray(t.bucket, uintptr(1)<<B)
+               buckets = newarray(t.bucket, 1<<B)
        }
 
        // initialize Hmap
@@ -821,7 +821,7 @@ func hashGrow(t *maptype, h *hmap) {
                throw("evacuation not done in time")
        }
        oldbuckets := h.buckets
-       newbuckets := newarray(t.bucket, uintptr(1)<<(h.B+1))
+       newbuckets := newarray(t.bucket, 1<<(h.B+1))
        flags := h.flags &^ (iterator | oldIterator)
        if h.flags&iterator != 0 {
                flags |= oldIterator
index 95d24a467aa5b0cd5d7a66ad406fabf941cb2ff3..30f2a4fca54415dd5b1c224d228a22d86e742954 100644 (file)
@@ -770,16 +770,16 @@ func reflect_unsafe_New(typ *_type) unsafe.Pointer {
        return newobject(typ)
 }
 
-// implementation of make builtin for slices
-func newarray(typ *_type, n uintptr) unsafe.Pointer {
-       if int(n) < 0 || n > maxSliceCap(typ.size) {
+// newarray allocates an array of n elements of type typ.
+func newarray(typ *_type, n int) unsafe.Pointer {
+       if n < 0 || uintptr(n) > maxSliceCap(typ.size) {
                panic(plainError("runtime: allocation size out of range"))
        }
-       return mallocgc(typ.size*n, typ, true)
+       return mallocgc(typ.size*uintptr(n), typ, true)
 }
 
 //go:linkname reflect_unsafe_NewArray reflect.unsafe_NewArray
-func reflect_unsafe_NewArray(typ *_type, n uintptr) unsafe.Pointer {
+func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer {
        return newarray(typ, n)
 }