Skip to content

Commit 6ffa9f0

Browse files
committed
Avoid duplicate stable and unstable attributes between ffi/mod.rs and ffi/primitives.rs
Split c_ptrdiff_t.md c_size_t.md c_ssize_t.md out of primitives.rs for consistence
1 parent 14ab13f commit 6ffa9f0

File tree

5 files changed

+60
-52
lines changed

5 files changed

+60
-52
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++).
2+
3+
This type is currently always [`isize`], however in the future there may be platforms where this is not the case.

library/core/src/ffi/c_size_t.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++).
2+
3+
This type is currently always [`usize`], however in the future there may be platforms where this is not the case.

library/core/src/ffi/c_ssize_t.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type.
2+
3+
This type is currently always [`isize`], however in the future there may be platforms where this is not the case.

library/core/src/ffi/mod.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,41 @@ pub use self::va_list::{VaArgSafe, VaList, VaListImpl};
3838
pub mod va_list;
3939

4040
mod primitives;
41-
#[stable(feature = "core_ffi_c", since = "1.64.0")]
42-
pub use self::primitives::{
43-
c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint,
44-
c_ulong, c_ulonglong, c_ushort,
45-
};
46-
#[unstable(feature = "c_size_t", issue = "88345")]
47-
pub use self::primitives::{c_ptrdiff_t, c_size_t, c_ssize_t};
41+
42+
macro_rules! type_alias {
43+
{
44+
$Docfile:tt, $Alias:ident = $Real:ty;
45+
$( $Cfg:tt )*
46+
} => {
47+
#[doc = include_str!($Docfile)]
48+
#[doc(cfg(all()))]
49+
$( $Cfg )*
50+
pub type $Alias = $Real;
51+
}
52+
}
53+
54+
type_alias! { "c_char.md", c_char = self::primitives::c_char; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
55+
type_alias! { "c_schar.md", c_schar = self::primitives::c_schar; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
56+
type_alias! { "c_uchar.md", c_uchar = self::primitives::c_uchar; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
57+
58+
type_alias! { "c_short.md", c_short = self::primitives::c_short; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
59+
type_alias! { "c_ushort.md", c_ushort = self::primitives::c_ushort; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
60+
61+
type_alias! { "c_int.md", c_int = self::primitives::c_int; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
62+
type_alias! { "c_uint.md", c_uint = self::primitives::c_uint; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
63+
64+
type_alias! { "c_long.md", c_long = self::primitives::c_long; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
65+
type_alias! { "c_ulong.md", c_ulong = self::primitives::c_ulong; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
66+
67+
type_alias! { "c_longlong.md", c_longlong = self::primitives::c_longlong; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
68+
type_alias! { "c_ulonglong.md", c_ulonglong = self::primitives::c_ulonglong; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
69+
70+
type_alias! { "c_float.md", c_float = self::primitives::c_float; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
71+
type_alias! { "c_double.md", c_double = self::primitives::c_double; #[stable(feature = "core_ffi_c", since = "1.64.0")]}
72+
73+
type_alias! { "c_size_t.md", c_size_t = self::primitives::c_size_t; #[unstable(feature = "c_size_t", issue = "88345")]}
74+
type_alias! { "c_ptrdiff_t.md", c_ptrdiff_t = self::primitives::c_ptrdiff_t; #[unstable(feature = "c_size_t", issue = "88345")]}
75+
type_alias! { "c_ssize_t.md", c_ssize_t = self::primitives::c_ssize_t; #[unstable(feature = "c_size_t", issue = "88345")]}
4876

4977
// N.B., for LLVM to recognize the void pointer type and by extension
5078
// functions like malloc(), we need to have it represented as i8* in

library/core/src/ffi/primitives.rs

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,24 @@
33
//! This module is intentionally standalone to facilitate parsing when retrieving
44
//! core C types.
55
6-
macro_rules! type_alias {
7-
{
8-
$Docfile:tt, $Alias:ident = $Real:ty;
9-
$( $Cfg:tt )*
10-
} => {
11-
#[doc = include_str!($Docfile)]
12-
$( $Cfg )*
13-
#[stable(feature = "core_ffi_c", since = "1.64.0")]
14-
pub type $Alias = $Real;
15-
}
16-
}
17-
18-
type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] }
6+
pub(super) type c_char = c_char_definition::c_char;
7+
pub(super) type c_schar = i8;
8+
pub(super) type c_uchar = u8;
199

20-
type_alias! { "c_schar.md", c_schar = i8; }
21-
type_alias! { "c_uchar.md", c_uchar = u8; }
22-
type_alias! { "c_short.md", c_short = i16; }
23-
type_alias! { "c_ushort.md", c_ushort = u16; }
10+
pub(super) type c_short = i16;
11+
pub(super) type c_ushort = u16;
2412

25-
type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] }
26-
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] }
13+
pub(super) type c_int = c_int_definition::c_int;
14+
pub(super) type c_uint = c_int_definition::c_uint;
2715

28-
type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] }
29-
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] }
16+
pub(super) type c_long = c_long_definition::c_long;
17+
pub(super) type c_ulong = c_long_definition::c_ulong;
3018

31-
type_alias! { "c_longlong.md", c_longlong = i64; }
32-
type_alias! { "c_ulonglong.md", c_ulonglong = u64; }
19+
pub(super) type c_longlong = i64;
20+
pub(super) type c_ulonglong = u64;
3321

34-
type_alias! { "c_float.md", c_float = f32; }
35-
type_alias! { "c_double.md", c_double = f64; }
22+
pub(super) type c_float = f32;
23+
pub(super) type c_double = f64;
3624

3725
mod c_char_definition {
3826
crate::cfg_select! {
@@ -150,26 +138,9 @@ mod c_long_definition {
150138
}
151139
}
152140

153-
/// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++).
154-
///
155-
/// This type is currently always [`usize`], however in the future there may be
156-
/// platforms where this is not the case.
157-
#[unstable(feature = "c_size_t", issue = "88345")]
158-
pub type c_size_t = usize;
159-
160-
/// Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++).
161-
///
162-
/// This type is currently always [`isize`], however in the future there may be
163-
/// platforms where this is not the case.
164-
#[unstable(feature = "c_size_t", issue = "88345")]
165-
pub type c_ptrdiff_t = isize;
166-
167-
/// Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type.
168-
///
169-
/// This type is currently always [`isize`], however in the future there may be
170-
/// platforms where this is not the case.
171-
#[unstable(feature = "c_size_t", issue = "88345")]
172-
pub type c_ssize_t = isize;
141+
pub(super) type c_size_t = usize;
142+
pub(super) type c_ptrdiff_t = isize;
143+
pub(super) type c_ssize_t = isize;
173144

174145
mod c_int_definition {
175146
crate::cfg_select! {

0 commit comments

Comments
 (0)