Skip to content

Commit 8b16e6b

Browse files
committed
Merge branch 'master' into truffle-head
Conflicts: core/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
2 parents ddee507 + 40ba655 commit 8b16e6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+744
-702
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.jruby.compiler.Constantizable;
4343
import org.jruby.compiler.NotCompilableException;
4444
import org.jruby.ir.IRScriptBody;
45+
import org.jruby.parser.StaticScope;
4546
import org.objectweb.asm.util.TraceClassVisitor;
4647

4748
import jnr.constants.Constant;
@@ -3164,6 +3165,16 @@ public void tearDown(boolean systemExit) {
31643165
// clear out threadlocals so they don't leak
31653166
recursive = new ThreadLocal<Map<String, RubyHash>>();
31663167

3168+
ThreadContext context = getCurrentContext();
3169+
3170+
// FIXME: 73df3d230b9d92c7237d581c6366df1b92ad9b2b exposed no toplevel scope existing anymore (I think the
3171+
// bogus scope I removed was playing surrogate toplevel scope and wallpapering this bug). For now, add a
3172+
// bogus scope back for at_exit block run. This is buggy if at_exit is capturing vars.
3173+
if (!context.hasAnyScopes()) {
3174+
StaticScope topStaticScope = getStaticScopeFactory().newLocalScope(null);
3175+
context.pushScope(new ManyVarsDynamicScope(topStaticScope, null));
3176+
}
3177+
31673178
while (!atExitBlocks.empty()) {
31683179
RubyProc proc = atExitBlocks.pop();
31693180
try {

core/src/main/java/org/jruby/RubyFile.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.nio.file.Paths;
5454
import java.nio.file.attribute.FileTime;
5555
import java.nio.file.attribute.PosixFileAttributeView;
56+
import java.util.ArrayList;
5657
import java.util.Enumeration;
5758
import java.util.concurrent.TimeUnit;
5859
import java.util.jar.JarFile;
@@ -199,6 +200,7 @@ public static RubyClass createFileClass(Ruby runtime) {
199200
constants.setConstant("FNM_SYSCASE", runtime.newFixnum(FNM_SYSCASE));
200201
constants.setConstant("FNM_DOTMATCH", runtime.newFixnum(FNM_DOTMATCH));
201202
constants.setConstant("FNM_PATHNAME", runtime.newFixnum(FNM_PATHNAME));
203+
constants.setConstant("FNM_EXTGLOB", runtime.newFixnum(FNM_EXTGLOB));
202204

203205
// flock operations
204206
constants.setConstant("LOCK_SH", runtime.newFixnum(RubyFile.LOCK_SH));
@@ -765,7 +767,7 @@ public static IRubyObject expand_path(ThreadContext context, IRubyObject recv, I
765767

766768
@JRubyMethod(name = "expand_path", required = 1, optional = 1, meta = true)
767769
public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
768-
RubyString path = (RubyString) expandPathInternal(context, recv, args, true);
770+
RubyString path = (RubyString) expandPathInternal(context, recv, args, true, false);
769771
path.force_encoding(context, context.runtime.getEncodingService().getDefaultExternal());
770772

771773
return path;
@@ -793,25 +795,21 @@ public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv,
793795
*/
794796
@JRubyMethod(required = 1, optional = 1, meta = true)
795797
public static IRubyObject absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
796-
return expandPathInternal(context, recv, args, false);
798+
return expandPathInternal(context, recv, args, false, false);
797799
}
798800

799801
@JRubyMethod(required = 1, optional = 1, meta = true)
800802
public static IRubyObject realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
801-
return expandPathInternal(context, recv, args, false);
803+
return expandPathInternal(context, recv, args, false, false);
802804
}
803805

804806
@JRubyMethod(required = 1, optional = 1, meta = true)
805807
public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
806-
IRubyObject file = expandPathInternal(context, recv, args, false);
808+
IRubyObject file = expandPathInternal(context, recv, args, false, true);
807809
if (!RubyFileTest.exist_p(recv, file).isTrue()) {
808810
throw context.runtime.newErrnoENOENTError(file.toString());
809811
}
810-
try {
811-
return context.runtime.newString(new File(file.toString()).getCanonicalPath());
812-
} catch (IOException ioex) {
813-
throw context.runtime.newErrnoENOENTError(file.toString());
814-
}
812+
return file;
815813
}
816814

817815
/**
@@ -826,16 +824,41 @@ public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRub
826824
@JRubyMethod(name = {"fnmatch", "fnmatch?"}, required = 2, optional = 1, meta = true)
827825
public static IRubyObject fnmatch(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
828826
int flags = args.length == 3 ? RubyNumeric.num2int(args[2]) : 0;
827+
boolean braces_match = false;
828+
boolean extglob = (flags & FNM_EXTGLOB) != 0;
829829

830830
ByteList pattern = args[0].convertToString().getByteList();
831831
ByteList path = get_path(context, args[1]).getByteList();
832832

833-
if (org.jruby.util.Dir.fnmatch(pattern.getUnsafeBytes(), pattern.getBegin(), pattern.getBegin()+pattern.getRealSize(), path.getUnsafeBytes(), path.getBegin(), path.getBegin()+path.getRealSize(), flags) == 0) {
833+
if(extglob) {
834+
String spattern = args[0].asJavaString();
835+
ArrayList<String> patterns = org.jruby.util.Dir.braces(spattern, flags, new ArrayList<String>());
836+
837+
ArrayList<Boolean> matches = new ArrayList<Boolean>();
838+
for(int i = 0; i < patterns.size(); i++) {
839+
String p = patterns.get(i);
840+
boolean match = dir_fnmatch(new ByteList(p.getBytes()), path, flags);
841+
matches.add(match);
842+
}
843+
braces_match = matches.contains(true);
844+
}
845+
846+
if(braces_match || dir_fnmatch(pattern, path, flags)) {
834847
return context.runtime.getTrue();
835848
}
836849
return context.runtime.getFalse();
837850
}
838-
851+
852+
private static boolean dir_fnmatch(ByteList pattern, ByteList path, int flags) {
853+
return org.jruby.util.Dir.fnmatch(pattern.getUnsafeBytes(),
854+
pattern.getBegin(),
855+
pattern.getBegin()+pattern.getRealSize(),
856+
path.getUnsafeBytes(),
857+
path.getBegin(),
858+
path.getBegin()+path.getRealSize(),
859+
flags) == 0;
860+
}
861+
839862
@JRubyMethod(name = "ftype", required = 1, meta = true)
840863
public static IRubyObject ftype(ThreadContext context, IRubyObject recv, IRubyObject filename) {
841864
return context.runtime.newFileStat(get_path(context, filename).getUnicodeValue(), true).ftype();
@@ -1462,7 +1485,7 @@ private static boolean isWindowsDriveLetter(char c) {
14621485
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
14631486
}
14641487

1465-
private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser) {
1488+
private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser, boolean canonicalize) {
14661489
Ruby runtime = context.runtime;
14671490

14681491
String relativePath = get_path(context, args[0]).getUnicodeValue();
@@ -1493,6 +1516,9 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
14931516
relativePath = uriParts[1];
14941517
}
14951518

1519+
// Now that we're not treating it as a URI, we need to honor the canonicalize flag.
1520+
// Do not insert early returns below.
1521+
14961522
// If there's a second argument, it's the path to which the first
14971523
// argument is relative.
14981524
if (args.length == 2 && !args[1].isNil()) {
@@ -1582,7 +1608,17 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
15821608
path = JRubyFile.create(cwd, relativePath);
15831609
}
15841610

1585-
return runtime.newString(padSlashes + canonicalize(path.getAbsolutePath()));
1611+
String realPath = padSlashes + canonicalize(path.getAbsolutePath());
1612+
1613+
if (canonicalize) {
1614+
try {
1615+
realPath = new File(realPath).getCanonicalPath();
1616+
} catch (IOException ioe) {
1617+
// Earlier canonicalization will have to do.
1618+
}
1619+
}
1620+
1621+
return runtime.newString(realPath);
15861622
}
15871623

15881624
public static String[] splitURI(String path) {
@@ -1886,6 +1922,7 @@ public IRubyObject initialize19(IRubyObject[] args, Block block) {
18861922
private static final int FNM_PATHNAME = 2;
18871923
private static final int FNM_DOTMATCH = 4;
18881924
private static final int FNM_CASEFOLD = 8;
1925+
private static final int FNM_EXTGLOB = 16;
18891926
private static final int FNM_SYSCASE = Platform.IS_WINDOWS ? FNM_CASEFOLD : 0;
18901927

18911928
private static final String[] SLASHES = {"", "/", "//"};

core/src/main/java/org/jruby/RubyInstanceConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,8 @@ private static int initGlobalJavaVersion() {
17981798
} else if (specVersion.equals("1.7") || specVersion.equals("1.8")) {
17991799
return Opcodes.V1_7;
18001800
} else {
1801-
throw new RuntimeException("unsupported Java version: " + specVersion);
1801+
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
1802+
return Opcodes.V1_5;
18021803
}
18031804
}
18041805
public void setTruffleHooks(TruffleHooksStub truffleHooks) {

core/src/main/java/org/jruby/RubyMatchData.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,8 @@ public IRubyObject initialize_copy(IRubyObject original) {
593593

594594
checkFrozen();
595595

596-
Ruby runtime = getRuntime();
597-
ThreadContext context = runtime.getCurrentContext();
598596
if (!(original instanceof RubyMatchData)) {
599-
throw runtime.newTypeError("wrong argument class");
597+
throw getRuntime().newTypeError("wrong argument class");
600598
}
601599

602600
RubyMatchData origMatchData = (RubyMatchData)original;

0 commit comments

Comments
 (0)