Skip to content

Commit 0ec8bba

Browse files
committed
---
yaml --- r: 2239 b: refs/heads/master c: 4c7886d h: refs/heads/master i: 2237: 50b4ff8 2235: 3009fbd 2231: 100b855 2223: 57067a4 2207: 941d27a 2175: 7dcbab2 v: v3
1 parent 60d6e07 commit 0ec8bba

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: fef8314c2e018d2e35c8bd91d3181de038e44de2
2+
refs/heads/master: 4c7886de8008b07e892ea741be08291dae38f7bd

trunk/src/lib/_str.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import _vec.rustrt.vbuf;
55
native "rust" mod rustrt {
66
type sbuf;
77
fn str_buf(str s) -> sbuf;
8+
fn str_vec(str s) -> vec[u8];
89
fn str_byte_len(str s) -> uint;
910
fn str_alloc(uint n_bytes) -> str;
1011
fn str_from_vec(vec[mutable? u8] b) -> str;
@@ -126,10 +127,7 @@ fn buf(str s) -> sbuf {
126127
}
127128

128129
fn bytes(str s) -> vec[u8] {
129-
fn ith(str s, uint i) -> u8 {
130-
ret s.(i);
131-
}
132-
ret _vec.init_fn[u8](bind ith(s, _), byte_len(s));
130+
ret rustrt.str_vec(s);
133131
}
134132

135133
fn from_bytes(vec[u8] v) : is_utf8(v) -> str {

trunk/src/rt/rust_builtin.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,32 @@ str_buf(rust_task *task, rust_str *s)
219219
return (char const *)&s->data[0];
220220
}
221221

222+
extern "C" CDECL rust_vec*
223+
str_vec(rust_task *task, rust_str *s)
224+
{
225+
// FIXME: this should just upref s and return it, but we
226+
// accidentally made too much of the language and runtime know
227+
// and care about the difference between str and vec (trailing null);
228+
// eliminate these differences and then rewrite this back to just
229+
// the following:
230+
//
231+
// if (s->ref_count != CONST_REFCOUNT)
232+
// s->ref();
233+
// return s;
234+
235+
rust_str *v =
236+
vec_alloc_with_data(task,
237+
s->fill - 1,
238+
s->fill - 1,
239+
1,
240+
(s->fill - 1) ? (void*)s->data : NULL);
241+
if (!v) {
242+
task->fail(2);
243+
return NULL;
244+
}
245+
return v;
246+
}
247+
222248
extern "C" CDECL size_t
223249
str_byte_len(rust_task *task, rust_str *s)
224250
{

0 commit comments

Comments
 (0)