1 /* go-make-slice.c -- make a slice.
3 Copyright 2011 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. */
10 #include "go-assert.h"
17 struct __go_open_array
18 __go_make_slice2 (const struct __go_type_descriptor *td, uintptr_t len,
21 const struct __go_slice_type* std;
25 struct __go_open_array ret;
28 __go_assert (td->__code == GO_SLICE);
29 std = (const struct __go_slice_type *) td;
32 if (ilen < 0 || (uintptr_t) ilen != len)
33 __go_panic_msg ("makeslice: len out of range");
37 || (uintptr_t) icap != cap
38 || (std->__element_type->__size > 0
39 && cap > (uintptr_t) -1U / std->__element_type->__size))
40 __go_panic_msg ("makeslice: cap out of range");
43 ret.__capacity = icap;
45 size = cap * std->__element_type->__size;
46 flag = ((std->__element_type->__code & GO_NO_POINTERS) != 0
49 ret.__values = runtime_mallocgc (size, flag, 1, 1);
54 struct __go_open_array
55 __go_make_slice1 (const struct __go_type_descriptor *td, uintptr_t len)
57 return __go_make_slice2 (td, len, len);