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 //! TODO(MSRV-1.64): Use `core::ffi::{c_int, c_uint}`, remove the libc 24 //! compatibility testing, and remove the libc dev-dependency. 25 26 // Keep in sync with the checks in base.h that verify these assumptions. 27 28 pub(crate) type int = i32; 29 pub(crate) type uint = u32; 30 pub(crate) type size_t = usize; 31 32 #[cfg(all(test, any(unix, windows)))] 33 mod tests { 34 use crate::c; 35 36 #[test] test_libc_compatible()37 fn test_libc_compatible() { 38 { 39 let x: c::int = 1; 40 let _x: libc::c_int = x; 41 } 42 43 { 44 let x: c::uint = 1; 45 let _x: libc::c_uint = x; 46 } 47 48 { 49 let x: c::size_t = 1; 50 let _x: libc::size_t = x; 51 let _x: usize = x; 52 } 53 } 54 } 55