Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jruby-1_7'
Browse files Browse the repository at this point in the history
Conflicts:
	core/pom.xml
	core/src/main/java/org/jruby/RubyFile.java
	core/src/main/java/org/jruby/RubyFileTest.java
	core/src/main/java/org/jruby/RubyKernel.java
	core/src/main/java/org/jruby/util/RegularFileResource.java
	core/src/main/java/org/jruby/util/TypeConverter.java
	docs/man/pom.xml
	docs/pom.xml
	ext/pom.xml
	ext/readline/pom.xml
	ext/ripper/pom.xml
	lib/pom.xml
	maven/jruby-complete/pom.xml
	maven/jruby-dist/pom.xml
	maven/jruby-jars/pom.xml
	maven/jruby-noasm/pom.xml
	maven/jruby-rake-plugin/pom.xml
	maven/jruby-stdlib/pom.xml
	maven/jruby/pom.xml
	maven/pom.xml
	pom.xml
	test/jruby/test_system_error.rb
	test/pom.xml
  • Loading branch information
headius committed Sep 11, 2014
2 parents b707c91 + 5f0e17b commit 0513c95
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 172 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -3379,7 +3379,7 @@ public IRubyObject product19(ThreadContext context, IRubyObject[] args, Block bl
int counters[] = new int[n];

arrays[0] = this;
for (int i = 1; i < n; i++) arrays[i] = args[i - 1].convertToArray();
for (int i = 1; i < n; i++) arrays[i] = TypeConverter.to_ary(context, args[i - 1]);

int resultLen = 1;
for (int i = 0; i < n; i++) {
Expand Down
81 changes: 62 additions & 19 deletions core/src/main/java/org/jruby/RubyClass.java
Expand Up @@ -30,6 +30,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jruby.runtime.Arity;
import org.jruby.runtime.ivars.VariableAccessor;
import static org.jruby.util.CodegenUtils.ci;
import static org.jruby.util.CodegenUtils.p;
Expand Down Expand Up @@ -616,30 +617,72 @@ public IRubyObject finvoke(ThreadContext context, IRubyObject self, String name)
}

public IRubyObject finvokeChecked(ThreadContext context, IRubyObject self, String name) {
DynamicMethod method = searchMethod(name);
if(method.isUndefined()) {
DynamicMethod methodMissing = searchMethod("method_missing");
if(methodMissing.isUndefined() || methodMissing.equals(context.runtime.getDefaultMethodMissing())) {
return null;
RubyClass klass = self.getMetaClass();
DynamicMethod me;
if (!checkFuncallRespondTo(context, self.getMetaClass(), self, name))
return null;

me = searchMethod(name);
if (!checkFuncallCallable(context, me)) {
return checkFuncallMissing(context, klass, self, name);
}
return me.call(context, self, klass, name);
}

// MRI: check_funcall_exec
private static IRubyObject checkFuncallExec(ThreadContext context, IRubyObject self, String name, IRubyObject... args) {
IRubyObject[] newArgs = new IRubyObject[args.length + 1];
System.arraycopy(args, 0, newArgs, 1, args.length);
newArgs[0] = context.runtime.newSymbol(name);
return self.callMethod(context, "method_missing", newArgs);
}

// MRI: check_funcall_failed
private static IRubyObject checkFuncallFailed(ThreadContext context, IRubyObject self, String name, RubyClass expClass, IRubyObject... args) {
if (self.respondsTo(name)) {
throw context.runtime.newRaiseException(expClass, name);
}
return null;
}

// MRI: check_funcall_respond_to
private static boolean checkFuncallRespondTo(ThreadContext context, RubyClass klass, IRubyObject recv, String mid) {
Ruby runtime = context.runtime;
RubyClass defined_class;
DynamicMethod me = klass.searchMethod("respond_to?");

if (me != null && !me.isUndefined()) {
Arity arity = me.getArity();

if (arity.getValue() > 2)
throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arity + ")");

IRubyObject result = me.call(context, recv, klass, "respond_to?", runtime.newString(mid), runtime.getTrue());
if (!result.isTrue()) {
return false;
}
}
return true;
}

// MRI: check_funcall_callable
public static boolean checkFuncallCallable(ThreadContext context, DynamicMethod method) {
// FIXME: MRI actually checks protectedness here too
return !method.getVisibility().isPrivate();
}

private static IRubyObject checkFuncallMissing(ThreadContext context, RubyClass klass, IRubyObject self, String method, IRubyObject... args) {
Ruby runtime = context.runtime;
if (klass.isMethodBuiltin("method_missing")) {
return null;
}
else {
try {
return Helpers.callMethodMissing(context, self, method.getVisibility(), name, CallType.FUNCTIONAL, Block.NULL_BLOCK);
} catch(RaiseException e) {
if(context.runtime.getNoMethodError().isInstance(e.getException())) {
if(self.respondsTo(name)) {
throw e;
} else {
// we swallow, so we also must clear $!
context.setErrorInfo(context.nil);
return null;
}
} else {
throw e;
}
return checkFuncallExec(context, self, method, args);
} catch (Exception e) {
return checkFuncallFailed(context, self, method, runtime.getNoMethodError(), args);
}
}
return method.call(context, self, this, name);
}

public IRubyObject invoke(ThreadContext context, IRubyObject self, String name,
Expand Down
25 changes: 17 additions & 8 deletions core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -1212,9 +1212,7 @@ public IRubyObject fileOpenGeneric(ThreadContext context, IRubyObject filename,

// mri: FilePathValue/rb_get_path/rb_get_patch_check
public static RubyString get_path(ThreadContext context, IRubyObject path) {
if (path instanceof RubyString) {
return (RubyString)path;
}
if (path instanceof RubyString) return (RubyString) path;

if (path.respondsTo("to_path")) path = path.callMethod(context, "to_path");

Expand Down Expand Up @@ -1242,7 +1240,20 @@ private static RubyString filePathConvert(ThreadContext context, RubyString path

return path;
}



public static FileResource fileResource(ThreadContext context, IRubyObject pathOrFile) {
Ruby runtime = context.runtime;

if (pathOrFile instanceof RubyFile) {
return JRubyFile.createResource(runtime, ((RubyFile) pathOrFile).getPath());
} else if (pathOrFile instanceof RubyIO) {
return JRubyFile.createResource(runtime, ((RubyIO) pathOrFile).openFile.getPath());

}

return JRubyFile.createResource(runtime, get_path(context, pathOrFile).toString());
}
/**
* Get the fully-qualified JRubyFile object for the path, taking into
* account the runtime's current directory.
Expand All @@ -1254,11 +1265,9 @@ public static FileResource fileResource(IRubyObject pathOrFile) {
return JRubyFile.createResource(runtime, ((RubyFile) pathOrFile).getPath());
} else if (pathOrFile instanceof RubyIO) {
return JRubyFile.createResource(runtime, ((RubyIO) pathOrFile).openFile.getPath());
} else {
RubyString pathStr = get_path(runtime.getCurrentContext(), pathOrFile);

return JRubyFile.createResource(runtime, pathStr.toString());
}

return JRubyFile.createResource(runtime, get_path(runtime.getCurrentContext(), pathOrFile).toString());
}

@Deprecated // Use fileResource instead
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/jruby/RubyFileStat.java
Expand Up @@ -126,12 +126,9 @@ private void setup(String filename, boolean lstat) {
}

file = JRubyFile.createResource(getRuntime().getPosix(), getRuntime().getCurrentDirectory(), filename);

if (!file.exists()) {
throw getRuntime().newErrnoENOENTError("No such file or directory - " + filename);
}

stat = lstat ? file.lstat() : file.stat();

if (stat == null) throw getRuntime().newErrnoFromInt(getRuntime().getPosix().errno());
}

public IRubyObject initialize(IRubyObject fname, Block unusedBlock) {
Expand Down

0 comments on commit 0513c95

Please sign in to comment.