Skip to content

Commit becf32e

Browse files
committed
---
yaml --- r: 153402 b: refs/heads/try2 c: 996263a h: refs/heads/master v: v3
1 parent 49cc6fc commit becf32e

File tree

5 files changed

+170
-9
lines changed

5 files changed

+170
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c5edc70fadd136c0e0b1fe402fbb3170e94458aa
8+
refs/heads/try2: 996263a01589c5d2bd2a5ad559abac267296ad71
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/str.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@ impl<'a> Iterator<char> for Decompositions<'a> {
352352
/// # Return value
353353
///
354354
/// The original string with all occurrences of `from` replaced with `to`
355+
///
356+
/// # Example
357+
///
358+
/// ```rust
359+
/// use std::str;
360+
/// let string = "orange";
361+
/// let new_string = str::replace(string, "or", "str");
362+
/// assert_eq!(new_string.as_slice(), "strange");
363+
/// ```
355364
pub fn replace(s: &str, from: &str, to: &str) -> String {
356365
let mut result = String::new();
357366
let mut last_end = 0;
@@ -573,6 +582,14 @@ pub type SendStr = MaybeOwned<'static>;
573582

574583
impl<'a> MaybeOwned<'a> {
575584
/// Returns `true` if this `MaybeOwned` wraps an owned string
585+
///
586+
/// # Example
587+
///
588+
/// ```rust
589+
/// let string = String::from_str("orange");
590+
/// let maybe_owned_string = string.into_maybe_owned();
591+
/// assert_eq!(true, maybe_owned_string.is_owned());
592+
/// ```
576593
#[inline]
577594
pub fn is_owned(&self) -> bool {
578595
match *self {
@@ -582,6 +599,14 @@ impl<'a> MaybeOwned<'a> {
582599
}
583600

584601
/// Returns `true` if this `MaybeOwned` wraps a borrowed string
602+
///
603+
/// # Example
604+
///
605+
/// ```rust
606+
/// let string = "orange";
607+
/// let maybe_owned_string = string.as_slice().into_maybe_owned();
608+
/// assert_eq!(true, maybe_owned_string.is_slice());
609+
/// ```
585610
#[inline]
586611
pub fn is_slice(&self) -> bool {
587612
match *self {
@@ -597,18 +622,40 @@ pub trait IntoMaybeOwned<'a> {
597622
fn into_maybe_owned(self) -> MaybeOwned<'a>;
598623
}
599624

625+
/// # Example
626+
///
627+
/// ```rust
628+
/// let owned_string = String::from_str("orange");
629+
/// let maybe_owned_string = owned_string.into_maybe_owned();
630+
/// assert_eq!(true, maybe_owned_string.is_owned());
631+
/// ```
600632
impl<'a> IntoMaybeOwned<'a> for String {
601633
#[inline]
602634
fn into_maybe_owned(self) -> MaybeOwned<'a> {
603635
Owned(self)
604636
}
605637
}
606638

639+
/// # Example
640+
///
641+
/// ```rust
642+
/// let string = "orange";
643+
/// let maybe_owned_str = string.as_slice().into_maybe_owned();
644+
/// assert_eq!(false, maybe_owned_str.is_owned());
645+
/// ```
607646
impl<'a> IntoMaybeOwned<'a> for &'a str {
608647
#[inline]
609648
fn into_maybe_owned(self) -> MaybeOwned<'a> { Slice(self) }
610649
}
611650

651+
/// # Example
652+
///
653+
/// ```rust
654+
/// let str = "orange";
655+
/// let maybe_owned_str = str.as_slice().into_maybe_owned();
656+
/// let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
657+
/// assert_eq!(false, maybe_maybe_owned_str.is_owned());
658+
/// ```
612659
impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> {
613660
#[inline]
614661
fn into_maybe_owned(self) -> MaybeOwned<'a> { self }

branches/try2/src/libnative/io/process.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,25 @@ fn spawn_process_os(cfg: ProcessConfig,
305305
})
306306
}
307307

308+
// To have the spawning semantics of unix/windows stay the same, we need to
309+
// read the *child's* PATH if one is provided. See #15149 for more details.
310+
let program = cfg.env.and_then(|env| {
311+
for &(ref key, ref v) in env.iter() {
312+
if b"PATH" != key.as_bytes_no_nul() { continue }
313+
314+
// Split the value and test each path to see if the program exists.
315+
for path in os::split_paths(v.as_bytes_no_nul()).move_iter() {
316+
let path = path.join(cfg.program.as_bytes_no_nul())
317+
.with_extension(os::consts::EXE_EXTENSION);
318+
if path.exists() {
319+
return Some(path.to_c_str())
320+
}
321+
}
322+
break
323+
}
324+
None
325+
});
326+
308327
unsafe {
309328
let mut si = zeroed_startupinfo();
310329
si.cb = mem::size_of::<STARTUPINFO>() as DWORD;
@@ -362,7 +381,8 @@ fn spawn_process_os(cfg: ProcessConfig,
362381
try!(set_fd(&out_fd, &mut si.hStdOutput, false));
363382
try!(set_fd(&err_fd, &mut si.hStdError, false));
364383

365-
let cmd_str = make_command_line(cfg.program, cfg.args);
384+
let cmd_str = make_command_line(program.as_ref().unwrap_or(cfg.program),
385+
cfg.args);
366386
let mut pi = zeroed_process_information();
367387
let mut create_err = None;
368388

branches/try2/src/libstd/os.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,24 @@ pub fn tmpdir() -> Path {
837837
}
838838
}
839839

840-
/**
841-
* Convert a relative path to an absolute path
842-
*
843-
* If the given path is relative, return it prepended with the current working
844-
* directory. If the given path is already an absolute path, return it
845-
* as is.
846-
*/
840+
///
841+
/// Convert a relative path to an absolute path
842+
///
843+
/// If the given path is relative, return it prepended with the current working
844+
/// directory. If the given path is already an absolute path, return it
845+
/// as is.
846+
///
847+
/// # Example
848+
/// ```rust
849+
/// use std::os;
850+
/// use std::path::Path;
851+
///
852+
/// // Assume we're in a path like /home/someuser
853+
/// let rel_path = Path::new("..");
854+
/// let abs_path = os::make_absolute(&rel_path);
855+
/// println!("The absolute path is {}", abs_path.display());
856+
/// // Prints "The absolute path is /home"
857+
/// ```
847858
// NB: this is here rather than in path because it is a form of environment
848859
// querying; what it does depends on the process working directory, not just
849860
// the input paths.
@@ -859,6 +870,16 @@ pub fn make_absolute(p: &Path) -> Path {
859870

860871
/// Changes the current working directory to the specified path, returning
861872
/// whether the change was completed successfully or not.
873+
///
874+
/// # Example
875+
/// ```rust
876+
/// use std::os;
877+
/// use std::path::Path;
878+
///
879+
/// let root = Path::new("/");
880+
/// assert!(os::change_dir(&root));
881+
/// println!("Succesfully changed working directory to {}!", root.display());
882+
/// ```
862883
pub fn change_dir(p: &Path) -> bool {
863884
return chdir(p);
864885

@@ -930,6 +951,13 @@ pub fn errno() -> uint {
930951
}
931952

932953
/// Return the string corresponding to an `errno()` value of `errnum`.
954+
/// # Example
955+
/// ```rust
956+
/// use std::os;
957+
///
958+
/// // Same as println!("{}", last_os_error());
959+
/// println!("{}", os::error_string(os::errno() as uint));
960+
/// ```
933961
pub fn error_string(errnum: uint) -> String {
934962
return strerror(errnum);
935963

@@ -1217,6 +1245,16 @@ extern "system" {
12171245
///
12181246
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
12191247
/// See `str::from_utf8_lossy` for details.
1248+
/// # Example
1249+
///
1250+
/// ```rust
1251+
/// use std::os;
1252+
///
1253+
/// // Prints each argument on a separate line
1254+
/// for argument in os::args().iter() {
1255+
/// println!("{}", argument);
1256+
/// }
1257+
/// ```
12201258
pub fn args() -> Vec<String> {
12211259
real_args()
12221260
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2014 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+
#![feature(phase)]
12+
extern crate native;
13+
#[phase(plugin)]
14+
extern crate green;
15+
16+
use native::NativeTaskBuilder;
17+
use std::io::{TempDir, Command, fs};
18+
use std::os;
19+
use std::task::TaskBuilder;
20+
21+
// FIXME(#15149) libgreen still needs to be update. There is an open PR for it
22+
// but it is not yet merged.
23+
// green_start!(main)
24+
25+
fn main() {
26+
// If we're the child, make sure we were invoked correctly
27+
let args = os::args();
28+
if args.len() > 1 && args.get(1).as_slice() == "child" {
29+
return assert_eq!(args.get(0).as_slice(), "mytest");
30+
}
31+
32+
test();
33+
let (tx, rx) = channel();
34+
TaskBuilder::new().native().spawn(proc() {
35+
tx.send(test());
36+
});
37+
rx.recv();
38+
}
39+
40+
fn test() {
41+
// If we're the parent, copy our own binary to a tempr directory, and then
42+
// make it executable.
43+
let dir = TempDir::new("mytest").unwrap();
44+
let me = os::self_exe_name().unwrap();
45+
let dest = dir.path().join(format!("mytest{}", os::consts::EXE_SUFFIX));
46+
fs::copy(&me, &dest).unwrap();
47+
48+
// Append the temp directory to our own PATH.
49+
let mut path = os::split_paths(os::getenv("PATH").unwrap_or(String::new()));
50+
path.push(dir.path().clone());
51+
let path = os::join_paths(path.as_slice()).unwrap();
52+
53+
Command::new("mytest").env("PATH", path.as_slice())
54+
.arg("child")
55+
.spawn().unwrap();
56+
}

0 commit comments

Comments
 (0)