Exemple #1
0
Hchan*
runtime_makechan_c(ChanType *t, int64 hint)
{
	Hchan *c;
	uintptr n;
	const Type *elem;

	elem = t->__element_type;

	// compiler checks this but be safe.
	if(elem->__size >= (1<<16))
		runtime_throw("makechan: invalid channel element type");

	if(hint < 0 || (intgo)hint != hint || (elem->__size > 0 && (uintptr)hint > MaxMem / elem->__size))
		runtime_panicstring("makechan: size out of range");

	n = sizeof(*c);

	// allocate memory in one call
	c = (Hchan*)runtime_mal(n + hint*elem->__size);
	c->elemsize = elem->__size;
	c->elemalign = elem->__align;
	c->dataqsiz = hint;
	runtime_settype(c, (uintptr)t | TypeInfo_Chan);

	if(debug)
		runtime_printf("makechan: chan=%p; elemsize=%D; elemalign=%d; dataqsiz=%D\n",
			c, (int64)elem->__size, elem->__align, (int64)c->dataqsiz);

	return c;
}
void *
unsafe_New (const struct __go_type_descriptor *descriptor)
{
  uint32 flag;
  void *ret;

  flag = (descriptor->__code & GO_NO_POINTERS) != 0 ? FlagNoPointers : 0;
  ret = runtime_mallocgc (descriptor->__size, flag, 1, 1);

  if (UseSpanType && flag == 0)
    runtime_settype (ret, (uintptr) descriptor | TypeInfo_SingleObject);

  return ret;
}
Exemple #3
0
void *
unsafe_NewArray (const struct __go_type_descriptor *descriptor, intgo 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;
}