Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 1 | extern crate libc; |
| 2 | extern crate libc_test; |
| 3 | |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame^] | 4 | use std::any::{Any, TypeId}; |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 5 | use std::mem; |
| 6 | |
Alex Crichton | a9adfbf | 2015-09-09 23:21:27 -0700 | [diff] [blame] | 7 | use libc::*; |
| 8 | use libc::types::os::common::bsd43::*; |
| 9 | |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 10 | fn same(rust: u64, c: u64, attr: &str) { |
| 11 | if rust != c { |
| 12 | panic!("bad {}: rust: {} != c {}", attr, rust, c); |
| 13 | } |
| 14 | } |
| 15 | |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame^] | 16 | fn align<T: Any>() -> u64 { |
| 17 | // TODO: apparently these three types have less alignment in Rust on x86 |
| 18 | // than they do in C this difference should.. probably be reconciled. |
| 19 | // |
| 20 | // Perhaps #27195? |
| 21 | if cfg!(target_pointer_width = "32") { |
| 22 | if TypeId::of::<T>() == TypeId::of::<f64>() || |
| 23 | TypeId::of::<T>() == TypeId::of::<i64>() || |
| 24 | TypeId::of::<T>() == TypeId::of::<u64>() { |
| 25 | return 8 |
| 26 | } |
| 27 | } |
| 28 | mem::align_of::<T>() as u64 |
| 29 | } |
| 30 | |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 31 | macro_rules! offset_of { |
| 32 | ($ty:ident, $field:ident) => ( |
| 33 | (&((*(0 as *const $ty)).$field)) as *const _ as u64 |
| 34 | ) |
| 35 | } |
| 36 | |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 37 | #[cfg(test)] |
| 38 | include!(concat!(env!("OUT_DIR"), "/all.rs")); |