1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Raw OS-specific types for the current platform/architecture
13 #![stable(feature = "raw_os", since = "1.1.0")]
17 #[cfg(any(target_os = "android",
18 target_os = "emscripten",
19 all(target_os = "linux", any(target_arch = "aarch64",
21 target_arch = "powerpc",
22 target_arch = "powerpc64",
23 target_arch = "s390x")),
24 all(target_os = "fuchsia", target_arch = "aarch64")))]
25 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
26 #[cfg(not(any(target_os = "android",
27 target_os = "emscripten",
28 all(target_os = "linux", any(target_arch = "aarch64",
30 target_arch = "powerpc",
31 target_arch = "powerpc64",
32 target_arch = "s390x")),
33 all(target_os = "fuchsia", target_arch = "aarch64"))))]
34 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
35 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
36 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
37 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
38 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
39 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
40 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
41 #[cfg(any(target_pointer_width = "32", windows))]
42 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
43 #[cfg(any(target_pointer_width = "32", windows))]
44 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
45 #[cfg(all(target_pointer_width = "64", not(windows)))]
46 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
47 #[cfg(all(target_pointer_width = "64", not(windows)))]
48 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
49 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
50 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
51 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
52 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
54 /// Type used to construct void pointers for use with C.
56 /// This type is only useful as a pointer target. Do not use it as a
57 /// return type for FFI functions which have the `void` return type in
58 /// C. Use the unit type `()` or omit the return type instead.
59 // NB: For LLVM to recognize the void pointer type and by extension
60 // functions like malloc(), we need to have it represented as i8* in
61 // LLVM bitcode. The enum used here ensures this and prevents misuse
62 // of the "raw" type by only having private variants.. We need two
63 // variants, because the compiler complains about the repr attribute
66 #[stable(feature = "raw_os", since = "1.1.0")]
68 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
70 #[doc(hidden)] __variant1,
71 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
73 #[doc(hidden)] __variant2,
76 #[stable(feature = "std_debug", since = "1.15.0")]
77 impl fmt::Debug for c_void {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
84 #[allow(unused_imports)]
92 assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
93 "{} is wrong", stringify!($t));
100 ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
101 c_longlong c_ulonglong c_float c_double);