aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/slice.c
diff options
context:
space:
mode:
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>2012-10-21 17:41:32 -0400
committerRuss Cox <rsc@golang.org>2012-10-21 17:41:32 -0400
commit4a191c2c1b3fe1325ab8617472aef628fd494076 (patch)
treef257db791881a8690e69ae85100f4d8b01a4f161 /src/pkg/runtime/slice.c
parent4545dc6a6953b2be6d0d50719ad165d46278d9bf (diff)
downloadgo-4a191c2c1b3fe1325ab8617472aef628fd494076.tar.xz
runtime: store types of allocated objects
R=rsc CC=golang-dev https://golang.org/cl/6569057
Diffstat (limited to 'src/pkg/runtime/slice.c')
-rw-r--r--src/pkg/runtime/slice.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c
index d24f6a88ae..3ec44b875f 100644
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -38,7 +38,7 @@ runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
// Dummy word to use as base pointer for make([]T, 0).
// Since you cannot take the address of such a slice,
// you can't tell that they all have the same base pointer.
-static uintptr zerobase;
+uintptr runtime·zerobase;
static void
makeslice1(SliceType *t, intgo len, intgo cap, Slice *ret)
@@ -50,12 +50,20 @@ makeslice1(SliceType *t, intgo len, intgo cap, Slice *ret)
ret->len = len;
ret->cap = cap;
- if(cap == 0)
- ret->array = (byte*)&zerobase;
+ if(size == 0)
+ ret->array = (byte*)&runtime·zerobase;
else if((t->elem->kind&KindNoPointers))
ret->array = runtime·mallocgc(size, FlagNoPointers, 1, 1);
- else
- ret->array = runtime·mal(size);
+ else {
+ ret->array = runtime·mallocgc(size, 0, 1, 1);
+
+ if(UseSpanType) {
+ if(false) {
+ runtime·printf("new slice [%D]%S: %p\n", (int64)cap, *t->elem->string, ret->array);
+ }
+ runtime·settype(ret->array, (uintptr)t->elem | TypeInfo_Array);
+ }
+ }
}
// appendslice(type *Type, x, y, []T) []T