From 1b67d211b40b268180c3642fc8f6f09cbf0895a6 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 2 Sep 2011 17:00:40 -0700 Subject: [PATCH] Add a rust_str typedef to the runtime. Issue #855 --- src/rt/rust.cpp | 4 ++-- src/rt/rust_builtin.cpp | 16 ++++++++-------- src/rt/rust_util.h | 6 ++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp index 25fb9331314..fbf6ff7a08b 100644 --- a/src/rt/rust.cpp +++ b/src/rt/rust.cpp @@ -43,10 +43,10 @@ command_line_args : public kernel_owned "command line arg interior"); args->fill = args->alloc = sizeof(rust_vec*) * argc; for (int i = 0; i < argc; ++i) { - rust_vec *str = make_str(kernel, argv[i], + rust_str *str = make_str(kernel, argv[i], strlen(argv[i]), "command line arg"); - ((rust_vec**)&args->data)[i] = str; + ((rust_str**)&args->data)[i] = str; } } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index a09e7ac1849..f8fc85a0fe1 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -7,7 +7,7 @@ /* Native builtins. */ -extern "C" CDECL rust_vec* +extern "C" CDECL rust_str* last_os_error(rust_task *task) { LOG(task, task, "last_os_error()"); @@ -40,15 +40,15 @@ last_os_error(rust_task *task) { } #endif - rust_vec * st = make_str(task->kernel, buf, strlen(buf), - "last_os_error"); + rust_str * st = make_str(task->kernel, buf, strlen(buf), + "last_os_error"); #ifdef __WIN32__ LocalFree((HLOCAL)buf); #endif return st; } -extern "C" CDECL rust_vec * +extern "C" CDECL rust_str * rust_getcwd(rust_task *task) { LOG(task, task, "rust_getcwd()"); @@ -323,15 +323,15 @@ debug_ptrcast(rust_task *task, extern "C" CDECL rust_vec* rust_list_files(rust_task *task, rust_vec **path) { - array_list strings; + array_list strings; #if defined(__WIN32__) WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile((char*)(*path)->data, &FindFileData); if (hFind != INVALID_HANDLE_VALUE) { do { - rust_vec *str = make_str(task->kernel, FindFileData.cFileName, - strlen(FindFileData.cFileName), - "list_files_str"); + rust_str *str = make_str(task->kernel, FindFileData.cFileName, + strlen(FindFileData.cFileName), + "list_files_str"); strings.push(str); } while (FindNextFile(hFind, &FindFileData)); FindClose(hFind); diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index 25886aef74b..50545b21310 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -188,11 +188,13 @@ inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) { } } -inline rust_vec * +typedef rust_vec rust_str; + +inline rust_str * make_str(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 *) + rust_str *str = (rust_str *) kernel->malloc(vec_size(str_fill), name); str->fill = str_fill; str->alloc = str_alloc;