/src/test/auxiliary/extern-crosscrate-source.rs

https://gitlab.com/pranith/rust · Rust · 41 lines · 26 code · 6 blank · 9 comment · 3 complexity · 14453e54e47138150f430118f3ac211e MD5 · raw file

  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. #![crate_name="externcallback"]
  11. #![crate_type = "lib"]
  12. #![feature(libc)]
  13. extern crate libc;
  14. pub mod rustrt {
  15. extern crate libc;
  16. #[link(name = "rust_test_helpers")]
  17. extern {
  18. pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
  19. data: libc::uintptr_t)
  20. -> libc::uintptr_t;
  21. }
  22. }
  23. pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
  24. unsafe {
  25. println!("n = {}", n);
  26. rustrt::rust_dbg_call(cb, n)
  27. }
  28. }
  29. pub extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
  30. if data == 1 {
  31. data
  32. } else {
  33. fact(data - 1) * data
  34. }
  35. }