@@ -69,57 +69,50 @@ impl DoubleEndedIterator for Args {
69
69
target_os = "fuchsia" ) ) ]
70
70
mod imp {
71
71
use os:: unix:: prelude:: * ;
72
- use mem ;
72
+ use ptr ;
73
73
use ffi:: { CStr , OsString } ;
74
74
use marker:: PhantomData ;
75
75
use libc;
76
76
use super :: Args ;
77
77
78
78
use sys_common:: mutex:: Mutex ;
79
79
80
- static mut GLOBAL_ARGS_PTR : usize = 0 ;
80
+ static mut ARGC : isize = 0 ;
81
+ static mut ARGV : * const * const u8 = ptr:: null ( ) ;
81
82
static LOCK : Mutex = Mutex :: new ( ) ;
82
83
83
84
pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
84
- let args = ( 0 ..argc) . map ( |i| {
85
- CStr :: from_ptr ( * argv. offset ( i) as * const libc:: c_char ) . to_bytes ( ) . to_vec ( )
86
- } ) . collect ( ) ;
87
-
88
85
LOCK . lock ( ) ;
89
- let ptr = get_global_ptr ( ) ;
90
- assert ! ( ( * ptr) . is_none( ) ) ;
91
- ( * ptr) = Some ( box args) ;
86
+ ARGC = argc;
87
+ ARGV = argv;
92
88
LOCK . unlock ( ) ;
93
89
}
94
90
95
91
pub unsafe fn cleanup ( ) {
96
92
LOCK . lock ( ) ;
97
- * get_global_ptr ( ) = None ;
93
+ ARGC = 0 ;
94
+ ARGV = ptr:: null ( ) ;
98
95
LOCK . unlock ( ) ;
99
96
}
100
97
101
98
pub fn args ( ) -> Args {
102
- let bytes = clone ( ) . unwrap_or ( Vec :: new ( ) ) ;
103
- let v: Vec < OsString > = bytes. into_iter ( ) . map ( |v| {
104
- OsStringExt :: from_vec ( v)
105
- } ) . collect ( ) ;
106
- Args { iter : v. into_iter ( ) , _dont_send_or_sync_me : PhantomData }
99
+ Args {
100
+ iter : clone ( ) . into_iter ( ) ,
101
+ _dont_send_or_sync_me : PhantomData
102
+ }
107
103
}
108
104
109
- fn clone ( ) -> Option < Vec < Vec < u8 > > > {
105
+ fn clone ( ) -> Vec < OsString > {
110
106
unsafe {
111
107
LOCK . lock ( ) ;
112
- let ptr = get_global_ptr ( ) ;
113
- let ret = ( * ptr) . as_ref ( ) . map ( |s| ( * * s) . clone ( ) ) ;
108
+ let ret = ( 0 ..ARGC ) . map ( |i| {
109
+ let cstr = CStr :: from_ptr ( * ARGV . offset ( i) as * const libc:: c_char ) ;
110
+ OsStringExt :: from_vec ( cstr. to_bytes ( ) . to_vec ( ) )
111
+ } ) . collect ( ) ;
114
112
LOCK . unlock ( ) ;
115
113
return ret
116
114
}
117
115
}
118
-
119
- fn get_global_ptr ( ) -> * mut Option < Box < Vec < Vec < u8 > > > > {
120
- unsafe { mem:: transmute ( & GLOBAL_ARGS_PTR ) }
121
- }
122
-
123
116
}
124
117
125
118
#[ cfg( any( target_os = "macos" ,
0 commit comments