summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-unsafe-newarray.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-unsafe-newarray.c')
-rw-r--r--libgo/runtime/go-unsafe-newarray.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/libgo/runtime/go-unsafe-newarray.c b/libgo/runtime/go-unsafe-newarray.c
index 67399eac88c..47dcd847e64 100644
--- a/libgo/runtime/go-unsafe-newarray.c
+++ b/libgo/runtime/go-unsafe-newarray.c
@@ -5,28 +5,37 @@
license that can be found in the LICENSE file. */
#include "runtime.h"
-#include "go-alloc.h"
+#include "arch.h"
+#include "malloc.h"
#include "go-type.h"
#include "interface.h"
/* Implement unsafe_NewArray, called from the reflect package. */
-void *unsafe_NewArray (struct __go_empty_interface type, int n)
+void *unsafe_NewArray (const struct __go_type_descriptor *, intgo)
asm ("reflect.unsafe_NewArray");
/* The dynamic type of the argument will be a pointer to a type
descriptor. */
void *
-unsafe_NewArray (struct __go_empty_interface type, int n)
+unsafe_NewArray (const struct __go_type_descriptor *descriptor, intgo n)
{
- const struct __go_type_descriptor *descriptor;
-
- if (((uintptr_t) type.__type_descriptor & reflectFlags) != 0)
- runtime_panicstring ("invalid interface value");
-
- /* FIXME: We should check __type_descriptor to verify that this is
- really a type descriptor. */
- descriptor = (const struct __go_type_descriptor *) type.__object;
- return __go_alloc (descriptor->__size * n);
+ uint64 size;
+ void *ret;
+
+ size = n * descriptor->__size;
+ if (size == 0)
+ ret = &runtime_zerobase;
+ else if ((descriptor->__code & GO_NO_POINTERS) != 0)
+ ret = runtime_mallocgc (size, FlagNoPointers, 1, 1);
+ else
+ {
+ ret = runtime_mallocgc (size, 0, 1, 1);
+
+ if (UseSpanType)
+ runtime_settype (ret, (uintptr) descriptor | TypeInfo_Array);
+ }
+
+ return ret;
}