Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
  • Loading branch information
chrisseaton committed Dec 19, 2014
2 parents ddee507 + 40ba655 commit 8b16e6b
Show file tree
Hide file tree
Showing 54 changed files with 744 additions and 702 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -42,6 +42,7 @@
import org.jruby.compiler.Constantizable;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ir.IRScriptBody;
import org.jruby.parser.StaticScope;
import org.objectweb.asm.util.TraceClassVisitor;

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

ThreadContext context = getCurrentContext();

// FIXME: 73df3d230b9d92c7237d581c6366df1b92ad9b2b exposed no toplevel scope existing anymore (I think the
// bogus scope I removed was playing surrogate toplevel scope and wallpapering this bug). For now, add a
// bogus scope back for at_exit block run. This is buggy if at_exit is capturing vars.
if (!context.hasAnyScopes()) {
StaticScope topStaticScope = getStaticScopeFactory().newLocalScope(null);
context.pushScope(new ManyVarsDynamicScope(topStaticScope, null));
}

while (!atExitBlocks.empty()) {
RubyProc proc = atExitBlocks.pop();
try {
Expand Down
63 changes: 50 additions & 13 deletions core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -53,6 +53,7 @@
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.PosixFileAttributeView;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -199,6 +200,7 @@ public static RubyClass createFileClass(Ruby runtime) {
constants.setConstant("FNM_SYSCASE", runtime.newFixnum(FNM_SYSCASE));
constants.setConstant("FNM_DOTMATCH", runtime.newFixnum(FNM_DOTMATCH));
constants.setConstant("FNM_PATHNAME", runtime.newFixnum(FNM_PATHNAME));
constants.setConstant("FNM_EXTGLOB", runtime.newFixnum(FNM_EXTGLOB));

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

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

return path;
Expand Down Expand Up @@ -793,25 +795,21 @@ public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv,
*/
@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false);
return expandPathInternal(context, recv, args, false, false);
}

@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false);
return expandPathInternal(context, recv, args, false, false);
}

@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
IRubyObject file = expandPathInternal(context, recv, args, false);
IRubyObject file = expandPathInternal(context, recv, args, false, true);
if (!RubyFileTest.exist_p(recv, file).isTrue()) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
try {
return context.runtime.newString(new File(file.toString()).getCanonicalPath());
} catch (IOException ioex) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
return file;
}

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

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

if (org.jruby.util.Dir.fnmatch(pattern.getUnsafeBytes(), pattern.getBegin(), pattern.getBegin()+pattern.getRealSize(), path.getUnsafeBytes(), path.getBegin(), path.getBegin()+path.getRealSize(), flags) == 0) {
if(extglob) {
String spattern = args[0].asJavaString();
ArrayList<String> patterns = org.jruby.util.Dir.braces(spattern, flags, new ArrayList<String>());

ArrayList<Boolean> matches = new ArrayList<Boolean>();
for(int i = 0; i < patterns.size(); i++) {
String p = patterns.get(i);
boolean match = dir_fnmatch(new ByteList(p.getBytes()), path, flags);
matches.add(match);
}
braces_match = matches.contains(true);
}

if(braces_match || dir_fnmatch(pattern, path, flags)) {
return context.runtime.getTrue();
}
return context.runtime.getFalse();
}


private static boolean dir_fnmatch(ByteList pattern, ByteList path, int flags) {
return org.jruby.util.Dir.fnmatch(pattern.getUnsafeBytes(),
pattern.getBegin(),
pattern.getBegin()+pattern.getRealSize(),
path.getUnsafeBytes(),
path.getBegin(),
path.getBegin()+path.getRealSize(),
flags) == 0;
}

@JRubyMethod(name = "ftype", required = 1, meta = true)
public static IRubyObject ftype(ThreadContext context, IRubyObject recv, IRubyObject filename) {
return context.runtime.newFileStat(get_path(context, filename).getUnicodeValue(), true).ftype();
Expand Down Expand Up @@ -1462,7 +1485,7 @@ private static boolean isWindowsDriveLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser) {
private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser, boolean canonicalize) {
Ruby runtime = context.runtime;

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

// Now that we're not treating it as a URI, we need to honor the canonicalize flag.
// Do not insert early returns below.

// If there's a second argument, it's the path to which the first
// argument is relative.
if (args.length == 2 && !args[1].isNil()) {
Expand Down Expand Up @@ -1582,7 +1608,17 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
path = JRubyFile.create(cwd, relativePath);
}

return runtime.newString(padSlashes + canonicalize(path.getAbsolutePath()));
String realPath = padSlashes + canonicalize(path.getAbsolutePath());

if (canonicalize) {
try {
realPath = new File(realPath).getCanonicalPath();
} catch (IOException ioe) {
// Earlier canonicalization will have to do.
}
}

return runtime.newString(realPath);
}

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

private static final String[] SLASHES = {"", "/", "//"};
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -1798,7 +1798,8 @@ private static int initGlobalJavaVersion() {
} else if (specVersion.equals("1.7") || specVersion.equals("1.8")) {
return Opcodes.V1_7;
} else {
throw new RuntimeException("unsupported Java version: " + specVersion);
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
return Opcodes.V1_5;
}
}
public void setTruffleHooks(TruffleHooksStub truffleHooks) {
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/RubyMatchData.java
Expand Up @@ -593,10 +593,8 @@ public IRubyObject initialize_copy(IRubyObject original) {

checkFrozen();

Ruby runtime = getRuntime();
ThreadContext context = runtime.getCurrentContext();
if (!(original instanceof RubyMatchData)) {
throw runtime.newTypeError("wrong argument class");
throw getRuntime().newTypeError("wrong argument class");
}

RubyMatchData origMatchData = (RubyMatchData)original;
Expand Down

0 comments on commit 8b16e6b

Please sign in to comment.