Fix _str.bytes to trivial version.

This commit is contained in:
Graydon Hoare
2011-04-27 13:06:19 -07:00
parent fef8314c2e
commit 4c7886de80
2 changed files with 28 additions and 4 deletions

View File

@@ -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)
{