re PR go/52358 (math FAILs on Solaris 8 and 9)
[gcc.git] / libgo / runtime / go-unsafe-new.c
1 /* go-unsafe-new.c -- unsafe.New function for Go.
2
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. */
6
7 #include "runtime.h"
8 #include "go-alloc.h"
9 #include "go-type.h"
10 #include "interface.h"
11
12 /* Implement unsafe_New, called from the reflect package. */
13
14 void *unsafe_New (struct __go_empty_interface type)
15 asm ("libgo_reflect.reflect.unsafe_New");
16
17 /* The dynamic type of the argument will be a pointer to a type
18 descriptor. */
19
20 void *
21 unsafe_New (struct __go_empty_interface type)
22 {
23 const struct __go_type_descriptor *descriptor;
24
25 if (((uintptr_t) type.__type_descriptor & reflectFlags) != 0)
26 runtime_panicstring ("invalid interface value");
27
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);
32 }