PR target/60017
[official-gcc.git] / libgo / runtime / go-string-to-int-array.c
blobd91c9e2df82c00d536cda19f6b04f6f1b30d3605
1 /* go-string-to-int-array.c -- convert a string to an array of ints 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 "go-alloc.h"
9 #include "go-string.h"
10 #include "array.h"
11 #include "arch.h"
12 #include "malloc.h"
14 struct __go_open_array
15 __go_string_to_int_array (String str)
17 size_t c;
18 const unsigned char *p;
19 const unsigned char *pend;
20 uint32_t *data;
21 uint32_t *pd;
22 struct __go_open_array ret;
24 c = 0;
25 p = str.str;
26 pend = p + str.len;
27 while (p < pend)
29 int rune;
31 ++c;
32 p += __go_get_rune (p, pend - p, &rune);
35 data = (uint32_t *) runtime_mallocgc (c * sizeof (uint32_t), 0,
36 FlagNoScan | FlagNoZero);
37 p = str.str;
38 pd = data;
39 while (p < pend)
41 int rune;
43 p += __go_get_rune (p, pend - p, &rune);
44 *pd++ = rune;
47 ret.__values = (void *) data;
48 ret.__count = c;
49 ret.__capacity = c;
50 return ret;