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/util/cli/Options.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  • Loading branch information
chrisseaton committed Feb 6, 2015
2 parents b8b9da1 + 584ec92 commit 8330e22
Show file tree
Hide file tree
Showing 55 changed files with 1,429 additions and 866 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -71,6 +71,7 @@ tool/nailgun/Makefile
tool/nailgun/config.log
tool/nailgun/config.status
tool/nailgun/ng
reference.txt

# binaries
!bin/gem
Expand Down
84 changes: 66 additions & 18 deletions core/src/main/java/org/jruby/RubyFileStat.java
Expand Up @@ -66,6 +66,10 @@ public class RubyFileStat extends RubyObject {
private FileResource file;
private FileStat stat;

private void checkInitialized() {
if (stat == null) throw getRuntime().newTypeError("uninitialized File::Stat");
}

private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
Expand Down Expand Up @@ -148,31 +152,37 @@ public IRubyObject initialize19(IRubyObject fname, Block unusedBlock) {

@JRubyMethod(name = "atime")
public IRubyObject atime() {
checkInitialized();
return getRuntime().newTime(stat.atime() * 1000);
}

@JRubyMethod(name = "blksize")
public RubyFixnum blksize() {
checkInitialized();
return getRuntime().newFixnum(stat.blockSize());
}

@JRubyMethod(name = "blockdev?")
public IRubyObject blockdev_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isBlockDev());
}

@JRubyMethod(name = "blocks")
public IRubyObject blocks() {
checkInitialized();
return getRuntime().newFixnum(stat.blocks());
}

@JRubyMethod(name = "chardev?")
public IRubyObject chardev_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isCharDev());
}

@JRubyMethod(name = "<=>", required = 1)
public IRubyObject cmp(IRubyObject other) {
checkInitialized();
if (!(other instanceof RubyFileStat)) return getRuntime().getNil();

long time1 = stat.mtime();
Expand All @@ -189,63 +199,75 @@ public IRubyObject cmp(IRubyObject other) {

@JRubyMethod(name = "ctime")
public IRubyObject ctime() {
checkInitialized();
return getRuntime().newTime(stat.ctime() * 1000);
}

@JRubyMethod(name = "birthtime")
public IRubyObject birthtime() {
checkInitialized();
FileTime btime = RubyFile.getBirthtimeWithNIO(file.absolutePath());
if (btime != null) return getRuntime().newTime(btime.toMillis());
return ctime();
}

@JRubyMethod(name = "dev")
public IRubyObject dev() {
checkInitialized();
return getRuntime().newFixnum(stat.dev());
}

@JRubyMethod(name = "dev_major")
public IRubyObject devMajor() {
checkInitialized();
return getRuntime().newFixnum(stat.major(stat.dev()));
}

@JRubyMethod(name = "dev_minor")
public IRubyObject devMinor() {
checkInitialized();
return getRuntime().newFixnum(stat.minor(stat.dev()));
}

@JRubyMethod(name = "directory?")
public RubyBoolean directory_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isDirectory());
}

@JRubyMethod(name = "executable?")
public IRubyObject executable_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isExecutable());
}

@JRubyMethod(name = "executable_real?")
public IRubyObject executableReal_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isExecutableReal());
}

@JRubyMethod(name = "file?")
public RubyBoolean file_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isFile());
}

@JRubyMethod(name = "ftype")
public RubyString ftype() {
checkInitialized();
return getRuntime().newString(stat.ftype());
}

@JRubyMethod(name = "gid")
public IRubyObject gid() {
checkInitialized();
return getRuntime().newFixnum(stat.gid());
}

@JRubyMethod(name = "grpowned?")
public IRubyObject group_owned_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isGroupOwned());
}

Expand All @@ -268,6 +290,7 @@ public IRubyObject initialize_copy(IRubyObject original) {

@JRubyMethod(name = "ino")
public IRubyObject ino() {
checkInitialized();
return getRuntime().newFixnum(stat.ino());
}

Expand All @@ -276,41 +299,48 @@ public IRubyObject ino() {
public IRubyObject inspect() {
StringBuilder buf = new StringBuilder("#<");
buf.append(getMetaClass().getRealClass().getName());
buf.append(" ");
// FIXME: Obvious issue that not all platforms can display all attributes. Ugly hacks.
// Using generic posix library makes pushing inspect behavior into specific system impls
// rather painful.
try { buf.append("dev=0x").append(Long.toHexString(stat.dev())); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("ino=").append(stat.ino()); } catch (Exception e) {} finally { buf.append(", "); }
buf.append("mode=0").append(Integer.toOctalString(stat.mode())).append(", ");
try { buf.append("nlink=").append(stat.nlink()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("uid=").append(stat.uid()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("gid=").append(stat.gid()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("rdev=0x").append(Long.toHexString(stat.rdev())); } catch (Exception e) {} finally { buf.append(", "); }
buf.append("size=").append(sizeInternal()).append(", ");
try { buf.append("blksize=").append(stat.blockSize()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("blocks=").append(stat.blocks()); } catch (Exception e) {} finally { buf.append(", "); }

buf.append("atime=").append(atime()).append(", ");
buf.append("mtime=").append(mtime()).append(", ");
buf.append("ctime=").append(ctime());
if (stat == null) {
buf.append(": uninitialized");
} else {
buf.append(" ");
// FIXME: Obvious issue that not all platforms can display all attributes. Ugly hacks.
// Using generic posix library makes pushing inspect behavior into specific system impls
// rather painful.
try { buf.append("dev=0x").append(Long.toHexString(stat.dev())); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("ino=").append(stat.ino()); } catch (Exception e) {} finally { buf.append(", "); }
buf.append("mode=0").append(Integer.toOctalString(stat.mode())).append(", ");
try { buf.append("nlink=").append(stat.nlink()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("uid=").append(stat.uid()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("gid=").append(stat.gid()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("rdev=0x").append(Long.toHexString(stat.rdev())); } catch (Exception e) {} finally { buf.append(", "); }
buf.append("size=").append(sizeInternal()).append(", ");
try { buf.append("blksize=").append(stat.blockSize()); } catch (Exception e) {} finally { buf.append(", "); }
try { buf.append("blocks=").append(stat.blocks()); } catch (Exception e) {} finally { buf.append(", "); }

buf.append("atime=").append(atime()).append(", ");
buf.append("mtime=").append(mtime()).append(", ");
buf.append("ctime=").append(ctime());
}
buf.append(">");

return getRuntime().newString(buf.toString());
}

@JRubyMethod(name = "uid")
public IRubyObject uid() {
checkInitialized();
return getRuntime().newFixnum(stat.uid());
}

@JRubyMethod(name = "mode")
public IRubyObject mode() {
checkInitialized();
return getRuntime().newFixnum(stat.mode());
}

@JRubyMethod(name = "mtime")
public IRubyObject mtime() {
checkInitialized();
return getRuntime().newTime(stat.mtime() * 1000);
}

Expand All @@ -328,55 +358,66 @@ public IRubyObject mtimeLessThan(IRubyObject other) {

@JRubyMethod(name = "nlink")
public IRubyObject nlink() {
checkInitialized();
return getRuntime().newFixnum(stat.nlink());
}

@JRubyMethod(name = "owned?")
public IRubyObject owned_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isOwned());
}

@JRubyMethod(name = "pipe?")
public IRubyObject pipe_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isNamedPipe());
}

@JRubyMethod(name = "rdev")
public IRubyObject rdev() {
checkInitialized();
return getRuntime().newFixnum(stat.rdev());
}

@JRubyMethod(name = "rdev_major")
public IRubyObject rdevMajor() {
checkInitialized();
return getRuntime().newFixnum(stat.major(stat.rdev()));
}

@JRubyMethod(name = "rdev_minor")
public IRubyObject rdevMinor() {
checkInitialized();
return getRuntime().newFixnum(stat.minor(stat.rdev()));
}

@JRubyMethod(name = "readable?")
public IRubyObject readable_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isReadable());
}

@JRubyMethod(name = "readable_real?")
public IRubyObject readableReal_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isReadableReal());
}

@JRubyMethod(name = "setgid?")
public IRubyObject setgid_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isSetgid());
}

@JRubyMethod(name = "setuid?")
public IRubyObject setuid_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isSetuid());
}

private long sizeInternal() {
checkInitialized();
// Workaround for JRUBY-4149
if (Platform.IS_WINDOWS && file != null) {
try {
Expand Down Expand Up @@ -405,11 +446,13 @@ public IRubyObject size_p() {

@JRubyMethod(name = "socket?")
public IRubyObject socket_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isSocket());
}

@JRubyMethod(name = "sticky?")
public IRubyObject sticky_p() {
checkInitialized();
Ruby runtime = getRuntime();

if (runtime.getPosix().isNative()) {
Expand All @@ -421,21 +464,25 @@ public IRubyObject sticky_p() {

@JRubyMethod(name = "symlink?")
public IRubyObject symlink_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isSymlink());
}

@JRubyMethod(name = "writable?")
public IRubyObject writable_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isWritable());
}

@JRubyMethod(name = "writable_real?")
public IRubyObject writableReal_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isWritableReal());
}

@JRubyMethod(name = "zero?")
public IRubyObject zero_p() {
checkInitialized();
return getRuntime().newBoolean(stat.isEmpty());
}

Expand All @@ -450,6 +497,7 @@ public IRubyObject worldWritable(ThreadContext context) {
}

private IRubyObject getWorldMode(ThreadContext context, int mode) {
checkInitialized();
if ((stat.mode() & mode) == mode) {
return RubyNumeric.int2fix(context.runtime,
(stat.mode() & (S_IRUGO | S_IWUGO | S_IXUGO) ));
Expand Down
30 changes: 17 additions & 13 deletions core/src/main/java/org/jruby/RubyHash.java
Expand Up @@ -1892,25 +1892,29 @@ public IRubyObject any_p(ThreadContext context, Block block) {

private IRubyObject any_p_i(ThreadContext context, Block block) {
iteratorEntry();
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
IRubyObject newAssoc = RubyArray.newArray(context.runtime, entry.key, entry.value);
if (block.yield(context, newAssoc).isTrue())
return context.getRuntime().getTrue();
try {
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
IRubyObject newAssoc = RubyArray.newArray(context.runtime, entry.key, entry.value);
if (block.yield(context, newAssoc).isTrue())
return context.getRuntime().getTrue();
}
return context.getRuntime().getFalse();
} finally {
iteratorExit();
}
iteratorExit();

return context.getRuntime().getFalse();
}

private IRubyObject any_p_i_fast(ThreadContext context, Block block) {
iteratorEntry();
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
if (block.yieldSpecific(context, entry.key, entry.value).isTrue())
return context.getRuntime().getTrue();
try {
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
if (block.yieldSpecific(context, entry.key, entry.value).isTrue())
return context.getRuntime().getTrue();
}
return context.getRuntime().getFalse();
} finally {
iteratorExit();
}
iteratorExit();

return context.getRuntime().getFalse();
}

/**
Expand Down

0 comments on commit 8330e22

Please sign in to comment.