Skip to content

Commit 2b483e7

Browse files
committed
Move std::os::raw into core
1 parent 70cac59 commit 2b483e7

17 files changed

+135
-96
lines changed

src/libcore/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#![feature(doc_cfg)]
8888
#![feature(doc_spotlight)]
8989
#![feature(extern_types)]
90+
#![feature(external_doc)]
9091
#![feature(fundamental)]
9192
#![feature(intrinsics)]
9293
#![feature(lang_items)]
@@ -205,6 +206,9 @@ pub mod time;
205206

206207
pub mod unicode;
207208

209+
/* OS-specific functionality */
210+
pub mod os;
211+
208212
/* Async */
209213
pub mod future;
210214
pub mod task;

src/libcore/os/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2012-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.
4+
//
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.
10+
11+
//! OS-specific functionality.
12+
13+
#![stable(feature = "os", since = "1.29.0")]
14+
15+
pub mod raw;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/libcore/os/raw/mod.rs

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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.
4+
//
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.
10+
11+
//! Platform-specific types, as defined by C.
12+
//!
13+
//! Code that interacts via FFI will almost certainly be using the
14+
//! base types provided by C, which aren't nearly as nicely defined
15+
//! as Rust's primitive types. This module provides types which will
16+
//! match those defined by C, so that code that interacts with C will
17+
//! refer to the correct types.
18+
19+
#![stable(feature = "raw_os", since = "1.1.0")]
20+
21+
use fmt;
22+
23+
#[doc(include = "os/raw/char.md")]
24+
#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
25+
target_arch = "arm",
26+
target_arch = "powerpc",
27+
target_arch = "powerpc64",
28+
target_arch = "s390x")),
29+
all(target_os = "android", any(target_arch = "aarch64",
30+
target_arch = "arm")),
31+
all(target_os = "l4re", target_arch = "x86_64"),
32+
all(target_os = "openbsd", target_arch = "aarch64"),
33+
all(target_os = "fuchsia", target_arch = "aarch64")))]
34+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
35+
#[doc(include = "os/raw/char.md")]
36+
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
37+
target_arch = "arm",
38+
target_arch = "powerpc",
39+
target_arch = "powerpc64",
40+
target_arch = "s390x")),
41+
all(target_os = "android", any(target_arch = "aarch64",
42+
target_arch = "arm")),
43+
all(target_os = "l4re", target_arch = "x86_64"),
44+
all(target_os = "openbsd", target_arch = "aarch64"),
45+
all(target_os = "fuchsia", target_arch = "aarch64"))))]
46+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
47+
#[doc(include = "os/raw/schar.md")]
48+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
49+
#[doc(include = "os/raw/uchar.md")]
50+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
51+
#[doc(include = "os/raw/short.md")]
52+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
53+
#[doc(include = "os/raw/ushort.md")]
54+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
55+
#[doc(include = "os/raw/int.md")]
56+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
57+
#[doc(include = "os/raw/uint.md")]
58+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
59+
#[doc(include = "os/raw/long.md")]
60+
#[cfg(any(target_pointer_width = "32", windows))]
61+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
62+
#[doc(include = "os/raw/ulong.md")]
63+
#[cfg(any(target_pointer_width = "32", windows))]
64+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
65+
#[doc(include = "os/raw/long.md")]
66+
#[cfg(all(target_pointer_width = "64", not(windows)))]
67+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
68+
#[doc(include = "os/raw/ulong.md")]
69+
#[cfg(all(target_pointer_width = "64", not(windows)))]
70+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
71+
#[doc(include = "os/raw/longlong.md")]
72+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
73+
#[doc(include = "os/raw/ulonglong.md")]
74+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
75+
#[doc(include = "os/raw/float.md")]
76+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
77+
#[doc(include = "os/raw/double.md")]
78+
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
79+
80+
/// Equivalent to C's `void` type when used as a [pointer].
81+
///
82+
/// In essence, `*const c_void` is equivalent to C's `const void*`
83+
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
84+
/// *not* the same as C's `void` return type, which is Rust's `()` type.
85+
///
86+
/// Ideally, this type would be equivalent to [`!`], but currently it may
87+
/// be more ideal to use `c_void` for FFI purposes.
88+
///
89+
/// [`!`]: ../../../std/primitive.never.html
90+
/// [pointer]: ../../../std/primitive.pointer.html
91+
// NB: For LLVM to recognize the void pointer type and by extension
92+
// functions like malloc(), we need to have it represented as i8* in
93+
// LLVM bitcode. The enum used here ensures this and prevents misuse
94+
// of the "raw" type by only having private variants.. We need two
95+
// variants, because the compiler complains about the repr attribute
96+
// otherwise.
97+
#[repr(u8)]
98+
#[stable(feature = "raw_os", since = "1.1.0")]
99+
pub enum c_void {
100+
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
101+
issue = "0")]
102+
#[doc(hidden)] __variant1,
103+
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
104+
issue = "0")]
105+
#[doc(hidden)] __variant2,
106+
}
107+
108+
#[stable(feature = "std_debug", since = "1.16.0")]
109+
impl fmt::Debug for c_void {
110+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111+
f.pad("c_void")
112+
}
113+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/libstd/os/raw/mod.rs

+3-96
Original file line numberDiff line numberDiff line change
@@ -18,115 +18,22 @@
1818
1919
#![stable(feature = "raw_os", since = "1.1.0")]
2020

21-
use fmt;
22-
23-
#[doc(include = "os/raw/char.md")]
24-
#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
25-
target_arch = "arm",
26-
target_arch = "powerpc",
27-
target_arch = "powerpc64",
28-
target_arch = "s390x")),
29-
all(target_os = "android", any(target_arch = "aarch64",
30-
target_arch = "arm")),
31-
all(target_os = "l4re", target_arch = "x86_64"),
32-
all(target_os = "openbsd", target_arch = "aarch64"),
33-
all(target_os = "fuchsia", target_arch = "aarch64")))]
34-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
35-
#[doc(include = "os/raw/char.md")]
36-
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
37-
target_arch = "arm",
38-
target_arch = "powerpc",
39-
target_arch = "powerpc64",
40-
target_arch = "s390x")),
41-
all(target_os = "android", any(target_arch = "aarch64",
42-
target_arch = "arm")),
43-
all(target_os = "l4re", target_arch = "x86_64"),
44-
all(target_os = "openbsd", target_arch = "aarch64"),
45-
all(target_os = "fuchsia", target_arch = "aarch64"))))]
46-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
47-
#[doc(include = "os/raw/schar.md")]
48-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
49-
#[doc(include = "os/raw/uchar.md")]
50-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
51-
#[doc(include = "os/raw/short.md")]
52-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
53-
#[doc(include = "os/raw/ushort.md")]
54-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
55-
#[doc(include = "os/raw/int.md")]
56-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
57-
#[doc(include = "os/raw/uint.md")]
58-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
59-
#[doc(include = "os/raw/long.md")]
60-
#[cfg(any(target_pointer_width = "32", windows))]
61-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
62-
#[doc(include = "os/raw/ulong.md")]
63-
#[cfg(any(target_pointer_width = "32", windows))]
64-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
65-
#[doc(include = "os/raw/long.md")]
66-
#[cfg(all(target_pointer_width = "64", not(windows)))]
67-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
68-
#[doc(include = "os/raw/ulong.md")]
69-
#[cfg(all(target_pointer_width = "64", not(windows)))]
70-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
71-
#[doc(include = "os/raw/longlong.md")]
72-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
73-
#[doc(include = "os/raw/ulonglong.md")]
74-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
75-
#[doc(include = "os/raw/float.md")]
76-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
77-
#[doc(include = "os/raw/double.md")]
78-
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
79-
80-
/// Equivalent to C's `void` type when used as a [pointer].
81-
///
82-
/// In essence, `*const c_void` is equivalent to C's `const void*`
83-
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
84-
/// *not* the same as C's `void` return type, which is Rust's `()` type.
85-
///
86-
/// Ideally, this type would be equivalent to [`!`], but currently it may
87-
/// be more ideal to use `c_void` for FFI purposes.
88-
///
89-
/// [`!`]: ../../primitive.never.html
90-
/// [pointer]: ../../primitive.pointer.html
91-
// NB: For LLVM to recognize the void pointer type and by extension
92-
// functions like malloc(), we need to have it represented as i8* in
93-
// LLVM bitcode. The enum used here ensures this and prevents misuse
94-
// of the "raw" type by only having private variants.. We need two
95-
// variants, because the compiler complains about the repr attribute
96-
// otherwise.
97-
#[repr(u8)]
9821
#[stable(feature = "raw_os", since = "1.1.0")]
99-
pub enum c_void {
100-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
101-
issue = "0")]
102-
#[doc(hidden)] __variant1,
103-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
104-
issue = "0")]
105-
#[doc(hidden)] __variant2,
106-
}
107-
108-
#[stable(feature = "std_debug", since = "1.16.0")]
109-
impl fmt::Debug for c_void {
110-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111-
f.pad("c_void")
112-
}
113-
}
22+
pub use ::core::os::raw::*;
11423

11524
#[cfg(test)]
11625
#[allow(unused_imports)]
11726
mod tests {
11827
use any::TypeId;
11928
use libc;
12029
use mem;
121-
122-
macro_rules! ok {
30+
macro_rules! ok {
12331
($($t:ident)*) => {$(
12432
assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
12533
"{} is wrong", stringify!($t));
12634
)*}
12735
}
128-
129-
#[test]
36+
#[test]
13037
fn same() {
13138
use os::raw;
13239
ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong

0 commit comments

Comments
 (0)