@@ -45,7 +45,7 @@ pub struct Command {
45
45
// other keys.
46
46
program : CString ,
47
47
args : Vec < CString > ,
48
- argv : Vec < * const c_char > ,
48
+ argv : Argv ,
49
49
env : CommandEnv < DefaultEnvKey > ,
50
50
51
51
cwd : Option < CString > ,
@@ -58,6 +58,12 @@ pub struct Command {
58
58
stderr : Option < Stdio > ,
59
59
}
60
60
61
+ // Create a new type for argv, so that we can make it `Send`
62
+ struct Argv ( Vec < * const c_char > ) ;
63
+
64
+ // It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args`
65
+ unsafe impl Send for Argv { }
66
+
61
67
// passed back to std::process with the pipes connected to the child, if any
62
68
// were requested
63
69
pub struct StdioPipes {
@@ -87,17 +93,12 @@ pub enum Stdio {
87
93
Fd ( FileDesc ) ,
88
94
}
89
95
90
- // Command is not Send by default due to the Command.argv field containing a raw pointers. However
91
- // it is safe to implement Send, because anyway, these pointers point to memory owned by the
92
- // Command.args field.
93
- unsafe impl Send for Command { }
94
-
95
96
impl Command {
96
97
pub fn new ( program : & OsStr ) -> Command {
97
98
let mut saw_nul = false ;
98
99
let program = os2c ( program, & mut saw_nul) ;
99
100
Command {
100
- argv : vec ! [ program. as_ptr( ) , ptr:: null( ) ] ,
101
+ argv : Argv ( vec ! [ program. as_ptr( ) , ptr:: null( ) ] ) ,
101
102
program,
102
103
args : Vec :: new ( ) ,
103
104
env : Default :: default ( ) ,
@@ -116,8 +117,8 @@ impl Command {
116
117
// Overwrite the trailing NULL pointer in `argv` and then add a new null
117
118
// pointer.
118
119
let arg = os2c ( arg, & mut self . saw_nul ) ;
119
- self . argv [ self . args . len ( ) + 1 ] = arg. as_ptr ( ) ;
120
- self . argv . push ( ptr:: null ( ) ) ;
120
+ self . argv . 0 [ self . args . len ( ) + 1 ] = arg. as_ptr ( ) ;
121
+ self . argv . 0 . push ( ptr:: null ( ) ) ;
121
122
122
123
// Also make sure we keep track of the owned value to schedule a
123
124
// destructor for this memory.
@@ -138,7 +139,7 @@ impl Command {
138
139
self . saw_nul
139
140
}
140
141
pub fn get_argv ( & self ) -> & Vec < * const c_char > {
141
- & self . argv
142
+ & self . argv . 0
142
143
}
143
144
144
145
#[ allow( dead_code) ]
0 commit comments