Skip to content

Commit

Permalink
Replace some uses of deprecated os functions
Browse files Browse the repository at this point in the history
This commit mostly replaces some of the uses of os::args with env::args.
  • Loading branch information
nagisa committed Feb 16, 2015
1 parent 839311c commit 7d941fa
Show file tree
Hide file tree
Showing 52 changed files with 223 additions and 255 deletions.
13 changes: 7 additions & 6 deletions src/rustbook/build.rs
Expand Up @@ -11,6 +11,7 @@
//! Implementation of the `build` subcommand, used to compile a book.

use std::os;
use std::env;
use std::old_io;
use std::old_io::{fs, File, BufferedWriter, TempDir, IoResult};

Expand Down Expand Up @@ -80,10 +81,10 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
let out_path = tgt.join(item.path.dirname());

let src;
if os::args().len() < 3 {
if env::args().len() < 3 {
src = os::getcwd().unwrap().clone();
} else {
src = Path::new(os::args()[2].clone());
src = Path::new(env::args().nth(2).unwrap().clone());
}
// preprocess the markdown, rerouting markdown references to html references
let markdown_data = try!(File::open(&src.join(&item.path)).read_to_string());
Expand Down Expand Up @@ -153,16 +154,16 @@ impl Subcommand for Build {
let src;
let tgt;

if os::args().len() < 3 {
if env::args().len() < 3 {
src = cwd.clone();
} else {
src = Path::new(os::args()[2].clone());
src = Path::new(env::args().nth(2).unwrap().clone());
}

if os::args().len() < 4 {
if env::args().len() < 4 {
tgt = cwd.join("_book");
} else {
tgt = Path::new(os::args()[3].clone());
tgt = Path::new(env::args().nth(3).unwrap().clone());
}

try!(fs::mkdir(&tgt, old_io::USER_DIR));
Expand Down
5 changes: 3 additions & 2 deletions src/rustbook/main.rs
Expand Up @@ -13,12 +13,13 @@
#![feature(core)]
#![feature(io)]
#![feature(os)]
#![feature(env)]
#![feature(path)]
#![feature(rustdoc)]

extern crate rustdoc;

use std::os;
use std::env;
use subcommand::Subcommand;
use term::Term;

Expand Down Expand Up @@ -48,7 +49,7 @@ mod javascript;
#[cfg(not(test))] // thanks #12327
fn main() {
let mut term = Term::new();
let cmd = os::args();
let cmd: Vec<_> = env::args().collect();

if cmd.len() < 1 {
help::usage()
Expand Down
4 changes: 2 additions & 2 deletions src/rustbook/term.rs
Expand Up @@ -11,7 +11,7 @@
//! An abstraction of the terminal. Eventually, provide color and
//! verbosity support. For now, just a wrapper around stdout/stderr.

use std::os;
use std::env;
use std::old_io::stdio;

pub struct Term {
Expand All @@ -28,6 +28,6 @@ impl Term {
pub fn err(&mut self, msg: &str) {
// swallow any errors
let _ = self.err.write_line(msg);
os::set_exit_status(101);
env::set_exit_status(101);
}
}
57 changes: 28 additions & 29 deletions src/test/bench/core-map.rs
Expand Up @@ -11,7 +11,7 @@
#![feature(unboxed_closures)]

use std::collections::{BTreeMap, HashMap, HashSet};
use std::os;
use std::env;
use std::rand::{Rng, IsaacRng, SeedableRng};
use std::time::Duration;

Expand All @@ -20,33 +20,33 @@ fn timed<F>(label: &str, f: F) where F: FnMut() {
}

trait MutableMap {
fn insert(&mut self, k: uint, v: uint);
fn remove(&mut self, k: &uint) -> bool;
fn find(&self, k: &uint) -> Option<&uint>;
fn insert(&mut self, k: usize, v: usize);
fn remove(&mut self, k: &usize) -> bool;
fn find(&self, k: &usize) -> Option<&usize>;
}

impl MutableMap for BTreeMap<uint, uint> {
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
impl MutableMap for BTreeMap<usize, usize> {
fn insert(&mut self, k: usize, v: usize) { self.insert(k, v); }
fn remove(&mut self, k: &usize) -> bool { self.remove(k).is_some() }
fn find(&self, k: &usize) -> Option<&usize> { self.get(k) }
}
impl MutableMap for HashMap<uint, uint> {
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
impl MutableMap for HashMap<usize, usize> {
fn insert(&mut self, k: usize, v: usize) { self.insert(k, v); }
fn remove(&mut self, k: &usize) -> bool { self.remove(k).is_some() }
fn find(&self, k: &usize) -> Option<&usize> { self.get(k) }
}

fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
fn ascending<M: MutableMap>(map: &mut M, n_keys: usize) {
println!(" Ascending integers:");

timed("insert", || {
for i in 0u..n_keys {
for i in 0..n_keys {
map.insert(i, i + 1);
}
});

timed("search", || {
for i in 0u..n_keys {
for i in 0..n_keys {
assert_eq!(map.find(&i).unwrap(), &(i + 1));
}
});
Expand All @@ -58,7 +58,7 @@ fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
});
}

fn descending<M: MutableMap>(map: &mut M, n_keys: uint) {
fn descending<M: MutableMap>(map: &mut M, n_keys: usize) {
println!(" Descending integers:");

timed("insert", || {
Expand All @@ -80,32 +80,31 @@ fn descending<M: MutableMap>(map: &mut M, n_keys: uint) {
});
}

fn vector<M: MutableMap>(map: &mut M, n_keys: uint, dist: &[uint]) {
fn vector<M: MutableMap>(map: &mut M, n_keys: usize, dist: &[usize]) {
timed("insert", || {
for i in 0u..n_keys {
for i in 0..n_keys {
map.insert(dist[i], i + 1);
}
});

timed("search", || {
for i in 0u..n_keys {
for i in 0..n_keys {
assert_eq!(map.find(&dist[i]).unwrap(), &(i + 1));
}
});

timed("remove", || {
for i in 0u..n_keys {
for i in 0..n_keys {
assert!(map.remove(&dist[i]));
}
});
}

fn main() {
let args = os::args();
let args = args;
let mut args = env::args();
let n_keys = {
if args.len() == 2 {
args[1].parse::<uint>().unwrap()
args.nth(1).unwrap().parse::<usize>().unwrap()
} else {
1000000
}
Expand All @@ -131,37 +130,37 @@ fn main() {
println!("{}", "\nBTreeMap:");

{
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
ascending(&mut map, n_keys);
}

{
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
descending(&mut map, n_keys);
}

{
println!(" Random integers:");
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
vector(&mut map, n_keys, &rand);
}

// FIXME: #9970
println!("{}", "\nHashMap:");

{
let mut map: HashMap<uint,uint> = HashMap::new();
let mut map: HashMap<usize,usize> = HashMap::new();
ascending(&mut map, n_keys);
}

{
let mut map: HashMap<uint,uint> = HashMap::new();
let mut map: HashMap<usize,usize> = HashMap::new();
descending(&mut map, n_keys);
}

{
println!(" Random integers:");
let mut map: HashMap<uint,uint> = HashMap::new();
let mut map: HashMap<usize,usize> = HashMap::new();
vector(&mut map, n_keys, &rand);
}
}
47 changes: 23 additions & 24 deletions src/test/bench/core-set.rs
Expand Up @@ -20,7 +20,7 @@ use std::collections::BitvSet;
use std::collections::HashSet;
use std::collections::hash_map::Hasher;
use std::hash::Hash;
use std::os;
use std::env;
use std::time::Duration;

struct Results {
Expand Down Expand Up @@ -53,29 +53,29 @@ impl<T: Ord> MutableSet<T> for BTreeSet<T> {
fn remove(&mut self, k: &T) -> bool { self.remove(k) }
fn contains(&self, k: &T) -> bool { self.contains(k) }
}
impl MutableSet<uint> for BitvSet {
fn insert(&mut self, k: uint) { self.insert(k); }
fn remove(&mut self, k: &uint) -> bool { self.remove(k) }
fn contains(&self, k: &uint) -> bool { self.contains(k) }
impl MutableSet<usize> for BitvSet {
fn insert(&mut self, k: usize) { self.insert(k); }
fn remove(&mut self, k: &usize) -> bool { self.remove(k) }
fn contains(&self, k: &usize) -> bool { self.contains(k) }
}

impl Results {
pub fn bench_int<T:MutableSet<uint>,
pub fn bench_int<T:MutableSet<usize>,
R:rand::Rng,
F:FnMut() -> T>(
&mut self,
rng: &mut R,
num_keys: uint,
rand_cap: uint,
num_keys: usize,
rand_cap: usize,
mut f: F) {
{
let mut set = f();
timed(&mut self.sequential_ints, || {
for i in 0u..num_keys {
for i in 0..num_keys {
set.insert(i);
}

for i in 0u..num_keys {
for i in 0..num_keys {
assert!(set.contains(&i));
}
})
Expand All @@ -85,19 +85,19 @@ impl Results {
let mut set = f();
timed(&mut self.random_ints, || {
for _ in 0..num_keys {
set.insert(rng.gen::<uint>() % rand_cap);
set.insert(rng.gen::<usize>() % rand_cap);
}
})
}

{
let mut set = f();
for i in 0u..num_keys {
for i in 0..num_keys {
set.insert(i);
}

timed(&mut self.delete_ints, || {
for i in 0u..num_keys {
for i in 0..num_keys {
assert!(set.remove(&i));
}
})
Expand All @@ -109,16 +109,16 @@ impl Results {
F:FnMut() -> T>(
&mut self,
rng: &mut R,
num_keys: uint,
num_keys: usize,
mut f: F) {
{
let mut set = f();
timed(&mut self.sequential_strings, || {
for i in 0u..num_keys {
for i in 0..num_keys {
set.insert(i.to_string());
}

for i in 0u..num_keys {
for i in 0..num_keys {
assert!(set.contains(&i.to_string()));
}
})
Expand All @@ -128,19 +128,19 @@ impl Results {
let mut set = f();
timed(&mut self.random_strings, || {
for _ in 0..num_keys {
let s = rng.gen::<uint>().to_string();
let s = rng.gen::<usize>().to_string();
set.insert(s);
}
})
}

{
let mut set = f();
for i in 0u..num_keys {
for i in 0..num_keys {
set.insert(i.to_string());
}
timed(&mut self.delete_strings, || {
for i in 0u..num_keys {
for i in 0..num_keys {
assert!(set.remove(&i.to_string()));
}
})
Expand Down Expand Up @@ -179,11 +179,10 @@ fn empty_results() -> Results {
}

fn main() {
let args = os::args();
let args = args;
let mut args = env::args();
let num_keys = {
if args.len() == 2 {
args[1].parse::<uint>().unwrap()
args.nth(1).unwrap().parse::<usize>().unwrap()
} else {
100 // woefully inadequate for any real measurement
}
Expand All @@ -196,7 +195,7 @@ fn main() {
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
let mut results = empty_results();
results.bench_int(&mut rng, num_keys, max, || {
let s: HashSet<uint> = HashSet::new();
let s: HashSet<usize> = HashSet::new();
s
});
results.bench_str(&mut rng, num_keys, || {
Expand All @@ -210,7 +209,7 @@ fn main() {
let mut rng: rand::IsaacRng = rand::SeedableRng::from_seed(seed);
let mut results = empty_results();
results.bench_int(&mut rng, num_keys, max, || {
let s: BTreeSet<uint> = BTreeSet::new();
let s: BTreeSet<usize> = BTreeSet::new();
s
});
results.bench_str(&mut rng, num_keys, || {
Expand Down
4 changes: 1 addition & 3 deletions src/test/bench/core-std.rs
Expand Up @@ -16,7 +16,6 @@
use std::old_io::File;
use std::iter::repeat;
use std::mem::swap;
use std::os;
use std::env;
use std::rand::Rng;
use std::rand;
Expand All @@ -25,8 +24,7 @@ use std::time::Duration;
use std::vec;

fn main() {
let argv = os::args();
let _tests = &argv[1..argv.len()];
let argv: Vec<String> = env::args().collect();

macro_rules! bench {
($id:ident) =>
Expand Down

0 comments on commit 7d941fa

Please sign in to comment.