Fix _str.bytes to trivial version.
This commit is contained in:
parent
fef8314c2e
commit
4c7886de80
2 changed files with 28 additions and 4 deletions
|
@ -5,6 +5,7 @@ import _vec.rustrt.vbuf;
|
|||
native "rust" mod rustrt {
|
||||
type sbuf;
|
||||
fn str_buf(str s) -> sbuf;
|
||||
fn str_vec(str s) -> vec[u8];
|
||||
fn str_byte_len(str s) -> uint;
|
||||
fn str_alloc(uint n_bytes) -> str;
|
||||
fn str_from_vec(vec[mutable? u8] b) -> str;
|
||||
|
@ -126,10 +127,7 @@ fn buf(str s) -> sbuf {
|
|||
}
|
||||
|
||||
fn bytes(str s) -> vec[u8] {
|
||||
fn ith(str s, uint i) -> u8 {
|
||||
ret s.(i);
|
||||
}
|
||||
ret _vec.init_fn[u8](bind ith(s, _), byte_len(s));
|
||||
ret rustrt.str_vec(s);
|
||||
}
|
||||
|
||||
fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
|
||||
|
|
|
@ -219,6 +219,32 @@ str_buf(rust_task *task, rust_str *s)
|
|||
return (char const *)&s->data[0];
|
||||
}
|
||||
|
||||
extern "C" CDECL rust_vec*
|
||||
str_vec(rust_task *task, rust_str *s)
|
||||
{
|
||||
// FIXME: this should just upref s and return it, but we
|
||||
// accidentally made too much of the language and runtime know
|
||||
// and care about the difference between str and vec (trailing null);
|
||||
// eliminate these differences and then rewrite this back to just
|
||||
// the following:
|
||||
//
|
||||
// if (s->ref_count != CONST_REFCOUNT)
|
||||
// s->ref();
|
||||
// return s;
|
||||
|
||||
rust_str *v =
|
||||
vec_alloc_with_data(task,
|
||||
s->fill - 1,
|
||||
s->fill - 1,
|
||||
1,
|
||||
(s->fill - 1) ? (void*)s->data : NULL);
|
||||
if (!v) {
|
||||
task->fail(2);
|
||||
return NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
extern "C" CDECL size_t
|
||||
str_byte_len(rust_task *task, rust_str *s)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue