Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -59,6 +59,8 @@

public abstract class IOPrimitiveNodes {

private static int STDOUT = 1;

@RubiniusPrimitive(name = "io_allocate")
public static abstract class IOAllocatePrimitiveNode extends RubiniusPrimitiveNode {

@@ -326,6 +328,11 @@ public IOWritePrimitiveNode(RubyContext context, SourceSection sourceSection) {
public int write(VirtualFrame frame, RubyBasicObject file, RubyString string) {
final int fd = (int) rubyWithSelf(frame, file, "@descriptor");

if (getContext().getDebugStandardOut() != null && fd == STDOUT) {
getContext().getDebugStandardOut().write(string.getByteList().unsafeBytes(), string.getByteList().begin(), string.getByteList().length());
return string.getByteList().length();
}

// We have to copy here as write starts at byte[0], and the ByteList may not

final ByteList byteList = string.getByteList();
12 changes: 11 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
@@ -94,6 +95,8 @@ public class RubyContext extends ExecutionContext implements TruffleContextInter

private final boolean runningOnWindows;

private final PrintStream debugStandardOut;

public RubyContext(Ruby runtime) {
latestInstance = this;

@@ -160,6 +163,9 @@ public RubyContext(Ruby runtime) {
sourceManager = new SourceManager(this);
rubiniusConfiguration = new RubiniusConfiguration(this);

final PrintStream configStandardOut = runtime.getInstanceConfig().getOutput();
debugStandardOut = configStandardOut == System.out ? null : configStandardOut;

// Give the core library manager a chance to tweak some of those methods

coreLibrary.initializeAfterMethodsAdded();
@@ -666,5 +672,9 @@ public void shutdown() {
}
}
}


public PrintStream getDebugStandardOut() {
return debugStandardOut;
}

}

0 comments on commit 2fe04df

Please sign in to comment.