Skip to content

Commit 372aa4d

Browse files
committed
Factor out make_istr utility function in runtime. Issue #855
1 parent 3690f38 commit 372aa4d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/rt/rust.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,9 @@ command_line_args : public kernel_owned<command_line_args>
6666
"command line arg interior");
6767
args_istr->fill = args_istr->alloc = sizeof(rust_vec*) * argc;
6868
for (int i = 0; i < argc; ++i) {
69-
size_t str_fill = strlen(argv[i]) + 1;
70-
size_t str_alloc = str_fill;
71-
rust_vec *str = (rust_vec *)
72-
kernel->malloc(vec_size<char>(str_fill),
73-
"command line arg");
74-
str->fill = str_fill;
75-
str->alloc = str_alloc;
76-
memcpy(&str->data, argv[i], str_fill);
69+
rust_vec *str = make_istr(kernel, argv[i],
70+
strlen(argv[i]),
71+
"command line arg");
7772
((rust_vec**)&args_istr->data)[i] = str;
7873
}
7974
}

src/rt/rust_util.h

+13
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) {
218218
}
219219
}
220220

221+
inline rust_vec *
222+
make_istr(rust_kernel* kernel, char* c, size_t strlen, const char* name) {
223+
size_t str_fill = strlen + 1;
224+
size_t str_alloc = str_fill;
225+
rust_vec *str = (rust_vec *)
226+
kernel->malloc(vec_size<char>(str_fill), name);
227+
str->fill = str_fill;
228+
str->alloc = str_alloc;
229+
memcpy(&str->data, c, strlen);
230+
str->data[strlen] = '\0';
231+
return str;
232+
}
233+
221234
//
222235
// Local Variables:
223236
// mode: C++

0 commit comments

Comments
 (0)