]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | // Copyright 2012 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // This time we're testing repeatedly going up and down both stacks to | |
12 | // make sure the stack pointers are maintained properly in both | |
13 | // directions | |
14 | ||
c34b1796 AL |
15 | #![feature(libc, std_misc)] |
16 | ||
1a4d82fc | 17 | extern crate libc; |
c34b1796 | 18 | use std::thread; |
970d7e83 | 19 | |
223e47cc | 20 | mod rustrt { |
1a4d82fc | 21 | extern crate libc; |
970d7e83 | 22 | |
1a4d82fc JJ |
23 | #[link(name = "rust_test_helpers")] |
24 | extern { | |
25 | pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t, | |
26 | data: libc::uintptr_t) | |
970d7e83 | 27 | -> libc::uintptr_t; |
223e47cc LB |
28 | } |
29 | } | |
30 | ||
31 | extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t { | |
1a4d82fc | 32 | if data == 1 { |
223e47cc LB |
33 | data |
34 | } else { | |
1a4d82fc | 35 | count(data - 1) + count(data - 1) |
223e47cc LB |
36 | } |
37 | } | |
38 | ||
1a4d82fc | 39 | fn count(n: libc::uintptr_t) -> libc::uintptr_t { |
223e47cc | 40 | unsafe { |
1a4d82fc | 41 | println!("n = {}", n); |
223e47cc LB |
42 | rustrt::rust_dbg_call(cb, n) |
43 | } | |
44 | } | |
45 | ||
46 | pub fn main() { | |
bd371182 | 47 | // Make sure we're on a thread with small Rust stacks (main currently |
223e47cc | 48 | // has a large stack) |
9346a6ac | 49 | thread::spawn(move|| { |
1a4d82fc JJ |
50 | let result = count(12); |
51 | println!("result = {}", result); | |
52 | assert_eq!(result, 2048); | |
9346a6ac | 53 | }).join(); |
223e47cc | 54 | } |