re PR c++/64514 (Error in template instantiation in GCC 4.9, works fine in GCC 4.8)
[official-gcc.git] / libgo / runtime / go-string-to-byte-array.c
bloba4edb50da5f72b8324684600927c14e0665b1ce8
1 /* go-string-to-byte-array.c -- convert a string to an array of bytes in Go.
3 Copyright 2010 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. */
7 #include "runtime.h"
8 #include "array.h"
9 #include "arch.h"
10 #include "malloc.h"
12 struct __go_open_array
13 __go_string_to_byte_array (String str)
15 uintptr cap;
16 unsigned char *data;
17 struct __go_open_array ret;
19 cap = runtime_roundupsize (str.len);
20 data = (unsigned char *) runtime_mallocgc (cap, 0, FlagNoScan | FlagNoZero);
21 __builtin_memcpy (data, str.str, str.len);
22 if (cap != (uintptr) str.len)
23 __builtin_memset (data + str.len, 0, cap - (uintptr) str.len);
24 ret.__values = (void *) data;
25 ret.__count = str.len;
26 ret.__capacity = (intgo) cap;
27 return ret;