| 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 | #![allow (dead_code)] |
| 29 | |
| 30 | use core::num::NonZeroUsize; |
| 31 | |
| 32 | pub(crate) type int = i32; |
| 33 | pub(crate) type uint = u32; |
| 34 | pub(crate) type size_t = usize; |
| 35 | pub(crate) type NonZero_size_t = NonZeroUsize; |
| 36 | |
| 37 | #[cfg (all(test, any(unix, windows)))] |
| 38 | mod tests { |
| 39 | use crate::c; |
| 40 | |
| 41 | #[test ] |
| 42 | fn test_libc_compatible() { |
| 43 | { |
| 44 | let x: c::int = 1; |
| 45 | let _x: libc::c_int = x; |
| 46 | } |
| 47 | |
| 48 | { |
| 49 | let x: c::uint = 1; |
| 50 | let _x: libc::c_uint = x; |
| 51 | } |
| 52 | |
| 53 | { |
| 54 | let x: c::size_t = 1; |
| 55 | let _x: libc::size_t = x; |
| 56 | let _x: usize = x; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |