Skip to content

Commit

Permalink
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ public class PopenExecutor {
public static IRubyObject checkPipeCommand(ThreadContext context, IRubyObject filenameOrCommand) {
RubyString filenameStr = filenameOrCommand.convertToString();
ByteList filenameByteList = filenameStr.getByteList();
int[] chlen = {0};
final int[] chlen = {0};

if (EncodingUtils.encAscget(
filenameByteList.getUnsafeBytes(),
@@ -779,13 +779,11 @@ static int run_exec_dup2(Ruby runtime, RubyArray ary, ExecArg eargp, ExecArg sar
for (i = 0; i < n; i++) {
int newfd = pairs[i].newfd;
run_exec_dup2_fd_pair key = new run_exec_dup2_fd_pair();
int found;
key.oldfd = newfd;
found = Arrays.binarySearch(pairs, key, intcmp); /* hopefully async-signal-safe */
int found = Arrays.binarySearch(pairs, key, intcmp); /* hopefully async-signal-safe */
pairs[i].num_newer = 0;
if (found != -1) {
while (found > 0 && pairs[found-1].oldfd == newfd)
found--;
if (found >= 0) {
while (found > 0 && pairs[found-1].oldfd == newfd) found--;
while (found < n && pairs[found].oldfd == newfd) {
pairs[i].num_newer++;
pairs[found].older_index = i;
@@ -804,9 +802,8 @@ static int run_exec_dup2(Ruby runtime, RubyArray ary, ExecArg eargp, ExecArg sar
// This always succeeds because we just defer it to posix_spawn.
redirectDup2(eargp, pairs[j].oldfd, pairs[j].newfd); /* async-signal-safe */
pairs[j].oldfd = -1;
j = (int)pairs[j].older_index;
if (j != -1)
pairs[j].num_newer--;
j = (int) pairs[j].older_index;
if (j != -1) pairs[j].num_newer--;
}
}

@@ -1840,14 +1837,7 @@ else if (progByteList.get(p) == '/'){
if (!has_meta && first.getUnsafeBytes() != DUMMY_ARRAY) {
if (first.length() == 0) first.setRealSize(p - first.getBegin());
if (first.length() > 0 && first.length() <= posix_sh_cmds[0].length() &&
Arrays.binarySearch(posix_sh_cmds, first.toString(), new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
int ret = o1.compareTo(o2);
if (ret == 0 && o1.length() > o2.length()) return -1;
return ret;
}
}) != -1)
Arrays.binarySearch(posix_sh_cmds, first.toString(), StringComparator.INSTANCE) >= 0)
has_meta = true;
}
if (!has_meta && !eargp.chdir_given()) {
@@ -1912,6 +1902,18 @@ public int compare(String o1, String o2) {
}
}

private static final class StringComparator implements Comparator<String> {

static final StringComparator INSTANCE = new StringComparator();

public int compare(String o1, String o2) {
int ret = o1.compareTo(o2);
if (ret == 0 && o1.length() > o2.length()) return -1;
return ret;
}

}

private static String dlnFindExeR(Ruby runtime, String fname, String path) {
if (path != null) throw new RuntimeException("BUG: dln_find_exe_r with path is not supported yet");
// FIXME: need to reencode path as same

0 comments on commit 528dba7

Please sign in to comment.