1 // Copyright 2016-2019 Brian Smith. 2 // 3 // Permission to use, copy, modify, and/or distribute this software for any 4 // purpose with or without fee is hereby granted, provided that the above 5 // copyright notice and this permission notice appear in all copies. 6 // 7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 10 // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 15 //! C types. 16 //! 17 //! Avoid using the `libc` crate to get C types since `libc` doesn't support 18 //! all the targets we need to support. It turns out that the few types we need 19 //! are all uniformly defined on the platforms we care about. This will 20 //! probably change if/when we support 16-bit platforms or platforms where 21 //! `usize` and `uintptr_t` are different sizes. 22 23 // Keep in sync with the checks in base.h that verify these assumptions. 24 25 pub(crate) type int = i32; 26 pub(crate) type uint = u32; 27 pub(crate) type size_t = usize; 28 29 #[cfg(all(test, any(unix, windows)))] 30 mod tests { 31 use crate::c; 32 33 #[test] test_libc_compatible()34 fn test_libc_compatible() { 35 { 36 let x: c::int = 1; 37 let _x: libc::c_int = x; 38 } 39 40 { 41 let x: c::uint = 1; 42 let _x: libc::c_uint = x; 43 } 44 45 { 46 let x: c::size_t = 1; 47 let _x: libc::size_t = x; 48 let _x: usize = x; 49 } 50 } 51 } 52