@@ -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 {
@@ -92,7 +98,7 @@ impl Command {
92
98
let mut saw_nul = false ;
93
99
let program = os2c ( program, & mut saw_nul) ;
94
100
Command {
95
- argv : vec ! [ program. as_ptr( ) , ptr:: null( ) ] ,
101
+ argv : Argv ( vec ! [ program. as_ptr( ) , ptr:: null( ) ] ) ,
96
102
program,
97
103
args : Vec :: new ( ) ,
98
104
env : Default :: default ( ) ,
@@ -111,8 +117,8 @@ impl Command {
111
117
// Overwrite the trailing NULL pointer in `argv` and then add a new null
112
118
// pointer.
113
119
let arg = os2c ( arg, & mut self . saw_nul ) ;
114
- self . argv [ self . args . len ( ) + 1 ] = arg. as_ptr ( ) ;
115
- self . argv . push ( ptr:: null ( ) ) ;
120
+ self . argv . 0 [ self . args . len ( ) + 1 ] = arg. as_ptr ( ) ;
121
+ self . argv . 0 . push ( ptr:: null ( ) ) ;
116
122
117
123
// Also make sure we keep track of the owned value to schedule a
118
124
// destructor for this memory.
@@ -133,7 +139,7 @@ impl Command {
133
139
self . saw_nul
134
140
}
135
141
pub fn get_argv ( & self ) -> & Vec < * const c_char > {
136
- & self . argv
142
+ & self . argv . 0
137
143
}
138
144
139
145
#[ allow( dead_code) ]
0 commit comments