Skip to content

Commit 628f5d2

Browse files
committed
std: Stabilize the ffi module
The two main sub-modules, `c_str` and `os_str`, have now had some time to bake in the standard library. This commits performs a sweep over the modules adding various stability tags. The following APIs are now marked `#[stable]` * `OsString` * `OsStr` * `OsString::from_string` * `OsString::from_str` * `OsString::new` * `OsString::into_string` * `OsString::push` (renamed from `push_os_str`, added an `AsOsStr` bound) * various trait implementations for `OsString` * `OsStr::from_str` * `OsStr::to_str` * `OsStr::to_string_lossy` * `OsStr::to_os_string` * various trait implementations for `OsStr` * `CString` * `CStr` * `NulError` * `CString::new` - this API's implementation may change as a result of rust-lang/rfcs#912 but the usage of `CString::new(thing)` looks like it is unlikely to change. Additionally, the `IntoBytes` bound is also likely to change but the set of implementors for the trait will not change (despite the trait perhaps being renamed). * `CString::from_vec_unchecked` * `CString::as_bytes` * `CString::as_bytes_with_nul` * `NulError::nul_position` * `NulError::into_vec` * `CStr::from_ptr` * `CStr::as_ptr` * `CStr::to_bytes` * `CStr::to_bytes_with_nul` * various trait implementations for `CStr` The following APIs remain `#[unstable]` * `OsStr*Ext` traits remain unstable as the organization of `os::platform` is uncertain still and the traits may change location. * `AsOsStr` remains unstable as generic conversion traits are likely to be rethought soon. The following APIs were deprecated * `OsString::push_os_str` is now called `push` and takes `T: AsOsStr` instead (a superset of the previous functionality).
1 parent 68740b4 commit 628f5d2

File tree

11 files changed

+89
-29
lines changed

11 files changed

+89
-29
lines changed

src/compiletest/compiletest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#![feature(unicode)]
2323
#![feature(core)]
2424
#![feature(path)]
25-
#![feature(os)]
2625
#![feature(io)]
2726
#![feature(fs)]
2827
#![feature(net)]

src/compiletest/runtest.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use procsrv;
2020
use util::logv;
2121

2222
use std::env;
23-
use std::ffi::OsStr;
2423
use std::fmt;
2524
use std::fs::{self, File};
2625
use std::io::BufReader;
@@ -1323,7 +1322,7 @@ fn make_exe_name(config: &Config, testfile: &Path) -> PathBuf {
13231322
let mut f = output_base_name(config, testfile);
13241323
if !env::consts::EXE_SUFFIX.is_empty() {
13251324
let mut fname = f.file_name().unwrap().to_os_string();
1326-
fname.push_os_str(OsStr::from_str(env::consts::EXE_SUFFIX));
1325+
fname.push(env::consts::EXE_SUFFIX);
13271326
f.set_file_name(&fname);
13281327
}
13291328
f
@@ -1433,7 +1432,7 @@ fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> PathBuf {
14331432
fn aux_output_dir_name(config: &Config, testfile: &Path) -> PathBuf {
14341433
let f = output_base_name(config, testfile);
14351434
let mut fname = f.file_name().unwrap().to_os_string();
1436-
fname.push_os_str(OsStr::from_str("libaux"));
1435+
fname.push("libaux");
14371436
f.with_file_name(&fname)
14381437
}
14391438

@@ -1647,8 +1646,8 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> PathBuf {
16471646
p.to_path_buf()
16481647
} else {
16491648
let mut stem = p.file_stem().unwrap().to_os_string();
1650-
stem.push_os_str(OsStr::from_str("-"));
1651-
stem.push_os_str(OsStr::from_str(suffix));
1649+
stem.push("-");
1650+
stem.push(suffix);
16521651
p.with_file_name(&stem)
16531652
}
16541653
}

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#![feature(unsafe_destructor)]
3939
#![feature(staged_api)]
4040
#![feature(std_misc)]
41-
#![feature(os)]
4241
#![feature(path)]
4342
#![feature(fs)]
4443
#![feature(io)]

src/librustc_driver/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(int_uint)]
3030
#![feature(old_io)]
3131
#![feature(libc)]
32-
#![feature(os)]
3332
#![feature(quote)]
3433
#![feature(rustc_diagnostic_macros)]
3534
#![feature(rustc_private)]

src/librustc_trans/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use util::common::time;
2727
use util::ppaux;
2828
use util::sha2::{Digest, Sha256};
2929

30-
use std::ffi::{AsOsStr, OsString};
30+
use std::ffi::OsString;
3131
use std::fs::{self, TempDir, PathExt};
3232
use std::io::{self, Read, Write};
3333
use std::mem;
@@ -882,7 +882,7 @@ fn link_args(cmd: &mut Command,
882882
let morestack = lib_path.join("libmorestack.a");
883883

884884
let mut v = OsString::from_str("-Wl,-force_load,");
885-
v.push_os_str(morestack.as_os_str());
885+
v.push(&morestack);
886886
cmd.arg(&v);
887887
} else {
888888
cmd.args(&["-Wl,--whole-archive", "-lmorestack", "-Wl,--no-whole-archive"]);
@@ -1007,7 +1007,7 @@ fn link_args(cmd: &mut Command,
10071007

10081008
if sess.opts.cg.rpath {
10091009
let mut v = OsString::from_str("-Wl,-install_name,@rpath/");
1010-
v.push_os_str(out_filename.file_name().unwrap());
1010+
v.push(out_filename.file_name().unwrap());
10111011
cmd.arg(&v);
10121012
}
10131013
} else {
@@ -1107,7 +1107,7 @@ fn add_local_native_libraries(cmd: &mut Command, sess: &Session) {
11071107
&search_path[..],
11081108
&sess.diagnostic().handler);
11091109
let mut v = OsString::from_str("-Wl,-force_load,");
1110-
v.push_os_str(lib.as_os_str());
1110+
v.push(&lib);
11111111
cmd.arg(&v);
11121112
}
11131113
}

src/librustc_trans/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
#![feature(rustc_private)]
3636
#![feature(unsafe_destructor)]
3737
#![feature(staged_api)]
38-
#![feature(std_misc)]
3938
#![feature(unicode)]
4039
#![feature(io)]
4140
#![feature(fs)]
4241
#![feature(path)]
43-
#![feature(os)]
4442
#![feature(tempdir)]
4543

4644
extern crate arena;

src/librustdoc/html/render.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use std::cell::RefCell;
3838
use std::cmp::Ordering;
3939
use std::collections::{HashMap, HashSet};
4040
use std::default::Default;
41-
use std::ffi::OsStr;
4241
use std::fmt;
4342
use std::fs::{self, File};
4443
use std::io::prelude::*;
@@ -770,7 +769,7 @@ impl<'a> SourceCollector<'a> {
770769

771770
let mut fname = p.file_name().expect("source has no filename")
772771
.to_os_string();
773-
fname.push_os_str(OsStr::from_str(".html"));
772+
fname.push(".html");
774773
cur.push(&fname);
775774
let mut w = BufWriter::new(try!(File::create(&cur)));
776775

src/libstd/ffi/c_str.rs

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![unstable(feature = "std_misc")]
12+
1113
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1214
use error::{Error, FromError};
1315
use fmt;
@@ -59,6 +61,7 @@ use vec::Vec;
5961
/// # }
6062
/// ```
6163
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
64+
#[stable(feature = "rust1", since = "1.0.0")]
6265
pub struct CString {
6366
inner: Vec<u8>,
6467
}
@@ -110,13 +113,19 @@ pub struct CString {
110113
/// }
111114
/// ```
112115
#[derive(Hash)]
116+
#[stable(feature = "rust1", since = "1.0.0")]
113117
pub struct CStr {
118+
// FIXME: this should not be represented with a DST slice but rather with
119+
// just a raw `libc::c_char` along with some form of marker to make
120+
// this an unsized type. Essentially `sizeof(&CStr)` should be the
121+
// same as `sizeof(&c_char)` but `CStr` should be an unsized type.
114122
inner: [libc::c_char]
115123
}
116124

117125
/// An error returned from `CString::new` to indicate that a nul byte was found
118126
/// in the vector provided.
119127
#[derive(Clone, PartialEq, Debug)]
128+
#[stable(feature = "rust1", since = "1.0.0")]
120129
pub struct NulError(usize, Vec<u8>);
121130

122131
/// A conversion trait used by the constructor of `CString` for types that can
@@ -153,6 +162,7 @@ impl CString {
153162
/// This function will return an error if the bytes yielded contain an
154163
/// internal 0 byte. The error returned will contain the bytes as well as
155164
/// the position of the nul byte.
165+
#[stable(feature = "rust1", since = "1.0.0")]
156166
pub fn new<T: IntoBytes>(t: T) -> Result<CString, NulError> {
157167
let bytes = t.into_bytes();
158168
match bytes.iter().position(|x| *x == 0) {
@@ -216,6 +226,7 @@ impl CString {
216226
///
217227
/// This method is equivalent to `from_vec` except that no runtime assertion
218228
/// is made that `v` contains no 0 bytes.
229+
#[stable(feature = "rust1", since = "1.0.0")]
219230
pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
220231
v.push(0);
221232
CString { inner: v }
@@ -225,17 +236,20 @@ impl CString {
225236
///
226237
/// The returned slice does **not** contain the trailing nul separator and
227238
/// it is guaranteed to not have any interior nul bytes.
239+
#[stable(feature = "rust1", since = "1.0.0")]
228240
pub fn as_bytes(&self) -> &[u8] {
229241
&self.inner[..self.inner.len() - 1]
230242
}
231243

232244
/// Equivalent to the `as_bytes` function except that the returned slice
233245
/// includes the trailing nul byte.
246+
#[stable(feature = "rust1", since = "1.0.0")]
234247
pub fn as_bytes_with_nul(&self) -> &[u8] {
235248
&self.inner
236249
}
237250
}
238251

252+
#[stable(feature = "rust1", since = "1.0.0")]
239253
impl Deref for CString {
240254
type Target = CStr;
241255

@@ -254,30 +268,36 @@ impl fmt::Debug for CString {
254268
impl NulError {
255269
/// Returns the position of the nul byte in the slice that was provided to
256270
/// `CString::from_vec`.
271+
#[stable(feature = "rust1", since = "1.0.0")]
257272
pub fn nul_position(&self) -> usize { self.0 }
258273

259274
/// Consumes this error, returning the underlying vector of bytes which
260275
/// generated the error in the first place.
276+
#[stable(feature = "rust1", since = "1.0.0")]
261277
pub fn into_vec(self) -> Vec<u8> { self.1 }
262278
}
263279

280+
#[stable(feature = "rust1", since = "1.0.0")]
264281
impl Error for NulError {
265282
fn description(&self) -> &str { "nul byte found in data" }
266283
}
267284

285+
#[stable(feature = "rust1", since = "1.0.0")]
268286
impl fmt::Display for NulError {
269287
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
270288
write!(f, "nul byte found in provided data at position: {}", self.0)
271289
}
272290
}
273291

292+
#[stable(feature = "rust1", since = "1.0.0")]
274293
impl FromError<NulError> for io::Error {
275294
fn from_error(_: NulError) -> io::Error {
276295
io::Error::new(io::ErrorKind::InvalidInput,
277296
"data provided contains a nul byte", None)
278297
}
279298
}
280299

300+
#[stable(feature = "rust1", since = "1.0.0")]
281301
impl FromError<NulError> for old_io::IoError {
282302
fn from_error(_: NulError) -> old_io::IoError {
283303
old_io::IoError {
@@ -325,6 +345,7 @@ impl CStr {
325345
/// }
326346
/// # }
327347
/// ```
348+
#[stable(feature = "rust1", since = "1.0.0")]
328349
pub unsafe fn from_ptr<'a>(ptr: *const libc::c_char) -> &'a CStr {
329350
let len = libc::strlen(ptr);
330351
mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
@@ -335,6 +356,7 @@ impl CStr {
335356
/// The returned pointer will be valid for as long as `self` is and points
336357
/// to a contiguous region of memory terminated with a 0 byte to represent
337358
/// the end of the string.
359+
#[stable(feature = "rust1", since = "1.0.0")]
338360
pub fn as_ptr(&self) -> *const libc::c_char {
339361
self.inner.as_ptr()
340362
}
@@ -351,6 +373,7 @@ impl CStr {
351373
/// > **Note**: This method is currently implemented as a 0-cost cast, but
352374
/// > it is planned to alter its definition in the future to perform the
353375
/// > length calculation whenever this method is called.
376+
#[stable(feature = "rust1", since = "1.0.0")]
354377
pub fn to_bytes(&self) -> &[u8] {
355378
let bytes = self.to_bytes_with_nul();
356379
&bytes[..bytes.len() - 1]
@@ -364,22 +387,27 @@ impl CStr {
364387
/// > **Note**: This method is currently implemented as a 0-cost cast, but
365388
/// > it is planned to alter its definition in the future to perform the
366389
/// > length calculation whenever this method is called.
390+
#[stable(feature = "rust1", since = "1.0.0")]
367391
pub fn to_bytes_with_nul(&self) -> &[u8] {
368392
unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.inner) }
369393
}
370394
}
371395

396+
#[stable(feature = "rust1", since = "1.0.0")]
372397
impl PartialEq for CStr {
373398
fn eq(&self, other: &CStr) -> bool {
374399
self.to_bytes().eq(other.to_bytes())
375400
}
376401
}
402+
#[stable(feature = "rust1", since = "1.0.0")]
377403
impl Eq for CStr {}
404+
#[stable(feature = "rust1", since = "1.0.0")]
378405
impl PartialOrd for CStr {
379406
fn partial_cmp(&self, other: &CStr) -> Option<Ordering> {
380407
self.to_bytes().partial_cmp(&other.to_bytes())
381408
}
382409
}
410+
#[stable(feature = "rust1", since = "1.0.0")]
383411
impl Ord for CStr {
384412
fn cmp(&self, other: &CStr) -> Ordering {
385413
self.to_bytes().cmp(&other.to_bytes())

src/libstd/ffi/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010

1111
//! Utilities related to FFI bindings.
1212
13-
#![unstable(feature = "std_misc",
14-
reason = "module just underwent fairly large reorganization and the dust \
15-
still needs to settle")]
13+
#![stable(feature = "rust1", since = "1.0.0")]
1614

17-
pub use self::c_str::{CString, CStr, NulError, IntoBytes};
15+
#[stable(feature = "rust1", since = "1.0.0")]
16+
pub use self::c_str::{CString, CStr};
17+
pub use self::c_str::{NulError, IntoBytes};
1818
#[allow(deprecated)]
1919
pub use self::c_str::c_str_to_bytes;
2020
#[allow(deprecated)]
2121
pub use self::c_str::c_str_to_bytes_with_nul;
2222

23+
#[stable(feature = "rust1", since = "1.0.0")]
2324
pub use self::os_str::OsString;
25+
#[stable(feature = "rust1", since = "1.0.0")]
2426
pub use self::os_str::OsStr;
2527

2628
mod c_str;
2729
mod os_str;
2830

2931
// FIXME (#21670): these should be defined in the os_str module
3032
/// Freely convertible to an `&OsStr` slice.
33+
#[unstable(feature = "std_misc")]
3134
pub trait AsOsStr {
3235
/// Convert to an `&OsStr` slice.
3336
fn as_os_str(&self) -> &OsStr;

0 commit comments

Comments
 (0)