Skip to content

Commit e697a52

Browse files
author
Eric Holk
committed
Adding a function to stdlib to set the min stack size, for programs
that absolutely will not succeed with a large default stack. This should be removed once we have stack grown working. Also updated word-count to succeed under the new test framework.
1 parent 117e251 commit e697a52

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

src/lib/task.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ native "rust" mod rustrt {
88
fn clone_chan(c: *rust_chan) -> *rust_chan;
99

1010
type rust_chan;
11+
12+
fn set_min_stack(stack_size: uint);
1113
}
1214

1315
/**
@@ -40,6 +42,10 @@ fn send[T](c: chan[T], v: &T) { c <| v; }
4042

4143
fn recv[T](p: port[T]) -> T { let v; p |> v; v }
4244

45+
fn set_min_stack(uint stack_size) {
46+
rustrt::set_min_stack(stack_size);
47+
}
48+
4349
// Local Variables:
4450
// mode: rust;
4551
// fill-column: 78;

src/rt/rust_builtin.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ clone_chan(rust_task *task, rust_chan *chan) {
856856
return chan->clone(task);
857857
}
858858

859+
// defined in rust_task.cpp
860+
extern size_t g_min_stack_size;
861+
extern "C" CDECL void
862+
set_min_stack(rust_task *task, uintptr_t stack_size) {
863+
g_min_stack_size = stack_size;
864+
}
865+
859866
//
860867
// Local Variables:
861868
// mode: C++

src/rt/rust_task.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
// FIXME (issue #151): This should be 0x300; the change here is for
1616
// practicality's sake until stack growth is working.
17+
size_t g_min_stack_size = 0x300000;
1718

1819
static size_t get_min_stk_size() {
1920
char *stack_size = getenv("RUST_MIN_STACK");
2021
if(stack_size) {
2122
return strtol(stack_size, NULL, 0);
2223
}
2324
else {
24-
return 0x300000;
25+
return g_min_stack_size;
2526
}
2627
}
2728

src/rt/rustrt.def.in

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rust_ptr_eq
3737
rust_run_program
3838
rust_start
3939
rust_getcwd
40+
set_min_stack
4041
size_of
4142
squareroot
4243
str_alloc

src/test/bench/task-perf-word-count.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// xfail-stage1
2-
// xfail-stage2
3-
// xfail-stage3
41
/**
52
A parallel word-frequency counting program.
63
@@ -233,10 +230,19 @@ fn main(argv: vec[str]) {
233230
let out = io::stdout();
234231

235232
out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
236-
fail;
233+
234+
// TODO: run something just to make sure the code hasn't
235+
// broken yet. This is the unit test mode of this program.
236+
237+
ret;
237238
}
238239

240+
// We can get by with 8k stacks, and we'll probably exhaust our
241+
// address space otherwise.
242+
task::set_min_stack(8192u);
243+
239244
let start = time::precise_time_ns();
245+
240246
map_reduce::map_reduce(vec::slice(argv, 1u, vec::len(argv)));
241247
let stop = time::precise_time_ns();
242248

@@ -342,4 +348,4 @@ fn is_alpha_upper(c: char) -> bool {
342348

343349
fn is_alpha(c: char) -> bool { is_alpha_upper(c) || is_alpha_lower(c) }
344350

345-
fn is_word_char(c: char) -> bool { is_alpha(c) || is_digit(c) || c == '_' }
351+
fn is_word_char(c: char) -> bool { is_alpha(c) || is_digit(c) || c == '_' }

0 commit comments

Comments
 (0)