private static Channel prepareStdioChannel(Ruby runtime, STDIO stdio, Object stream) { if (runtime.getPosix().isNative() && stdio.isJVMDefault(stream) && !Platform.IS_WINDOWS) { // use real native channel for stdio return new NativeDeviceChannel(stdio.fileno()); } else { switch (stdio) { case IN: return Channels.newChannel((InputStream) stream); case OUT: case ERR: return Channels.newChannel((OutputStream) stream); default: throw new RuntimeException("invalid stdio: " + stdio); } } }
private static int handleRaiseException(RaiseException rj) { RubyException raisedException = rj.getException(); Ruby runtime = raisedException.getRuntime(); if (runtime.getSystemExit().isInstance(raisedException)) { IRubyObject status = raisedException.callMethod(runtime.getCurrentContext(), "status"); if (status != null && !status.isNil()) { return RubyNumeric.fix2int(status); } else { return 0; } } else { runtime .getErrorStream() .print( runtime .getInstanceConfig() .getTraceType() .printBacktrace(raisedException, runtime.getPosix().isatty(FileDescriptor.err))); return 1; } }
public IRubyObject getValue() { return pid != null ? pid : (pid = runtime.newFixnum(runtime.getPosix().getpid())); }