]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/extern-call-indirect.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / extern-call-indirect.rs
CommitLineData
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
c34b1796
AL
11#![feature(libc)]
12
1a4d82fc 13extern crate libc;
970d7e83 14
223e47cc 15mod rustrt {
1a4d82fc 16 extern crate libc;
970d7e83 17
476ff2be 18 #[link(name = "rust_test_helpers", kind = "static")]
1a4d82fc
JJ
19 extern {
20 pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
21 data: libc::uintptr_t)
970d7e83 22 -> libc::uintptr_t;
223e47cc
LB
23 }
24}
25
26extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
1a4d82fc 27 if data == 1 {
223e47cc
LB
28 data
29 } else {
1a4d82fc 30 fact(data - 1) * data
223e47cc
LB
31 }
32}
33
1a4d82fc 34fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
223e47cc 35 unsafe {
1a4d82fc 36 println!("n = {}", n);
223e47cc
LB
37 rustrt::rust_dbg_call(cb, n)
38 }
39}
40
41pub fn main() {
1a4d82fc
JJ
42 let result = fact(10);
43 println!("result = {}", result);
44 assert_eq!(result, 3628800);
223e47cc 45}