Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c38e5cef99c8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 68cf9fc1253f
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 14, 2015

  1. 5
    Copy the full SHA
    089d126 View commit details
  2. Copy the full SHA
    68cf9fc View commit details
Original file line number Diff line number Diff line change
@@ -25,130 +25,15 @@ public abstract class ExceptionPrimitiveNodes {
@RubiniusPrimitive(name = "exception_errno_error", needsSelf = false)
public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPrimitiveNode {

// If you add a constant here, add it below in isExceptionSupported() too.
protected final static int EPERM = Errno.EPERM.intValue();
protected final static int ENOENT = Errno.ENOENT.intValue();
protected final static int EBADF = Errno.EBADF.intValue();
protected final static int EEXIST = Errno.EEXIST.intValue();
protected final static int EACCES = Errno.EACCES.intValue();
protected final static int EFAULT = Errno.EFAULT.intValue();
protected final static int ENOTDIR = Errno.ENOTDIR.intValue();
protected final static int EINVAL = Errno.EINVAL.intValue();
protected final static int EINPROGRESS = Errno.EINPROGRESS.intValue();
protected final static int ENOTCONN = Errno.ENOTCONN.intValue();
protected final static int ECONNREFUSED = Errno.ECONNREFUSED.intValue();

public static boolean isExceptionSupported(int errno) {
return errno == EPERM || errno == ENOENT || errno == EBADF || errno == EEXIST || errno == EACCES
|| errno == EFAULT || errno == ENOTDIR || errno == EINVAL || errno == EINPROGRESS
|| errno == ENOTCONN || errno == ECONNREFUSED;
}

public ExceptionErrnoErrorPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = {"isRubyString(message)", "errno == EPERM"})
public DynamicObject eperm(DynamicObject message, int errno) {
return getContext().getCoreLibrary().operationNotPermittedError(message.toString(), this);
}

@Specialization(guards = {"errno == EPERM", "isNil(message)"})
public DynamicObject eperm(Object message, int errno) {
return getContext().getCoreLibrary().operationNotPermittedError("nil", this);
}

@Specialization(guards = {"isRubyString(message)", "errno == ENOENT"})
public DynamicObject enoent(DynamicObject message, int errno) {
return getContext().getCoreLibrary().fileNotFoundError(message.toString(), this);
}

@Specialization(guards = { "errno == ENOENT", "isNil(message)" })
public DynamicObject enoent(Object message, int errno) {
return getContext().getCoreLibrary().fileNotFoundError("nil", this);
}

@Specialization(guards = { "errno == EBADF", "isNil(message)" })
public DynamicObject ebadf(Object message, int errno) {
return getContext().getCoreLibrary().badFileDescriptor(this);
}

@Specialization(guards = {"isRubyString(message)", "errno == EEXIST"})
public DynamicObject eexist(DynamicObject message, int errno) {
return getContext().getCoreLibrary().fileExistsError(message.toString(), this);
}

@Specialization(guards = { "errno == EEXIST", "isNil(message)" })
public DynamicObject eexist(Object message, int errno) {
return getContext().getCoreLibrary().fileExistsError("nil", this);
}

@Specialization(guards = {"isRubyString(message)", "errno == EACCES"})
public DynamicObject eacces(DynamicObject message, int errno) {
return getContext().getCoreLibrary().permissionDeniedError(message.toString(), this);
}

@Specialization(guards = {"errno == EACCES", "isNil(message)"})
public DynamicObject eacces(Object message, int errno) {
return getContext().getCoreLibrary().permissionDeniedError("nil", this);
}

@Specialization(guards = {"isRubyString(message)", "errno == EFAULT"})
public DynamicObject efault(DynamicObject message, int errno) {
return getContext().getCoreLibrary().badAddressError(this);
}

@Specialization(guards = {"errno == EFAULT", "isNil(message)"})
public DynamicObject efault(Object message, int errno) {
return getContext().getCoreLibrary().badAddressError(this);
}

@Specialization(guards = {"isRubyString(message)", "errno == ENOTDIR"})
public DynamicObject enotdir(DynamicObject message, int errno) {
return getContext().getCoreLibrary().notDirectoryError(message.toString(), this);
}

@Specialization(guards = {"isRubyString(message)", "errno == EINVAL"})
public DynamicObject einval(DynamicObject message, int errno) {
return getContext().getCoreLibrary().errnoError(errno, this);
}

@Specialization(guards = {"isRubyString(message)", "errno == EINPROGRESS"})
public DynamicObject einprogress(DynamicObject message, int errno) {
@Specialization
public DynamicObject exceptionErrnoError(DynamicObject message, int errno) {
return getContext().getCoreLibrary().errnoError(errno, this);
}

@Specialization(guards = {"isRubyString(message)", "errno == ENOTCONN"})
public DynamicObject enotconn(DynamicObject message, int errno) {
return getContext().getCoreLibrary().errnoError(errno, this);
}

@Specialization(guards = {"isRubyString(message)", "errno == ECONNREFUSED"})
public DynamicObject econnrefused(DynamicObject message, int errno) {
return getContext().getCoreLibrary().errnoError(errno, this);
}

@TruffleBoundary
@Specialization(guards = "!isExceptionSupported(errno)")
public DynamicObject unsupported(Object message, int errno) {
final Errno errnoObject = Errno.valueOf(errno);

final String messageString;
if (RubyGuards.isRubyString(message)) {
messageString = message.toString();
} else if (message == nil()) {
messageString = "nil";
} else {
messageString = "unsupported message type";
}

if (errnoObject == null) {
throw new UnsupportedOperationException("errno: " + errno + " " + messageString);
} else {
throw new UnsupportedOperationException("errno: " + errnoObject.name());
}
}

}

}
Original file line number Diff line number Diff line change
@@ -916,11 +916,6 @@ public DynamicObject indexTooSmallError(String type, int index, int length, Node
return indexError(String.format("index %d too small for %s; minimum: -%d", index, type, length), currentNode);
}

public DynamicObject indexNegativeLength(int length, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return indexError(String.format("negative length (%d)", length), currentNode);
}

public DynamicObject localJumpError(String message, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(localJumpErrorClass, Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(message, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
@@ -962,11 +957,6 @@ public DynamicObject typeErrorCantDefineSingleton(Node currentNode) {
return typeError("can't define singleton", currentNode);
}

public DynamicObject typeErrorNoClassToMakeAlias(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return typeError("no class to make alias", currentNode);
}

public DynamicObject typeErrorShouldReturn(String object, String method, String expectedType, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return typeError(String.format("%s#%s should return %s", object, method, expectedType), currentNode);
@@ -1012,11 +1002,6 @@ public DynamicObject typeErrorBadCoercion(Object from, String to, String coercio
Layouts.MODULE.getFields(getLogicalClass(coercedTo)).getName()), currentNode);
}

public DynamicObject typeErrorCantCoerce(Object from, String to, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return typeError(String.format("%s can't be coerced into %s", from, to), currentNode);
}

public DynamicObject typeErrorCantDump(Object object, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
String logicalClass = Layouts.MODULE.getFields(getLogicalClass(object)).getName();
@@ -1182,57 +1167,11 @@ public DynamicObject mathDomainError(String method, Node currentNode) {
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EDOM), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Numerical argument is out of domain - \"%s\"", method), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject invalidArgumentError(String value, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EINVAL), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Invalid argument - %s", value), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject ioError(String fileName, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(ioErrorClass, Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Error reading file - %s", fileName), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject badAddressError(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EFAULT), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist("Bad address", UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}


public DynamicObject badFileDescriptor(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EBADF), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist("Bad file descriptor", UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject fileExistsError(String fileName, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EEXIST), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("File exists - %s", fileName), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject fileNotFoundError(String fileName, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.ENOENT), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("No such file or directory - %s", fileName), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject dirNotEmptyError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.ENOTEMPTY), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Directory not empty - %s", path), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject operationNotPermittedError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EPERM), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Operation not permitted - %s", path), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject permissionDeniedError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.EACCES), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Permission denied - %s", path), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject notDirectoryError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(getErrnoClass(Errno.ENOTDIR), Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(String.format("Not a directory - %s", path), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null), RubyCallStack.getBacktrace(currentNode));
}

public DynamicObject rangeError(int code, DynamicObject encoding, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
assert RubyGuards.isRubyEncoding(encoding);