From 372aa4d2107ddaa5de98a0f71e66ffd9d0f59562 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 1 Sep 2011 13:40:11 -0700 Subject: [PATCH] Factor out make_istr utility function in runtime. Issue #855 --- src/rt/rust.cpp | 11 +++-------- src/rt/rust_util.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp index a7411b98cd0..c3b6526a4a3 100644 --- a/src/rt/rust.cpp +++ b/src/rt/rust.cpp @@ -66,14 +66,9 @@ command_line_args : public kernel_owned "command line arg interior"); args_istr->fill = args_istr->alloc = sizeof(rust_vec*) * argc; for (int i = 0; i < argc; ++i) { - size_t str_fill = strlen(argv[i]) + 1; - size_t str_alloc = str_fill; - rust_vec *str = (rust_vec *) - kernel->malloc(vec_size(str_fill), - "command line arg"); - str->fill = str_fill; - str->alloc = str_alloc; - memcpy(&str->data, argv[i], str_fill); + rust_vec *str = make_istr(kernel, argv[i], + strlen(argv[i]), + "command line arg"); ((rust_vec**)&args_istr->data)[i] = str; } } diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index 7118572393f..1137a63c0e1 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -218,6 +218,19 @@ inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) { } } +inline rust_vec * +make_istr(rust_kernel* kernel, char* c, size_t strlen, const char* name) { + size_t str_fill = strlen + 1; + size_t str_alloc = str_fill; + rust_vec *str = (rust_vec *) + kernel->malloc(vec_size(str_fill), name); + str->fill = str_fill; + str->alloc = str_alloc; + memcpy(&str->data, c, strlen); + str->data[strlen] = '\0'; + return str; +} + // // Local Variables: // mode: C++