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

Commits on Feb 24, 2015

  1. Copy the full SHA
    b881f9f View commit details
  2. Copy the full SHA
    e3cf9a9 View commit details
Showing with 26 additions and 2 deletions.
  1. +10 −0 core/src/main/java/org/jruby/RubyGlobal.java
  2. +14 −0 core/src/main/java/org/jruby/RubyIO.java
  3. +2 −2 core/src/main/java/org/jruby/util/io/PosixShim.java
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
@@ -64,6 +64,8 @@

import static org.jruby.internal.runtime.GlobalVariable.Scope.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channel;
@@ -283,9 +285,17 @@ private static Channel prepareStdioChannel(Ruby runtime, STDIO stdio, Object str
} else {
switch (stdio) {
case IN:
if (stream instanceof FileInputStream) {
return ((FileInputStream)stream).getChannel();
}

return Channels.newChannel((InputStream)stream);
case OUT:
case ERR:
if (stream instanceof FileOutputStream) {
return ((FileOutputStream)stream).getChannel();
}

return Channels.newChannel((OutputStream)stream);
default: throw new RuntimeException("invalid stdio: " + stdio);
}
14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -182,6 +182,12 @@ public static RubyIO prepStdio(Ruby runtime, InputStream f, Channel c, int fmode
RubyIO io = prepIO(runtime, c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);

fptr = io.getOpenFileChecked();

// Use standard stdio filenos if we're using System.in et al.
if (f == System.in) {
fptr.fd().realFileno = 0;
}

prepStdioEcflags(fptr, fmode);
fptr.stdio_file = f;

@@ -195,6 +201,14 @@ public static RubyIO prepStdio(Ruby runtime, OutputStream f, Channel c, int fmod
RubyIO io = prepIO(runtime, c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);

fptr = io.getOpenFileChecked();

// Use standard stdio filenos if we're using System.in et al.
if (f == System.out) {
fptr.fd().realFileno = 1;
} else if (f == System.err) {
fptr.fd().realFileno = 2;
}

prepStdioEcflags(fptr, fmode);
fptr.stdio_file = f;

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
@@ -392,8 +392,8 @@ public Channel open(String cwd, String path, ModeFlags flags, int perm) {
}

public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoader classLoader) {
if (path.equals("/dev/null") || path.equalsIgnoreCase("nul:") || path.equalsIgnoreCase("nul")) {
return new NullChannel();
if ((path.equals("/dev/null") || path.equalsIgnoreCase("nul")) && Platform.IS_WINDOWS) {
path = "nul:";
}

if (path.startsWith("classpath:/") && classLoader != null) {