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"
18 struct __go_open_array
19 __go_make_slice2 (const struct __go_type_descriptor *td, uintptr_t len,
22 const struct __go_slice_type* std;
26 struct __go_open_array ret;
29 __go_assert (td->__code == GO_SLICE);
30 std = (const struct __go_slice_type *) td;
33 if (ilen < 0 || (uintptr_t) ilen != len)
34 runtime_panicstring ("makeslice: len out of range");
38 || (uintptr_t) icap != cap
39 || (std->__element_type->__size > 0
40 && cap > MaxMem / std->__element_type->__size))
41 runtime_panicstring ("makeslice: cap out of range");
44 ret.__capacity = icap;
46 size = cap * std->__element_type->__size;
47 flag = ((std->__element_type->__code & GO_NO_POINTERS) != 0
50 ret.__values = runtime_mallocgc (size, flag, 1, 1);
55 struct __go_open_array
56 __go_make_slice1 (const struct __go_type_descriptor *td, uintptr_t len)
58 return __go_make_slice2 (td, len, len);
61 struct __go_open_array
62 __go_make_slice2_big (const struct __go_type_descriptor *td, uint64_t len,
68 slen = (uintptr_t) len;
69 if ((uint64_t) slen != len)
70 runtime_panicstring ("makeslice: len out of range");
72 scap = (uintptr_t) cap;
73 if ((uint64_t) scap != cap)
74 runtime_panicstring ("makeslice: cap out of range");
76 return __go_make_slice2 (td, slen, scap);
79 struct __go_open_array
80 __go_make_slice1_big (const struct __go_type_descriptor *td, uint64_t len)
82 return __go_make_slice2_big (td, len, len);