]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
b7449926 1// run-pass
0bf4aa26 2#![allow(unused_must_use)]
223e47cc
LB
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
7453a54e
SL
7// ignore-emscripten no threads support
8
0731742a 9#![feature(rustc_private)]
c34b1796 10
1a4d82fc 11extern crate libc;
c34b1796 12use std::thread;
970d7e83 13
223e47cc 14mod rustrt {
1a4d82fc 15 extern crate libc;
970d7e83 16
476ff2be 17 #[link(name = "rust_test_helpers", kind = "static")]
1a4d82fc
JJ
18 extern {
19 pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
20 data: libc::uintptr_t)
970d7e83 21 -> libc::uintptr_t;
223e47cc
LB
22 }
23}
24
25extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
1a4d82fc 26 if data == 1 {
223e47cc
LB
27 data
28 } else {
1a4d82fc 29 count(data - 1) + count(data - 1)
223e47cc
LB
30 }
31}
32
1a4d82fc 33fn count(n: libc::uintptr_t) -> libc::uintptr_t {
223e47cc 34 unsafe {
1a4d82fc 35 println!("n = {}", n);
223e47cc
LB
36 rustrt::rust_dbg_call(cb, n)
37 }
38}
39
40pub fn main() {
bd371182 41 // Make sure we're on a thread with small Rust stacks (main currently
223e47cc 42 // has a large stack)
9346a6ac 43 thread::spawn(move|| {
1a4d82fc
JJ
44 let result = count(12);
45 println!("result = {}", result);
46 assert_eq!(result, 2048);
9346a6ac 47 }).join();
223e47cc 48}