Skip to content

Commit 18b2c4c

Browse files
committed
Removed obsolete isExecutableAccessAllowed checks, use ConcurrentHashMap for emulated environ, remove redundant PGuard method
1 parent ad5edeb commit 18b2c4c

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Object execvArgsTuple(VirtualFrame frame, PosixPath path, PTuple argv,
400400
throw CompilerDirectives.shouldNotReachHere("execv should not return normally");
401401
}
402402

403-
@Specialization(guards = {"!isList(argv)", "!isTuple(argv)"})
403+
@Specialization(guards = {"!isList(argv)", "!isPTuple(argv)"})
404404
@SuppressWarnings("unused")
405405
Object execvInvalidArgs(VirtualFrame frame, PosixPath path, Object argv) {
406406
throw raise(TypeError, ErrorMessages.ARG_D_MUST_BE_S, "execv()", 2, "tuple or list");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ public static boolean isList(Object o) {
233233
return o instanceof PList;
234234
}
235235

236-
public static boolean isTuple(Object o) {
237-
return o instanceof PTuple;
238-
}
239-
240236
public static boolean isObjectStorageIterator(PSequenceIterator iterator) {
241237
if (!iterator.isPSequence()) {
242238
return false;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import java.util.Locale;
9595
import java.util.Map;
9696
import java.util.Set;
97+
import java.util.concurrent.ConcurrentHashMap;
9798
import java.util.concurrent.TimeUnit;
9899
import java.util.logging.Level;
99100

@@ -243,7 +244,7 @@ public final class EmulatedPosixSupport extends PosixResources {
243244
private static final int S_IFREG = 0100000;
244245

245246
private final PythonContext context;
246-
private final Map<String, String> environ = new HashMap<>();
247+
private final ConcurrentHashMap<String, String> environ = new ConcurrentHashMap<>();
247248
private int currentUmask = 0022;
248249
private boolean hasDefaultUmask = true;
249250

@@ -1606,9 +1607,13 @@ public String ctermid() {
16061607

16071608
@ExportMessage
16081609
@TruffleBoundary
1609-
public synchronized void setenv(Object name, Object value, boolean overwrite) {
1610-
if (overwrite || !environ.containsKey(name)) {
1611-
environ.put((String) name, (String) value);
1610+
public void setenv(Object name, Object value, boolean overwrite) {
1611+
String nameStr = pathToJavaStr(name);
1612+
String valueStr = pathToJavaStr(value);
1613+
if (overwrite) {
1614+
environ.put(nameStr, valueStr);
1615+
} else {
1616+
environ.putIfAbsent(nameStr, valueStr);
16121617
}
16131618
}
16141619

@@ -1620,12 +1625,6 @@ public int forkExec(Object[] executables, Object[] args, Object cwd, Object[] en
16201625
// TODO there are a few arguments we ignore, we should throw an exception or report a
16211626
// compatibility warning
16221627

1623-
if (!context.isExecutableAccessAllowed()) {
1624-
// TODO is this check relevant to NFI backend as well?
1625-
// TODO raise an exception instead of returning an invalid pid
1626-
return -1;
1627-
}
1628-
16291628
// TODO do we need to do this check (and the isExecutable() check later)?
16301629
TruffleFile cwdFile = cwd == null ? context.getEnv().getCurrentWorkingDirectory() : getTruffleFile(pathToJavaStr(cwd));
16311630
if (!cwdFile.exists()) {
@@ -1782,9 +1781,6 @@ private void handleIOError(int errpipe_write, IOException e) {
17821781
@ExportMessage
17831782
public void execv(Object pathname, Object[] args) throws PosixException {
17841783
assert args.length > 0;
1785-
if (!context.isExecutableAccessAllowed()) {
1786-
throw posixException(OSErrorEnum.EPERM);
1787-
}
17881784
String[] cmd = new String[args.length];
17891785
// ProcessBuilder does not accept separate executable name, we must overwrite the 0-th
17901786
// argument
@@ -1834,9 +1830,6 @@ private void execvInternal(String[] cmd) throws IOException {
18341830
@TruffleBoundary
18351831
public int system(Object commandObj) {
18361832
String cmd = pathToJavaStr(commandObj);
1837-
if (!context.isExecutableAccessAllowed()) {
1838-
return -1;
1839-
}
18401833
LOGGER.fine(() -> "os.system: " + cmd);
18411834

18421835
String[] command;

0 commit comments

Comments
 (0)