Skip to content

Commit

Permalink
Simplify unix argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gmorenz committed Jun 12, 2016
1 parent 79a53cf commit 80d2956
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
#![feature(core_float)]
#![feature(core_intrinsics)]
#![feature(dropck_parametricity)]
#![feature(drop_types_in_const)]
#![feature(float_extras)]
#![feature(float_from_str_radix)]
#![feature(fnbox)]
Expand Down
18 changes: 5 additions & 13 deletions src/libstd/sys/common/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ mod imp {
use prelude::v1::*;

use libc::c_char;
use mem;
use ffi::CStr;

use sys_common::mutex::Mutex;

static mut GLOBAL_ARGS_PTR: usize = 0;
static mut GLOBAL_ARGS: Option<Vec<Vec<u8>>> = None;
static LOCK: Mutex = Mutex::new();

pub unsafe fn init(argc: isize, argv: *const *const u8) {
Expand All @@ -59,32 +58,25 @@ mod imp {
}).collect();

LOCK.lock();
let ptr = get_global_ptr();
assert!((*ptr).is_none());
(*ptr) = Some(box args);
assert!(GLOBAL_ARGS.is_none());
GLOBAL_ARGS = Some(args);
LOCK.unlock();
}

pub unsafe fn cleanup() {
LOCK.lock();
*get_global_ptr() = None;
GLOBAL_ARGS = None;
LOCK.unlock();
}

pub fn clone() -> Option<Vec<Vec<u8>>> {
unsafe {
LOCK.lock();
let ptr = get_global_ptr();
let ret = (*ptr).as_ref().map(|s| (**s).clone());
let ret = GLOBAL_ARGS.clone();
LOCK.unlock();
return ret
}
}

fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> {
unsafe { mem::transmute(&mut GLOBAL_ARGS_PTR) }
}

}

#[cfg(any(target_os = "macos",
Expand Down

0 comments on commit 80d2956

Please sign in to comment.