about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-04-27 13:06:19 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-04-27 13:06:19 -0700
commit4c7886de8008b07e892ea741be08291dae38f7bd (patch)
tree32623b15f45c4f81d2ff167e9caddf1d5b2740cd /src/rt/rust_builtin.cpp
parentfef8314c2e018d2e35c8bd91d3181de038e44de2 (diff)
downloadrust-4c7886de8008b07e892ea741be08291dae38f7bd.tar.gz
rust-4c7886de8008b07e892ea741be08291dae38f7bd.zip
Fix _str.bytes to trivial version.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 30e2eb3ddeb..5566835d3cd 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -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)
 {