Retro68/gcc/libgo/runtime/go-string-to-byte-array.c

29 lines
817 B
C
Raw Normal View History

2012-03-27 23:13:14 +00:00
/* go-string-to-byte-array.c -- convert a string to an array of bytes in Go.
Copyright 2010 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include "runtime.h"
2014-09-21 17:33:12 +00:00
#include "array.h"
2012-03-27 23:13:14 +00:00
#include "arch.h"
#include "malloc.h"
struct __go_open_array
2014-09-21 17:33:12 +00:00
__go_string_to_byte_array (String str)
2012-03-27 23:13:14 +00:00
{
2015-08-28 15:33:40 +00:00
uintptr cap;
2012-03-27 23:13:14 +00:00
unsigned char *data;
struct __go_open_array ret;
2015-08-28 15:33:40 +00:00
cap = runtime_roundupsize (str.len);
data = (unsigned char *) runtime_mallocgc (cap, 0, FlagNoScan | FlagNoZero);
2014-09-21 17:33:12 +00:00
__builtin_memcpy (data, str.str, str.len);
2015-08-28 15:33:40 +00:00
if (cap != (uintptr) str.len)
__builtin_memset (data + str.len, 0, cap - (uintptr) str.len);
2012-03-27 23:13:14 +00:00
ret.__values = (void *) data;
2014-09-21 17:33:12 +00:00
ret.__count = str.len;
2017-04-10 11:32:00 +00:00
ret.__capacity = str.len;
2012-03-27 23:13:14 +00:00
return ret;
}