Alex Crichton | e860619 | 2015-09-10 20:19:44 -0700 | [diff] [blame^] | 1 | #![allow(bad_style, unused_imports)] |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 2 | |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 3 | extern crate libc; |
| 4 | extern crate libc_test; |
| 5 | |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame] | 6 | use std::any::{Any, TypeId}; |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 7 | use std::mem; |
| 8 | |
Alex Crichton | a9adfbf | 2015-09-09 23:21:27 -0700 | [diff] [blame] | 9 | use libc::*; |
Alex Crichton | 2237882 | 2015-09-10 19:59:23 -0700 | [diff] [blame] | 10 | #[cfg(unix)] use libc::types::os::common::bsd43::*; |
| 11 | #[cfg(unix)] use libc::funcs::bsd44::*; |
| 12 | #[cfg(unix)] use libc::funcs::posix01::mman::*; |
| 13 | #[cfg(unix)] use libc::funcs::posix01::glob::*; |
| 14 | #[cfg(unix)] use libc::funcs::posix01::signal::*; |
| 15 | #[cfg(unix)] use libc::funcs::posix88::signal::*; |
Alex Crichton | e860619 | 2015-09-10 20:19:44 -0700 | [diff] [blame^] | 16 | #[cfg(target_os = "macos")] use libc::funcs::extra::*; |
Alex Crichton | a9adfbf | 2015-09-09 23:21:27 -0700 | [diff] [blame] | 17 | |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 18 | trait Pretty { |
| 19 | fn pretty(&self) -> String; |
| 20 | } |
| 21 | |
| 22 | impl<T> Pretty for *const T { |
| 23 | fn pretty(&self) -> String { format!("{:?}", self) } |
| 24 | } |
| 25 | impl<T> Pretty for *mut T { |
| 26 | fn pretty(&self) -> String { format!("{:?}", self) } |
| 27 | } |
| 28 | macro_rules! p { |
| 29 | ($($i:ident)*) => ($( |
| 30 | impl Pretty for $i { |
| 31 | fn pretty(&self) -> String { format!("{} ({:#x})", self, self) } |
| 32 | } |
| 33 | )*) |
| 34 | } |
| 35 | p! { i8 i16 i32 i64 u8 u16 u32 u64 usize isize } |
| 36 | |
| 37 | fn same<T: Eq + Pretty>(rust: T, c: T, attr: &str) { |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 38 | if rust != c { |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 39 | panic!("bad {}: rust: {} != c {}", attr, rust.pretty(), c.pretty()); |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame] | 43 | fn align<T: Any>() -> u64 { |
| 44 | // TODO: apparently these three types have less alignment in Rust on x86 |
| 45 | // than they do in C this difference should.. probably be reconciled. |
| 46 | // |
| 47 | // Perhaps #27195? |
| 48 | if cfg!(target_pointer_width = "32") { |
| 49 | if TypeId::of::<T>() == TypeId::of::<f64>() || |
| 50 | TypeId::of::<T>() == TypeId::of::<i64>() || |
| 51 | TypeId::of::<T>() == TypeId::of::<u64>() { |
| 52 | return 8 |
| 53 | } |
| 54 | } |
| 55 | mem::align_of::<T>() as u64 |
| 56 | } |
| 57 | |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 58 | macro_rules! offset_of { |
| 59 | ($ty:ident, $field:ident) => ( |
| 60 | (&((*(0 as *const $ty)).$field)) as *const _ as u64 |
| 61 | ) |
| 62 | } |
| 63 | |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 64 | #[cfg(test)] |
| 65 | include!(concat!(env!("OUT_DIR"), "/all.rs")); |