issue-2214.rs 1.3 KB
Newer Older
1
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
// ignore-wasm32-bare no libc to test ffi with
12

13 14
#![feature(libc)]

15 16
extern crate libc;

A
Alex Crichton 已提交
17
use std::mem;
18
use libc::{c_double, c_int};
19

20
fn to_c_int(v: &mut isize) -> &mut c_int {
21
    unsafe {
A
Alex Crichton 已提交
22
        mem::transmute_copy(&v)
23
    }
24 25
}

26
fn lgamma(n: c_double, value: &mut isize) -> c_double {
27 28 29
    unsafe {
        return m::lgamma(n, to_c_int(value));
    }
30 31
}

32
mod m {
33
    use libc::{c_double, c_int};
34

35
    #[link_name = "m"]
S
Steve Klabnik 已提交
36
    extern {
37 38 39 40
        #[cfg(unix)]
        #[link_name="lgamma_r"]
        pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
        #[cfg(windows)]
41
        #[link_name="lgamma"]
42 43
        pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
    }
44 45
}

46
pub fn main() {
47 48
  let mut y: isize = 5;
  let x: &mut isize = &mut y;
49
  assert_eq!(lgamma(1.0 as c_double, x), 0.0 as c_double);
50
}