blob: 298a3c9a9a7f83d237a18925d65dbf6e95687090 [file] [log] [blame]
Alex Crichton0df7c102015-09-10 16:35:37 -07001#![allow(bad_style)]
2
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07003extern crate libc;
4extern crate libc_test;
5
Alex Crichtonc8b895c2015-09-10 13:24:15 -07006use std::any::{Any, TypeId};
Alex Crichton16083062015-09-09 22:59:24 -07007use std::mem;
8
Alex Crichtona9adfbf2015-09-09 23:21:27 -07009use libc::*;
Alex Crichton22378822015-09-10 19:59:23 -070010#[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 Crichtona9adfbf2015-09-09 23:21:27 -070016
Alex Crichton0df7c102015-09-10 16:35:37 -070017trait Pretty {
18 fn pretty(&self) -> String;
19}
20
21impl<T> Pretty for *const T {
22 fn pretty(&self) -> String { format!("{:?}", self) }
23}
24impl<T> Pretty for *mut T {
25 fn pretty(&self) -> String { format!("{:?}", self) }
26}
27macro_rules! p {
28 ($($i:ident)*) => ($(
29 impl Pretty for $i {
30 fn pretty(&self) -> String { format!("{} ({:#x})", self, self) }
31 }
32 )*)
33}
34p! { i8 i16 i32 i64 u8 u16 u32 u64 usize isize }
35
36fn same<T: Eq + Pretty>(rust: T, c: T, attr: &str) {
Alex Crichton3e5155b2015-09-09 23:46:19 -070037 if rust != c {
Alex Crichton0df7c102015-09-10 16:35:37 -070038 panic!("bad {}: rust: {} != c {}", attr, rust.pretty(), c.pretty());
Alex Crichton3e5155b2015-09-09 23:46:19 -070039 }
40}
41
Alex Crichtonc8b895c2015-09-10 13:24:15 -070042fn align<T: Any>() -> u64 {
43 // TODO: apparently these three types have less alignment in Rust on x86
44 // than they do in C this difference should.. probably be reconciled.
45 //
46 // Perhaps #27195?
47 if cfg!(target_pointer_width = "32") {
48 if TypeId::of::<T>() == TypeId::of::<f64>() ||
49 TypeId::of::<T>() == TypeId::of::<i64>() ||
50 TypeId::of::<T>() == TypeId::of::<u64>() {
51 return 8
52 }
53 }
54 mem::align_of::<T>() as u64
55}
56
Alex Crichton3e5155b2015-09-09 23:46:19 -070057macro_rules! offset_of {
58 ($ty:ident, $field:ident) => (
59 (&((*(0 as *const $ty)).$field)) as *const _ as u64
60 )
61}
62
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070063#[cfg(test)]
64include!(concat!(env!("OUT_DIR"), "/all.rs"));