2011-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / go-unsafe-newarray.c
blob5fd81ce273335c0d791ceee357a19080419d49c9
1 /* go-unsafe-newarray.c -- unsafe.NewArray function for Go.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "go-alloc.h"
8 #include "go-panic.h"
9 #include "go-type.h"
10 #include "interface.h"
12 /* Implement unsafe.NewArray. */
14 void *NewArray (struct __go_empty_interface type, int n)
15 asm ("libgo_unsafe.unsafe.NewArray");
17 /* The dynamic type of the argument will be a pointer to a type
18 descriptor. */
20 void *
21 NewArray (struct __go_empty_interface type, int n)
23 const struct __go_type_descriptor *descriptor;
25 if (((uintptr_t) type.__type_descriptor & reflectFlags) != 0)
26 __go_panic_msg ("invalid interface value");
28 /* FIXME: We should check __type_descriptor to verify that this is
29 really a type descriptor. */
30 descriptor = (const struct __go_type_descriptor *) type.__object;
31 return __go_alloc (descriptor->__size * n);