48
48
import java .nio .channels .WritableByteChannel ;
49
49
import java .util .ArrayList ;
50
50
import java .util .List ;
51
+ import java .util .Map ;
51
52
52
53
import com .oracle .graal .python .builtins .Builtin ;
53
54
import com .oracle .graal .python .builtins .CoreFunctions ;
54
55
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
55
56
import com .oracle .graal .python .builtins .PythonBuiltins ;
56
57
import com .oracle .graal .python .builtins .objects .PNone ;
58
+ import com .oracle .graal .python .builtins .objects .bytes .BytesNodes ;
59
+ import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
57
60
import com .oracle .graal .python .builtins .objects .list .PList ;
58
61
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
59
62
import com .oracle .graal .python .builtins .objects .str .PString ;
@@ -80,11 +83,25 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
80
83
"errpipe_read" , "errpipe_write" , "restore_signals" , "call_setsid" , "preexec_fn" })
81
84
@ GenerateNodeFactory
82
85
abstract static class ForkExecNode extends PythonBuiltinNode {
86
+ @ Child BytesNodes .ToBytesNode toBytes = BytesNodes .ToBytesNode .create ();
87
+
88
+ @ Specialization
89
+ synchronized int forkExecNoEnv (PList args , PTuple executable_list , boolean close_fds ,
90
+ PTuple fdsToKeep , PNone cwd , @ SuppressWarnings ("unused" ) PNone env ,
91
+ int p2cread , int p2cwrite , int c2pread , int c2pwrite ,
92
+ int errread , int errwrite , int errpipe_read , int errpipe_write ,
93
+ boolean restore_signals , boolean call_setsid , PNone preexec_fn ) {
94
+ return forkExec (args , executable_list , close_fds , fdsToKeep , cwd , factory ().createList (),
95
+ p2cread , p2cwrite , c2pread , c2pwrite ,
96
+ errread , errwrite , errpipe_read , errpipe_write ,
97
+ restore_signals , call_setsid , preexec_fn );
98
+ }
99
+
83
100
@ SuppressWarnings ("unused" )
84
101
@ TruffleBoundary
85
102
@ Specialization
86
103
synchronized int forkExec (PList args , PTuple executable_list , boolean close_fds ,
87
- PTuple fdsToKeep , PNone cwd , PNone env ,
104
+ PTuple fdsToKeep , PNone cwd , PList env ,
88
105
int p2cread , int p2cwrite , int c2pread , int c2pwrite ,
89
106
int errread , int errwrite , int errpipe_read , int errpipe_write ,
90
107
boolean restore_signals , boolean call_setsid , PNone preexec_fn ) {
@@ -142,6 +159,16 @@ synchronized int forkExec(PList args, PTuple executable_list, boolean close_fds,
142
159
pb .redirectError (Redirect .INHERIT );
143
160
}
144
161
162
+ Map <String , String > environment = pb .environment ();
163
+ for (Object keyValue : env .getSequenceStorage ().getInternalArray ()) {
164
+ if (keyValue instanceof PBytes ) {
165
+ String [] string = new String (toBytes .execute (keyValue )).split ("=" , 2 );
166
+ if (string .length == 2 ) {
167
+ environment .put (string [0 ], string [1 ]);
168
+ }
169
+ }
170
+ }
171
+
145
172
try {
146
173
Process process = pb .start ();
147
174
if (p2cwrite != -1 ) {
0 commit comments