]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/extern/extern-call-scrub.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / extern / extern-call-scrub.rs
1 // run-pass
2 #![allow(unused_must_use)]
3 // This time we're testing repeatedly going up and down both stacks to
4 // make sure the stack pointers are maintained properly in both
5 // directions
6
7 // ignore-emscripten no threads support
8
9 #![feature(rustc_private)]
10
11 extern crate libc;
12 use std::thread;
13
14 mod rustrt {
15 extern crate libc;
16
17 #[link(name = "rust_test_helpers", kind = "static")]
18 extern {
19 pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
20 data: libc::uintptr_t)
21 -> libc::uintptr_t;
22 }
23 }
24
25 extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
26 if data == 1 {
27 data
28 } else {
29 count(data - 1) + count(data - 1)
30 }
31 }
32
33 fn count(n: libc::uintptr_t) -> libc::uintptr_t {
34 unsafe {
35 println!("n = {}", n);
36 rustrt::rust_dbg_call(cb, n)
37 }
38 }
39
40 pub fn main() {
41 // Make sure we're on a thread with small Rust stacks (main currently
42 // has a large stack)
43 thread::spawn(move|| {
44 let result = count(12);
45 println!("result = {}", result);
46 assert_eq!(result, 2048);
47 }).join();
48 }