aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/os/raw
diff options
context:
space:
mode:
authorlinouxis9 <[email protected]>2018-05-07 15:31:54 +0200
committerlinouxis9 <[email protected]>2018-05-07 15:35:20 +0200
commit4901431b02227416b08e5fbc9a7ac3f5ac2f44a7 (patch)
tree7fb75cf805b8f0e9b7f169af37c9d2aa0c4aded6 /ctr-std/src/os/raw
parentMerge pull request #66 from FenrirWolf/swkbd (diff)
downloadctru-rs-4901431b02227416b08e5fbc9a7ac3f5ac2f44a7.tar.xz
ctru-rs-4901431b02227416b08e5fbc9a7ac3f5ac2f44a7.zip
Update for latest nightly 2018-05-06
Diffstat (limited to 'ctr-std/src/os/raw')
-rw-r--r--ctr-std/src/os/raw/char.md11
-rw-r--r--ctr-std/src/os/raw/double.md7
-rw-r--r--ctr-std/src/os/raw/float.md6
-rw-r--r--ctr-std/src/os/raw/int.md7
-rw-r--r--ctr-std/src/os/raw/long.md7
-rw-r--r--ctr-std/src/os/raw/longlong.md7
-rw-r--r--ctr-std/src/os/raw/mod.rs135
-rw-r--r--ctr-std/src/os/raw/schar.md6
-rw-r--r--ctr-std/src/os/raw/short.md6
-rw-r--r--ctr-std/src/os/raw/uchar.md6
-rw-r--r--ctr-std/src/os/raw/uint.md7
-rw-r--r--ctr-std/src/os/raw/ulong.md7
-rw-r--r--ctr-std/src/os/raw/ulonglong.md7
-rw-r--r--ctr-std/src/os/raw/ushort.md6
14 files changed, 225 insertions, 0 deletions
diff --git a/ctr-std/src/os/raw/char.md b/ctr-std/src/os/raw/char.md
new file mode 100644
index 0000000..9a55767
--- /dev/null
+++ b/ctr-std/src/os/raw/char.md
@@ -0,0 +1,11 @@
+Equivalent to C's `char` type.
+
+[C's `char` type] is completely unlike [Rust's `char` type]; while Rust's type represents a unicode scalar value, C's `char` type is just an ordinary integer. This type will always be either [`i8`] or [`u8`], as the type is defined as being one byte long.
+
+C chars are most commonly used to make C strings. Unlike Rust, where the length of a string is included alongside the string, C strings mark the end of a string with the character `'\0'`. See [`CStr`] for more information.
+
+[C's `char` type]: https://en.wikipedia.org/wiki/C_data_types#Basic_types
+[Rust's `char` type]: ../../primitive.char.html
+[`CStr`]: ../../ffi/struct.CStr.html
+[`i8`]: ../../primitive.i8.html
+[`u8`]: ../../primitive.u8.html
diff --git a/ctr-std/src/os/raw/double.md b/ctr-std/src/os/raw/double.md
new file mode 100644
index 0000000..6818dad
--- /dev/null
+++ b/ctr-std/src/os/raw/double.md
@@ -0,0 +1,7 @@
+Equivalent to C's `double` type.
+
+This type will almost always be [`f64`], which is guaranteed to be an [IEEE-754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard.
+
+[IEEE-754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754
+[`float`]: type.c_float.html
+[`f64`]: ../../primitive.f64.html
diff --git a/ctr-std/src/os/raw/float.md b/ctr-std/src/os/raw/float.md
new file mode 100644
index 0000000..57d1071
--- /dev/null
+++ b/ctr-std/src/os/raw/float.md
@@ -0,0 +1,6 @@
+Equivalent to C's `float` type.
+
+This type will almost always be [`f32`], which is guaranteed to be an [IEEE-754 single-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all.
+
+[IEEE-754 single-precision float]: https://en.wikipedia.org/wiki/IEEE_754
+[`f32`]: ../../primitive.f32.html
diff --git a/ctr-std/src/os/raw/int.md b/ctr-std/src/os/raw/int.md
new file mode 100644
index 0000000..a0d25fd
--- /dev/null
+++ b/ctr-std/src/os/raw/int.md
@@ -0,0 +1,7 @@
+Equivalent to C's `signed int` (`int`) type.
+
+This type will almost always be [`i32`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer that is at least the size of a [`short`]; some systems define it as an [`i16`], for example.
+
+[`short`]: type.c_short.html
+[`i32`]: ../../primitive.i32.html
+[`i16`]: ../../primitive.i16.html
diff --git a/ctr-std/src/os/raw/long.md b/ctr-std/src/os/raw/long.md
new file mode 100644
index 0000000..c620b40
--- /dev/null
+++ b/ctr-std/src/os/raw/long.md
@@ -0,0 +1,7 @@
+Equivalent to C's `signed long` (`long`) type.
+
+This type will always be [`i32`] or [`i64`]. Most notably, many Linux-based systems assume an `i64`, but Windows assumes `i32`. The C standard technically only requires that this type be a signed integer that is at least 32 bits and at least the size of an [`int`], although in practice, no system would have a `long` that is neither an `i32` nor `i64`.
+
+[`int`]: type.c_int.html
+[`i32`]: ../../primitive.i32.html
+[`i64`]: ../../primitive.i64.html
diff --git a/ctr-std/src/os/raw/longlong.md b/ctr-std/src/os/raw/longlong.md
new file mode 100644
index 0000000..ab3d643
--- /dev/null
+++ b/ctr-std/src/os/raw/longlong.md
@@ -0,0 +1,7 @@
+Equivalent to C's `signed long long` (`long long`) type.
+
+This type will almost always be [`i64`], but may differ on some systems. The C standard technically only requires that this type be a signed integer that is at least 64 bits and at least the size of a [`long`], although in practice, no system would have a `long long` that is not an `i64`, as most systems do not have a standardised [`i128`] type.
+
+[`long`]: type.c_int.html
+[`i64`]: ../../primitive.i64.html
+[`i128`]: ../../primitive.i128.html
diff --git a/ctr-std/src/os/raw/mod.rs b/ctr-std/src/os/raw/mod.rs
new file mode 100644
index 0000000..d5eeb52
--- /dev/null
+++ b/ctr-std/src/os/raw/mod.rs
@@ -0,0 +1,135 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Platform-specific types, as defined by C.
+//!
+//! Code that interacts via FFI will almost certainly be using the
+//! base types provided by C, which aren't nearly as nicely defined
+//! as Rust's primitive types. This module provides types which will
+//! match those defined by C, so that code that interacts with C will
+//! refer to the correct types.
+
+#![stable(feature = "raw_os", since = "1.1.0")]
+
+use fmt;
+
+#[doc(include = "os/raw/char.md")]
+#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
+ target_arch = "arm",
+ target_arch = "powerpc",
+ target_arch = "powerpc64",
+ target_arch = "s390x")),
+ all(target_os = "android", any(target_arch = "aarch64",
+ target_arch = "arm")),
+ all(target_os = "l4re", target_arch = "x86_64"),
+ all(target_os = "openbsd", target_arch = "aarch64"),
+ all(target_os = "fuchsia", target_arch = "aarch64")))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
+#[doc(include = "os/raw/char.md")]
+#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
+ target_arch = "arm",
+ target_arch = "powerpc",
+ target_arch = "powerpc64",
+ target_arch = "s390x")),
+ all(target_os = "android", any(target_arch = "aarch64",
+ target_arch = "arm")),
+ all(target_os = "l4re", target_arch = "x86_64"),
+ all(target_os = "openbsd", target_arch = "aarch64"),
+ all(target_os = "fuchsia", target_arch = "aarch64"))))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
+#[doc(include = "os/raw/schar.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
+#[doc(include = "os/raw/uchar.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
+#[doc(include = "os/raw/short.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
+#[doc(include = "os/raw/ushort.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
+#[doc(include = "os/raw/int.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
+#[doc(include = "os/raw/uint.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
+#[doc(include = "os/raw/long.md")]
+#[cfg(any(target_pointer_width = "32", windows))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
+#[doc(include = "os/raw/ulong.md")]
+#[cfg(any(target_pointer_width = "32", windows))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
+#[doc(include = "os/raw/long.md")]
+#[cfg(all(target_pointer_width = "64", not(windows)))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
+#[doc(include = "os/raw/ulong.md")]
+#[cfg(all(target_pointer_width = "64", not(windows)))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
+#[doc(include = "os/raw/longlong.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
+#[doc(include = "os/raw/ulonglong.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
+#[doc(include = "os/raw/float.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
+#[doc(include = "os/raw/double.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
+
+/// Equivalent to C's `void` type when used as a [pointer].
+///
+/// In essence, `*const c_void` is equivalent to C's `const void*`
+/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
+/// *not* the same as C's `void` return type, which is Rust's `()` type.
+///
+/// Ideally, this type would be equivalent to [`!`], but currently it may
+/// be more ideal to use `c_void` for FFI purposes.
+///
+/// [`!`]: ../../primitive.never.html
+/// [pointer]: ../../primitive.pointer.html
+// NB: For LLVM to recognize the void pointer type and by extension
+// functions like malloc(), we need to have it represented as i8* in
+// LLVM bitcode. The enum used here ensures this and prevents misuse
+// of the "raw" type by only having private variants.. We need two
+// variants, because the compiler complains about the repr attribute
+// otherwise.
+#[repr(u8)]
+#[stable(feature = "raw_os", since = "1.1.0")]
+pub enum c_void {
+ #[unstable(feature = "c_void_variant", reason = "should not have to exist",
+ issue = "0")]
+ #[doc(hidden)] __variant1,
+ #[unstable(feature = "c_void_variant", reason = "should not have to exist",
+ issue = "0")]
+ #[doc(hidden)] __variant2,
+}
+
+#[stable(feature = "std_debug", since = "1.16.0")]
+impl fmt::Debug for c_void {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.pad("c_void")
+ }
+}
+
+#[cfg(test)]
+#[allow(unused_imports)]
+mod tests {
+ use any::TypeId;
+ use libc;
+ use mem;
+
+ macro_rules! ok {
+ ($($t:ident)*) => {$(
+ assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
+ "{} is wrong", stringify!($t));
+ )*}
+ }
+
+ #[test]
+ fn same() {
+ use os::raw;
+ ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong
+ c_longlong c_ulonglong c_float c_double);
+ }
+}
diff --git a/ctr-std/src/os/raw/schar.md b/ctr-std/src/os/raw/schar.md
new file mode 100644
index 0000000..6aa8b12
--- /dev/null
+++ b/ctr-std/src/os/raw/schar.md
@@ -0,0 +1,6 @@
+Equivalent to C's `signed char` type.
+
+This type will always be [`i8`], but is included for completeness. It is defined as being a signed integer the same size as a C [`char`].
+
+[`char`]: type.c_char.html
+[`i8`]: ../../primitive.i8.html
diff --git a/ctr-std/src/os/raw/short.md b/ctr-std/src/os/raw/short.md
new file mode 100644
index 0000000..be92c6c
--- /dev/null
+++ b/ctr-std/src/os/raw/short.md
@@ -0,0 +1,6 @@
+Equivalent to C's `signed short` (`short`) type.
+
+This type will almost always be [`i16`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer with at least 16 bits; some systems may define it as `i32`, for example.
+
+[`char`]: type.c_char.html
+[`i16`]: ../../primitive.i16.html
diff --git a/ctr-std/src/os/raw/uchar.md b/ctr-std/src/os/raw/uchar.md
new file mode 100644
index 0000000..b6ca711
--- /dev/null
+++ b/ctr-std/src/os/raw/uchar.md
@@ -0,0 +1,6 @@
+Equivalent to C's `unsigned char` type.
+
+This type will always be [`u8`], but is included for completeness. It is defined as being an unsigned integer the same size as a C [`char`].
+
+[`char`]: type.c_char.html
+[`u8`]: ../../primitive.u8.html
diff --git a/ctr-std/src/os/raw/uint.md b/ctr-std/src/os/raw/uint.md
new file mode 100644
index 0000000..6f7013a
--- /dev/null
+++ b/ctr-std/src/os/raw/uint.md
@@ -0,0 +1,7 @@
+Equivalent to C's `unsigned int` type.
+
+This type will almost always be [`u32`], but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as an [`int`]; some systems define it as a [`u16`], for example.
+
+[`int`]: type.c_int.html
+[`u32`]: ../../primitive.u32.html
+[`u16`]: ../../primitive.u16.html
diff --git a/ctr-std/src/os/raw/ulong.md b/ctr-std/src/os/raw/ulong.md
new file mode 100644
index 0000000..c350395
--- /dev/null
+++ b/ctr-std/src/os/raw/ulong.md
@@ -0,0 +1,7 @@
+Equivalent to C's `unsigned long` type.
+
+This type will always be [`u32`] or [`u64`]. Most notably, many Linux-based systems assume an `u64`, but Windows assumes `u32`. The C standard technically only requires that this type be an unsigned integer with the size of a [`long`], although in practice, no system would have a `ulong` that is neither a `u32` nor `u64`.
+
+[`long`]: type.c_long.html
+[`u32`]: ../../primitive.u32.html
+[`u64`]: ../../primitive.u64.html
diff --git a/ctr-std/src/os/raw/ulonglong.md b/ctr-std/src/os/raw/ulonglong.md
new file mode 100644
index 0000000..c41faf7
--- /dev/null
+++ b/ctr-std/src/os/raw/ulonglong.md
@@ -0,0 +1,7 @@
+Equivalent to C's `unsigned long long` type.
+
+This type will almost always be [`u64`], but may differ on some systems. The C standard technically only requires that this type be an unsigned integer with the size of a [`long long`], although in practice, no system would have a `long long` that is not a `u64`, as most systems do not have a standardised [`u128`] type.
+
+[`long long`]: type.c_longlong.html
+[`u64`]: ../../primitive.u64.html
+[`u128`]: ../../primitive.u128.html
diff --git a/ctr-std/src/os/raw/ushort.md b/ctr-std/src/os/raw/ushort.md
new file mode 100644
index 0000000..d364abb
--- /dev/null
+++ b/ctr-std/src/os/raw/ushort.md
@@ -0,0 +1,6 @@
+Equivalent to C's `unsigned short` type.
+
+This type will almost always be [`u16`], but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as a [`short`].
+
+[`short`]: type.c_short.html
+[`u16`]: ../../primitive.u16.html