2010-12-03 05:34:57 +01:00
|
|
|
/* go-unsafe-newarray.c -- unsafe.NewArray function for Go.
|
|
|
|
|
|
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
2011-11-30 01:21:52 +01:00
|
|
|
#include "runtime.h"
|
2012-11-21 08:03:38 +01:00
|
|
|
#include "arch.h"
|
|
|
|
#include "malloc.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
#include "go-type.h"
|
|
|
|
#include "interface.h"
|
|
|
|
|
2012-03-02 17:38:43 +01:00
|
|
|
/* Implement unsafe_NewArray, called from the reflect package. */
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
void *unsafe_NewArray (const struct __go_type_descriptor *, intgo)
|
2012-05-15 00:08:42 +02:00
|
|
|
asm ("reflect.unsafe_NewArray");
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
/* The dynamic type of the argument will be a pointer to a type
|
|
|
|
descriptor. */
|
|
|
|
|
|
|
|
void *
|
2012-11-21 08:03:38 +01:00
|
|
|
unsafe_NewArray (const struct __go_type_descriptor *descriptor, intgo n)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2012-11-21 08:03:38 +01:00
|
|
|
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;
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|