Skip to content

Commit

Permalink
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/new_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:File.new raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL
fails:File.new raises an Errno::EBADF if the first parameter is an invalid file descriptor
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public abstract class ExceptionPrimitiveNodes {
public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPrimitiveNode {

protected final int ENOENT = Errno.ENOENT.intValue();
protected final int EBADF = Errno.EBADF.intValue();

public ExceptionErrnoErrorPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -37,8 +38,18 @@ public RubyException enoent(RubyString message, int errno) {
return getContext().getCoreLibrary().fileNotFoundError(message.toString(), this);
}

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

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

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "errno != ENOENT")
@Specialization(guards = "!isExceptionSupported(errno)")
public RubyException unsupported(RubyString message, int errno) {
final Errno errnoObject = Errno.valueOf(errno);

@@ -49,13 +60,8 @@ public RubyException unsupported(RubyString message, int errno) {
}
}

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

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "errno != ENOENT")
@Specialization(guards = "!isExceptionSupported(errno)")
public RubyException unsupported(RubyNilClass message, int errno) {
final Errno errnoObject = Errno.valueOf(errno);

@@ -66,6 +72,10 @@ public RubyException unsupported(RubyNilClass message, int errno) {
}
}

public static boolean isExceptionSupported(int errno) {
return Errno.ENOENT.intValue() == errno || Errno.EBADF.intValue() == errno;
}

}

}
Original file line number Diff line number Diff line change
@@ -931,6 +931,11 @@ public RubyException ioError(String fileName, Node currentNode) {
return new RubyException(ioErrorClass, context.makeString(String.format("Error reading file - %s", fileName)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException badFileDescriptor(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(getErrnoClass(Errno.EBADF), context.makeString("Bad file descriptor"), RubyCallStack.getBacktrace(currentNode));
}

public RubyException fileNotFoundError(String fileName, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(getErrnoClass(Errno.ENOENT), context.makeString(String.format("No such file or directory - %s", fileName)), RubyCallStack.getBacktrace(currentNode));

0 comments on commit acdac1f

Please sign in to comment.