blob: fe3bd246ce4b6b8b8f8795aa468d9d89528941da [file] [log] [blame]
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07001extern crate libc;
2extern crate libc_test;
3
Alex Crichtonc8b895c2015-09-10 13:24:15 -07004use std::any::{Any, TypeId};
Alex Crichton16083062015-09-09 22:59:24 -07005use std::mem;
6
Alex Crichtona9adfbf2015-09-09 23:21:27 -07007use libc::*;
8use libc::types::os::common::bsd43::*;
9
Alex Crichton3e5155b2015-09-09 23:46:19 -070010fn same(rust: u64, c: u64, attr: &str) {
11 if rust != c {
12 panic!("bad {}: rust: {} != c {}", attr, rust, c);
13 }
14}
15
Alex Crichtonc8b895c2015-09-10 13:24:15 -070016fn 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 Crichton3e5155b2015-09-09 23:46:19 -070031macro_rules! offset_of {
32 ($ty:ident, $field:ident) => (
33 (&((*(0 as *const $ty)).$field)) as *const _ as u64
34 )
35}
36
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070037#[cfg(test)]
38include!(concat!(env!("OUT_DIR"), "/all.rs"));