Skip to content

Commit f747cd9

Browse files
committed
---
yaml --- r: 4799 b: refs/heads/master c: 250cc45 h: refs/heads/master i: 4797: 3f10fb6 4795: a9931eb 4791: 860c51d 4783: 91840de 4767: 1c784cc 4735: e82535e v: v3
1 parent 84da18d commit f747cd9

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0a8bffceb3ba25b12926bbd42ed3d282f573c9a0
2+
refs/heads/master: 250cc45c3bf4fc3e623e72b8b36d66a4e0fb1dcf

trunk/src/rt/rust.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ command_line_args : public kernel_owned<command_line_args>
77
rust_task *task;
88
int argc;
99
char **argv;
10+
rust_str **strs;
1011

11-
// vec[str] passed to rust_task::start.
12-
rust_vec *args;
13-
rust_ivec *args_ivec;
12+
// [str] passed to rust_task::start.
13+
rust_ivec *args;
1414

1515
command_line_args(rust_task *task,
1616
int sys_argc,
1717
char **sys_argv)
1818
: kernel(task->kernel),
1919
task(task),
2020
argc(sys_argc),
21-
argv(sys_argv),
22-
args(NULL)
21+
argv(sys_argv)
2322
{
2423
#if defined(__WIN32__)
2524
LPCWSTR cmdline = GetCommandLineW();
@@ -40,10 +39,9 @@ command_line_args : public kernel_owned<command_line_args>
4039
LocalFree(wargv);
4140
#endif
4241
size_t vec_fill = sizeof(rust_str *) * argc;
43-
size_t vec_alloc = next_power_of_two(sizeof(rust_vec) + vec_fill);
42+
size_t vec_alloc = next_power_of_two(vec_fill);
4443
void *mem = kernel->malloc(vec_alloc, "command line");
45-
args = new (mem) rust_vec(vec_alloc, 0, NULL);
46-
rust_str **strs = (rust_str**) &args->data[0];
44+
strs = (rust_str**) mem;
4745
for (int i = 0; i < argc; ++i) {
4846
size_t str_fill = strlen(argv[i]) + 1;
4947
size_t str_alloc = next_power_of_two(sizeof(rust_str) + str_fill);
@@ -52,38 +50,29 @@ command_line_args : public kernel_owned<command_line_args>
5250
(uint8_t const *)argv[i]);
5351
strs[i]->ref_count++;
5452
}
55-
args->fill = vec_fill;
56-
// If the caller has a declared args array, they may drop; but
57-
// we don't know if they have such an array. So we pin the args
58-
// array here to ensure it survives to program-shutdown.
59-
args->ref();
6053

6154
size_t ivec_interior_sz =
6255
sizeof(size_t) * 2 + sizeof(rust_str *) * 4;
63-
args_ivec = (rust_ivec *)
56+
args = (rust_ivec *)
6457
kernel->malloc(ivec_interior_sz,
6558
"command line arg interior");
66-
args_ivec->fill = 0;
59+
args->fill = 0;
6760
size_t ivec_exterior_sz = sizeof(rust_str *) * argc;
68-
args_ivec->alloc = ivec_exterior_sz;
69-
// NB: This is freed by some ivec machinery, probably the drop
70-
// glue in main, so we don't free it ourselves
71-
args_ivec->payload.ptr = (rust_ivec_heap *)
61+
args->alloc = ivec_exterior_sz;
62+
// NB: _rust_main owns the ivec payload and will be responsible for
63+
// freeing it
64+
args->payload.ptr = (rust_ivec_heap *)
7265
kernel->malloc(ivec_exterior_sz + sizeof(size_t),
7366
"command line arg exterior");
74-
args_ivec->payload.ptr->fill = ivec_exterior_sz;
75-
memcpy(&args_ivec->payload.ptr->data, strs, ivec_exterior_sz);
67+
args->payload.ptr->fill = ivec_exterior_sz;
68+
memcpy(&args->payload.ptr->data, strs, ivec_exterior_sz);
7669
}
7770

7871
~command_line_args() {
79-
kernel->free(args_ivec);
80-
if (args) {
81-
// Drop the args we've had pinned here.
82-
rust_str **strs = (rust_str**) &args->data[0];
83-
for (int i = 0; i < argc; ++i)
84-
kernel->free(strs[i]);
85-
kernel->free(args);
86-
}
72+
kernel->free(args);
73+
for (int i = 0; i < argc; ++i)
74+
kernel->free(strs[i]);
75+
kernel->free(strs);
8776

8877
#ifdef __WIN32__
8978
for (int i = 0; i < argc; ++i) {
@@ -127,7 +116,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv,
127116
DLOG(sched, dom, "startup: arg[%d] = '%s'", i, args->argv[i]);
128117
}
129118

130-
root_task->start(main_fn, (uintptr_t)args->args_ivec);
119+
root_task->start(main_fn, (uintptr_t)args->args);
131120
root_task->deref();
132121
root_task = NULL;
133122

0 commit comments

Comments
 (0)