5
5
6
6
#![ allow( dead_code) ] // runtime init functions not used during testing
7
7
8
- use crate :: ffi:: { CStr , OsString } ;
8
+ use crate :: ffi:: CStr ;
9
9
use crate :: os:: unix:: ffi:: OsStringExt ;
10
- use crate :: { fmt, vec} ;
10
+
11
+ #[ path = "common.rs" ]
12
+ mod common;
13
+ pub use common:: Args ;
11
14
12
15
/// One-time global initialization.
13
16
pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
14
- imp:: init ( argc, argv)
17
+ unsafe { imp:: init ( argc, argv) }
15
18
}
16
19
17
20
/// Returns the command line arguments
@@ -55,42 +58,7 @@ pub fn args() -> Args {
55
58
vec. push ( OsStringExt :: from_vec ( cstr. to_bytes ( ) . to_vec ( ) ) ) ;
56
59
}
57
60
58
- Args { iter : vec. into_iter ( ) }
59
- }
60
-
61
- pub struct Args {
62
- iter : vec:: IntoIter < OsString > ,
63
- }
64
-
65
- impl !Send for Args { }
66
- impl !Sync for Args { }
67
-
68
- impl fmt:: Debug for Args {
69
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
70
- self . iter . as_slice ( ) . fmt ( f)
71
- }
72
- }
73
-
74
- impl Iterator for Args {
75
- type Item = OsString ;
76
- fn next ( & mut self ) -> Option < OsString > {
77
- self . iter . next ( )
78
- }
79
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
80
- self . iter . size_hint ( )
81
- }
82
- }
83
-
84
- impl ExactSizeIterator for Args {
85
- fn len ( & self ) -> usize {
86
- self . iter . len ( )
87
- }
88
- }
89
-
90
- impl DoubleEndedIterator for Args {
91
- fn next_back ( & mut self ) -> Option < OsString > {
92
- self . iter . next_back ( )
93
- }
61
+ Args :: new ( vec)
94
62
}
95
63
96
64
#[ cfg( any(
@@ -141,7 +109,7 @@ mod imp {
141
109
pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
142
110
// on GNU/Linux if we are main then we will init argv and argc twice, it "duplicates work"
143
111
// BUT edge-cases are real: only using .init_array can break most emulators, dlopen, etc.
144
- really_init ( argc, argv) ;
112
+ unsafe { really_init ( argc, argv) } ;
145
113
}
146
114
147
115
/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.
@@ -159,9 +127,7 @@ mod imp {
159
127
argv : * const * const u8 ,
160
128
_envp : * const * const u8 ,
161
129
) {
162
- unsafe {
163
- really_init ( argc as isize , argv) ;
164
- }
130
+ unsafe { really_init ( argc as isize , argv) } ;
165
131
}
166
132
init_wrapper
167
133
} ;
@@ -228,16 +194,3 @@ mod imp {
228
194
( argc as isize , argv. cast ( ) )
229
195
}
230
196
}
231
-
232
- #[ cfg( any( target_os = "espidf" , target_os = "vita" ) ) ]
233
- mod imp {
234
- use crate :: ffi:: c_char;
235
- use crate :: ptr;
236
-
237
- #[ inline( always) ]
238
- pub unsafe fn init ( _argc : isize , _argv : * const * const u8 ) { }
239
-
240
- pub fn argc_argv ( ) -> ( isize , * const * const c_char ) {
241
- ( 0 , ptr:: null ( ) )
242
- }
243
- }
0 commit comments