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: 3efa7feaf15c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5f85cb8fdecc
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 18, 2017

  1. Copy the full SHA
    4567351 View commit details
  2. Copy the full SHA
    5f85cb8 View commit details
Showing with 18 additions and 25 deletions.
  1. +5 −6 core/src/main/java/org/jruby/RubyRange.java
  2. +13 −19 core/src/main/java/org/jruby/runtime/Helpers.java
11 changes: 5 additions & 6 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -481,9 +481,8 @@ public IRubyObject each(final ThreadContext context, final Block block) {
if (!block.isGiven()) {
return enumeratorizeWithSize(context, this, "each", enumSizeFn(context));
}
final Ruby runtime = context.runtime;
if (begin instanceof RubyFixnum && end instanceof RubyFixnum) {
fixnumEach(context, runtime, block);
fixnumEach(context, block);
} else if (begin instanceof RubySymbol && end instanceof RubySymbol) {
begin.asString().uptoCommon(context, end.asString(), isExclusive, block, true);
} else {
@@ -492,8 +491,7 @@ public IRubyObject each(final ThreadContext context, final Block block) {
((RubyString) tmp).uptoCommon(context, end, isExclusive, block);
} else {
if (!discreteObject(context, begin)) {
throw runtime.newTypeError("can't iterate from "
+ begin.getMetaClass().getName());
throw context.runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
}
rangeEach(context, new RangeCallBack() {
@Override
@@ -506,7 +504,7 @@ void call(ThreadContext context, IRubyObject arg) {
return this;
}

private void fixnumEach(ThreadContext context, Ruby runtime, Block block) {
private void fixnumEach(ThreadContext context, Block block) {
// We must avoid integer overflows.
long to = ((RubyFixnum) end).getLongValue();
if (isExclusive) {
@@ -517,7 +515,7 @@ private void fixnumEach(ThreadContext context, Ruby runtime, Block block) {
}
long from = ((RubyFixnum) begin).getLongValue();
if (block.getSignature() == Signature.NO_ARGUMENTS) {
IRubyObject nil = runtime.getNil();
final IRubyObject nil = context.nil;
long i;
for (i = from; i < to; i++) {
block.yield(context, nil);
@@ -526,6 +524,7 @@ private void fixnumEach(ThreadContext context, Ruby runtime, Block block) {
block.yield(context, nil);
}
} else {
final Ruby runtime = context.runtime;
long i;
for (i = from; i < to; i++) {
block.yield(context, RubyFixnum.newFixnum(runtime, i));
32 changes: 13 additions & 19 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -259,31 +259,25 @@ public static Errno errnoFromException(Throwable t) {
return Errno.EBADF;
}

final String errorMessage = t.getMessage();
// TODO: this is kinda gross
if(t.getMessage() != null) {
String errorMessage = t.getMessage();

if (errorMessage != null) {
// All errors to sysread should be SystemCallErrors, but on a closed stream
// Ruby returns an IOError. Java throws same exception for all errors so
// we resort to this hack...
switch (errorMessage) {
case "Bad file descriptor" : return Errno.EBADF;
case "File not open" : return null;
case "An established connection was aborted by the software in your host machine" : return Errno.ECONNABORTED;
case "Broken pipe" : return Errno.EPIPE;

case "Connection reset by peer" : return Errno.ECONNRESET;
case "An existing connection was forcibly closed by the remote host" : return Errno.ECONNRESET;

if ("Bad file descriptor".equals(errorMessage)) {
return Errno.EBADF;
} else if ("File not open".equals(errorMessage)) {
return null;
} else if ("An established connection was aborted by the software in your host machine".equals(errorMessage)) {
return Errno.ECONNABORTED;
} else if (t.getMessage().equals("Broken pipe")) {
return Errno.EPIPE;
} else if ("Connection reset by peer".equals(errorMessage) ||
"An existing connection was forcibly closed by the remote host".equals(errorMessage) ||
(Platform.IS_WINDOWS && errorMessage.contains("connection was aborted"))) {
return Errno.ECONNRESET;
} else if (errorMessage.equals("No space left on device")) {
return Errno.ENOSPC;
} else if (errorMessage.equals("Too many open files")) {
return Errno.EMFILE;
case "No space left on device" : return Errno.ENOSPC;
case "Too many open files" : return Errno.EMFILE;
}
if (Platform.IS_WINDOWS && errorMessage.contains("connection was aborted")) return Errno.ECONNRESET;
}
return null;
}