diff --git a/library/core/src/ffi/c_longlong.md b/library/core/src/ffi/c_longlong.md index 49c61bd61f4ad..234ab344409da 100644 --- a/library/core/src/ffi/c_longlong.md +++ b/library/core/src/ffi/c_longlong.md @@ -2,4 +2,4 @@ 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`]: c_int +[`long`]: c_long diff --git a/library/core/src/ffi/c_ptrdiff_t.md b/library/core/src/ffi/c_ptrdiff_t.md new file mode 100644 index 0000000000000..b1d24c3323140 --- /dev/null +++ b/library/core/src/ffi/c_ptrdiff_t.md @@ -0,0 +1,3 @@ +Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++). + +This type is currently always [`isize`], however in the future there may be platforms where this is not the case. diff --git a/library/core/src/ffi/c_short.md b/library/core/src/ffi/c_short.md index 3d1e53d1325f3..29415129b50a7 100644 --- a/library/core/src/ffi/c_short.md +++ b/library/core/src/ffi/c_short.md @@ -1,5 +1,3 @@ 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`]: c_char diff --git a/library/core/src/ffi/c_size_t.md b/library/core/src/ffi/c_size_t.md new file mode 100644 index 0000000000000..e1aff8672fdd3 --- /dev/null +++ b/library/core/src/ffi/c_size_t.md @@ -0,0 +1,3 @@ +Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++). + +This type is currently always [`usize`], however in the future there may be platforms where this is not the case. diff --git a/library/core/src/ffi/c_ssize_t.md b/library/core/src/ffi/c_ssize_t.md new file mode 100644 index 0000000000000..08adad4545aa8 --- /dev/null +++ b/library/core/src/ffi/c_ssize_t.md @@ -0,0 +1,3 @@ +Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type. + +This type is currently always [`isize`], however in the future there may be platforms where this is not the case. diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 0bc98e2ea8645..b73486250d270 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -38,13 +38,42 @@ pub use self::va_list::{VaArgSafe, VaList, VaListImpl}; pub mod va_list; mod primitives; -#[stable(feature = "core_ffi_c", since = "1.64.0")] -pub use self::primitives::{ - c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, - c_ulong, c_ulonglong, c_ushort, -}; -#[unstable(feature = "c_size_t", issue = "88345")] -pub use self::primitives::{c_ptrdiff_t, c_size_t, c_ssize_t}; + +macro_rules! type_alias { + { + $Docfile:tt, $Alias:ident = $Real:ty; + $( $Cfg:tt )* + } => { + #[doc = include_str!($Docfile)] + #[doc(cfg(all()))] + $( $Cfg )* + pub type $Alias = $Real; + } +} + +type_alias! { "c_char.md", c_char = self::primitives::c_char; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_schar.md", c_schar = self::primitives::c_schar; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_uchar.md", c_uchar = self::primitives::c_uchar; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_short.md", c_short = self::primitives::c_short; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_ushort.md", c_ushort = self::primitives::c_ushort; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_int.md", c_int = self::primitives::c_int; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_uint.md", c_uint = self::primitives::c_uint; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_long.md", c_long = self::primitives::c_long; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_ulong.md", c_ulong = self::primitives::c_ulong; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_longlong.md", c_longlong = self::primitives::c_longlong; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_ulonglong.md", c_ulonglong = self::primitives::c_ulonglong; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_float.md", c_float = self::primitives::c_float; #[stable(feature = "core_ffi_c", since = "1.64.0")]} +type_alias! { "c_double.md", c_double = self::primitives::c_double; #[stable(feature = "core_ffi_c", since = "1.64.0")]} + +type_alias! { "c_size_t.md", c_size_t = self::primitives::c_size_t; #[unstable(feature = "c_size_t", issue = "88345")]} +type_alias! { "c_ptrdiff_t.md", c_ptrdiff_t = self::primitives::c_ptrdiff_t; #[unstable(feature = "c_size_t", issue = "88345")]} +type_alias! { "c_ssize_t.md", c_ssize_t = self::primitives::c_ssize_t; #[unstable(feature = "c_size_t", issue = "88345")]} // N.B., for LLVM to recognize the void pointer type and by extension // functions like malloc(), we need to have it represented as i8* in diff --git a/library/core/src/ffi/primitives.rs b/library/core/src/ffi/primitives.rs index fa23cf33af431..f72252f18f4bf 100644 --- a/library/core/src/ffi/primitives.rs +++ b/library/core/src/ffi/primitives.rs @@ -3,36 +3,25 @@ //! This module is intentionally standalone to facilitate parsing when retrieving //! core C types. -macro_rules! type_alias { - { - $Docfile:tt, $Alias:ident = $Real:ty; - $( $Cfg:tt )* - } => { - #[doc = include_str!($Docfile)] - $( $Cfg )* - #[stable(feature = "core_ffi_c", since = "1.64.0")] - pub type $Alias = $Real; - } -} +pub(super) type c_char = c_char_definition::c_char; -type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] } +pub(super) type c_schar = i8; +pub(super) type c_uchar = u8; -type_alias! { "c_schar.md", c_schar = i8; } -type_alias! { "c_uchar.md", c_uchar = u8; } -type_alias! { "c_short.md", c_short = i16; } -type_alias! { "c_ushort.md", c_ushort = u16; } +pub(super) type c_short = i16; +pub(super) type c_ushort = u16; -type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] } -type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] } +pub(super) type c_int = c_int_definition::c_int; +pub(super) type c_uint = c_int_definition::c_uint; -type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] } -type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] } +pub(super) type c_long = c_long_definition::c_long; +pub(super) type c_ulong = c_long_definition::c_ulong; -type_alias! { "c_longlong.md", c_longlong = i64; } -type_alias! { "c_ulonglong.md", c_ulonglong = u64; } +pub(super) type c_longlong = i64; +pub(super) type c_ulonglong = u64; -type_alias! { "c_float.md", c_float = f32; } -type_alias! { "c_double.md", c_double = f64; } +pub(super) type c_float = f32; +pub(super) type c_double = f64; mod c_char_definition { crate::cfg_select! { @@ -150,26 +139,9 @@ mod c_long_definition { } } -/// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++). -/// -/// This type is currently always [`usize`], however in the future there may be -/// platforms where this is not the case. -#[unstable(feature = "c_size_t", issue = "88345")] -pub type c_size_t = usize; - -/// Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++). -/// -/// This type is currently always [`isize`], however in the future there may be -/// platforms where this is not the case. -#[unstable(feature = "c_size_t", issue = "88345")] -pub type c_ptrdiff_t = isize; - -/// Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type. -/// -/// This type is currently always [`isize`], however in the future there may be -/// platforms where this is not the case. -#[unstable(feature = "c_size_t", issue = "88345")] -pub type c_ssize_t = isize; +pub(super) type c_size_t = usize; +pub(super) type c_ptrdiff_t = isize; +pub(super) type c_ssize_t = isize; mod c_int_definition { crate::cfg_select! {