Skip to content

Commit f26e25a

Browse files
committed
HACK: minimalist support for env in subprocess
1 parent dfe6086 commit f26e25a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@
4848
import java.nio.channels.WritableByteChannel;
4949
import java.util.ArrayList;
5050
import java.util.List;
51+
import java.util.Map;
5152

5253
import com.oracle.graal.python.builtins.Builtin;
5354
import com.oracle.graal.python.builtins.CoreFunctions;
5455
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5556
import com.oracle.graal.python.builtins.PythonBuiltins;
5657
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;
5760
import com.oracle.graal.python.builtins.objects.list.PList;
5861
import com.oracle.graal.python.builtins.objects.module.PythonModule;
5962
import com.oracle.graal.python.builtins.objects.str.PString;
@@ -80,11 +83,25 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
8083
"errpipe_read", "errpipe_write", "restore_signals", "call_setsid", "preexec_fn"})
8184
@GenerateNodeFactory
8285
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+
83100
@SuppressWarnings("unused")
84101
@TruffleBoundary
85102
@Specialization
86103
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,
88105
int p2cread, int p2cwrite, int c2pread, int c2pwrite,
89106
int errread, int errwrite, int errpipe_read, int errpipe_write,
90107
boolean restore_signals, boolean call_setsid, PNone preexec_fn) {
@@ -142,6 +159,16 @@ synchronized int forkExec(PList args, PTuple executable_list, boolean close_fds,
142159
pb.redirectError(Redirect.INHERIT);
143160
}
144161

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+
145172
try {
146173
Process process = pb.start();
147174
if (p2cwrite != -1) {

0 commit comments

Comments
 (0)