Allow args to work without rt initialization
This commit is contained in:
@@ -702,11 +702,7 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> {
|
|||||||
target_os = "dragonfly"))]
|
target_os = "dragonfly"))]
|
||||||
fn real_args_as_bytes() -> Vec<Vec<u8>> {
|
fn real_args_as_bytes() -> Vec<Vec<u8>> {
|
||||||
use rt;
|
use rt;
|
||||||
|
rt::args::clone().unwrap_or_else(|| vec![])
|
||||||
match rt::args::clone() {
|
|
||||||
Some(args) => args,
|
|
||||||
None => panic!("process arguments not initialized")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
|||||||
@@ -62,37 +62,33 @@ mod imp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn cleanup() {
|
pub unsafe fn cleanup() {
|
||||||
rtassert!(take().is_some());
|
take();
|
||||||
LOCK.destroy();
|
LOCK.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take() -> Option<Vec<Vec<u8>>> {
|
pub fn take() -> Option<Vec<Vec<u8>>> {
|
||||||
with_lock(|| unsafe {
|
let guard = LOCK.lock();
|
||||||
|
unsafe {
|
||||||
let ptr = get_global_ptr();
|
let ptr = get_global_ptr();
|
||||||
let val = mem::replace(&mut *ptr, None);
|
let val = mem::replace(&mut *ptr, None);
|
||||||
val.as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone())
|
val.as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone())
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put(args: Vec<Vec<u8>>) {
|
pub fn put(args: Vec<Vec<u8>>) {
|
||||||
with_lock(|| unsafe {
|
let guard = LOCK.lock();
|
||||||
|
unsafe {
|
||||||
let ptr = get_global_ptr();
|
let ptr = get_global_ptr();
|
||||||
rtassert!((*ptr).is_none());
|
rtassert!((*ptr).is_none());
|
||||||
(*ptr) = Some(box args.clone());
|
(*ptr) = Some(box args.clone());
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone() -> Option<Vec<Vec<u8>>> {
|
pub fn clone() -> Option<Vec<Vec<u8>>> {
|
||||||
with_lock(|| unsafe {
|
let guard = LOCK.lock();
|
||||||
|
unsafe {
|
||||||
let ptr = get_global_ptr();
|
let ptr = get_global_ptr();
|
||||||
(*ptr).as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone())
|
(*ptr).as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone())
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn with_lock<T, F>(f: F) -> T where F: FnOnce() -> T {
|
|
||||||
unsafe {
|
|
||||||
let _guard = LOCK.lock();
|
|
||||||
f()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user