2010-12-03 05:34:57 +01: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"
|
2012-11-01 04:02:13 +01:00
|
|
|
#include "array.h"
|
2011-10-27 01:57:58 +02:00
|
|
|
#include "arch.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
#include "malloc.h"
|
|
|
|
|
|
|
|
struct __go_open_array
|
2012-11-01 04:02:13 +01:00
|
|
|
__go_string_to_byte_array (String str)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
unsigned char *data;
|
|
|
|
struct __go_open_array ret;
|
|
|
|
|
2013-11-06 20:49:01 +01:00
|
|
|
data = (unsigned char *) runtime_mallocgc (str.len, 0,
|
|
|
|
FlagNoScan | FlagNoZero);
|
2012-11-01 04:02:13 +01:00
|
|
|
__builtin_memcpy (data, str.str, str.len);
|
2010-12-03 05:34:57 +01:00
|
|
|
ret.__values = (void *) data;
|
2012-11-01 04:02:13 +01:00
|
|
|
ret.__count = str.len;
|
|
|
|
ret.__capacity = str.len;
|
2010-12-03 05:34:57 +01:00
|
|
|
return ret;
|
|
|
|
}
|