From d0c509ad1b8a13102e7cb6ba2bf1d2dc75e5177e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Aug 2011 18:47:29 -0700 Subject: [PATCH] Remove a bunch of string builtins. Issue #855 --- src/lib/str.rs | 6 -- src/rt/rust_builtin.cpp | 82 ------------------------ src/rt/rustrt.def.in | 6 -- src/test/run-pass/binops.rs | 10 ++- src/test/run-pass/conditional-compile.rs | 4 +- 5 files changed, 6 insertions(+), 102 deletions(-) diff --git a/src/lib/str.rs b/src/lib/str.rs index 14399bb80d0..cac2de8ee3b 100644 --- a/src/lib/str.rs +++ b/src/lib/str.rs @@ -3,13 +3,7 @@ export unsafe_from_bytes; native "rust" mod rustrt { type sbuf; fn str_buf(s: str) -> sbuf; - fn str_byte_len(s: str) -> uint; - fn str_alloc(n_bytes: uint) -> str; fn str_from_vec(b: &[mutable? u8]) -> str; - fn str_from_cstr(cstr: sbuf) -> str; - fn str_from_buf(buf: sbuf, len: uint) -> str; - fn str_push_byte(s: str, byte: uint) -> str; - fn str_slice(s: str, begin: uint, end: uint) -> str; fn refcount(s: str) -> uint; } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index f3f67fef52d..1b57d0adb83 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -140,71 +140,12 @@ vec_alloc_with_data(rust_task *task, return new (mem) rust_evec(alloc, fill * elt_size, (uint8_t*)d); } -extern "C" CDECL rust_str* -str_alloc(rust_task *task, size_t n_bytes) -{ - rust_str *st = vec_alloc_with_data(task, - n_bytes + 1, // +1 to fit at least "" - 1, 1, - (void*)""); - if (!st) { - task->fail(); - return NULL; - } - return st; -} - -extern "C" CDECL rust_str* -str_push_byte(rust_task* task, rust_str* v, size_t byte) -{ - size_t fill = v->fill; - size_t alloc = next_power_of_two(sizeof(rust_evec) + fill + 1); - if (v->ref_count > 1 || v->alloc < alloc) { - v = vec_alloc_with_data(task, fill + 1, fill, 1, (void*)&v->data[0]); - if (!v) { - task->fail(); - return NULL; - } - } - else if (v->ref_count != CONST_REFCOUNT) { - v->ref(); - } - v->data[fill-1] = (char)byte; - v->data[fill] = '\0'; - v->fill++; - return v; -} - -extern "C" CDECL rust_str* -str_slice(rust_task* task, rust_str* v, size_t begin, size_t end) -{ - size_t len = end - begin; - rust_str *st = - vec_alloc_with_data(task, - len + 1, // +1 to fit at least '\0' - len, - 1, - len ? v->data + begin : NULL); - if (!st) { - task->fail(); - return NULL; - } - st->data[st->fill++] = '\0'; - return st; -} - extern "C" CDECL char const * str_buf(rust_task *task, rust_str *s) { return (char const *)&s->data[0]; } -extern "C" CDECL size_t -str_byte_len(rust_task *task, rust_str *s) -{ - return s->fill - 1; // -1 for the '\0' terminator. -} - extern "C" CDECL rust_str * str_from_vec(rust_task *task, rust_vec **vp) { @@ -252,29 +193,6 @@ rust_istr_push(rust_task* task, rust_vec** sp, uint8_t byte) { (*sp)->fill = fill + 1; } -extern "C" CDECL rust_str * -str_from_cstr(rust_task *task, char *sbuf) -{ - size_t len = strlen(sbuf) + 1; - rust_str *st = vec_alloc_with_data(task, len, len, 1, sbuf); - if (!st) { - task->fail(); - return NULL; - } - return st; -} - -extern "C" CDECL rust_str * -str_from_buf(rust_task *task, char *buf, unsigned int len) { - rust_str *st = vec_alloc_with_data(task, len + 1, len, 1, buf); - if (!st) { - task->fail(); - return NULL; - } - st->data[st->fill++] = '\0'; - return st; -} - extern "C" CDECL void * rand_new(rust_task *task) { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 806f63905da..1b623da6c2b 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -62,16 +62,10 @@ sched_threads size_of squareroot start_task -str_alloc str_buf -str_byte_len -str_from_buf -str_from_cstr str_from_vec vec_reserve_shared vec_from_buf_shared -str_push_byte -str_slice task_sleep task_yield task_join diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs index d64c2dd1fab..eee15a41394 100644 --- a/src/test/run-pass/binops.rs +++ b/src/test/run-pass/binops.rs @@ -118,16 +118,14 @@ fn test_fn() { } native "rust" mod native_mod = "" { - fn str_byte_len(s: str) -> uint; - // This isn't actually the signature of str_alloc, but since - // we're not calling it that shouldn't matter - fn str_alloc(s: str) -> uint; + fn do_gc(); + fn unsupervise(); } // FIXME: comparison of native fns fn test_native_fn() { - assert (native_mod::str_byte_len == native_mod::str_byte_len); - assert (native_mod::str_byte_len != native_mod::str_alloc); + assert (native_mod::do_gc == native_mod::do_gc); + assert (native_mod::do_gc != native_mod::unsupervise); } fn test_obj() { diff --git a/src/test/run-pass/conditional-compile.rs b/src/test/run-pass/conditional-compile.rs index e4d0526fbc1..5ee6d2eaeee 100644 --- a/src/test/run-pass/conditional-compile.rs +++ b/src/test/run-pass/conditional-compile.rs @@ -81,7 +81,7 @@ fn test_in_fn_ctxt() { mod test_native_items { native "rust" mod rustrt { #[cfg(bogus)] - fn str_byte_len(s: str) -> uint; - fn str_byte_len(s: str) -> uint; + fn vec_from_buf_shared(ptr: *T, count: uint) -> [T]; + fn vec_from_buf_shared(ptr: *T, count: uint) -> [T]; } }