blob: d4c7820d698dc17f39e04d37fc62536512bf4ccc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
extern crate stacker;
const RED_ZONE: usize = 100 * 1024; // 100k
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>(f: F) -> R {
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
}
#[inline(never)]
fn recurse(n: usize) {
let x = [42u8; 50000];
if n != 0 {
ensure_sufficient_stack(|| recurse(n - 1));
}
drop(x);
}
#[test]
fn foo() {
let limit = if cfg!(target_arch = "wasm32") {
2000
} else {
10000
};
recurse(limit);
}
|