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

Commits on Jan 4, 2016

  1. Copy the full SHA
    8a2cd2f View commit details
  2. [Truffle] Debug utility to write a string to a file - useful when sta…

    …ndard files are complex.
    chrisseaton committed Jan 4, 2016
    Copy the full SHA
    d586238 View commit details
  3. [Truffle] Typo.

    chrisseaton committed Jan 4, 2016
    Copy the full SHA
    f7747a7 View commit details
  4. Copy the full SHA
    3c5e0c6 View commit details
  5. Copy the full SHA
    359a909 View commit details
2 changes: 1 addition & 1 deletion spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ slow:The predefined global constant STDIN retains the encoding set by #set_encod
slow:The predefined global constant STDIN has the encodings set by #set_encoding
slow:The predefined global constant STDOUT has the encodings set by #set_encoding
slow:The predefined global constant ARGV contains Strings encoded in locale Encoding
linux:Global variable $0 actually sets the program name
fails:Predefined global $_ is set to the last line read by e.g. StringIO#gets
fails:Predefined global $_ is set at the method-scoped level rather than block-scoped
fails:Global variable $0 actually sets the program name
11 changes: 11 additions & 0 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require 'rbconfig'

class MSpecScript

def self.windows?
ENV.key?('WINDIR') || ENV.key?('windir')
end

def self.linux?
RbConfig::CONFIG['host_os'] == 'linux'
end

set :target, File.expand_path("../../../bin/jruby#{windows? ? '.bat' : ''}", __FILE__)

if ARGV[-2..-1] != %w[-t ruby] # No flags for MRI
@@ -61,6 +67,11 @@ class MSpecScript
set :xtags, (get(:xtags) || []) + ['windows']
end

if linux?
# exclude specs tagged with 'linux'
set :xtags, (get(:xtags) || []) + ['linux']
end

# Enable features
MSpec.enable_feature :fiber
MSpec.enable_feature :fiber_library
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.globals;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import jnr.ffi.Pointer;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;

import java.nio.charset.StandardCharsets;

@NodeChild(value = "value", type = RubyNode.class)
public abstract class WriteProgramNameNode extends RubyNode {

/*
* When we call _NSGetArgv we seem to always get a string that looks like what we'd expect from running ps, but
* with a null character inserted early. I don't know where this comes from, but it means I don't know how to get
* the length of space available for writing in the new program name. We therefore about 40 characters, which is
* a number without any foundation, but it at leaast allows the specs to pass, the functionality to be useful,
* and probably avoid crashing anyone's programs. I can't pretend this is great engineering.
*/
private static final int MAX_PROGRAM_NAME_LENGTH = 40;

public WriteProgramNameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization(guards = "isRubyString(value)")
protected Object writeProgramName(DynamicObject value) {
if (getContext().getCrtExterns() != null) {
final String valueString = value.toString();
final Pointer programNameAddress = getContext().getCrtExterns()._NSGetArgv().getPointer(0).getPointer(0);
programNameAddress.putString(0, valueString, MAX_PROGRAM_NAME_LENGTH, StandardCharsets.UTF_8);
}

return value;
}

}
21 changes: 21 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
import org.jruby.truffle.runtime.loader.SourceLoader;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.object.ObjectIDOperations;
import org.jruby.truffle.runtime.platform.CrtExterns;
import org.jruby.truffle.runtime.rubinius.RubiniusConfiguration;
import org.jruby.truffle.runtime.sockets.NativeSockets;
import org.jruby.truffle.runtime.subsystems.*;
@@ -62,6 +63,7 @@
import org.jruby.util.IdUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigInteger;
@@ -86,6 +88,7 @@ public class RubyContext extends ExecutionContext {
private final POSIX posix;
private final NativeSockets nativeSockets;
private final LibCClockGetTime libCClockGetTime;
private CrtExterns crtExterns;

private final CoreLibrary coreLibrary;
private final FeatureLoader featureLoader;
@@ -163,6 +166,12 @@ public RubyContext(Ruby runtime, TruffleLanguage.Env env) {

nativeSockets = LibraryLoader.create(NativeSockets.class).library("c").load();

try {
crtExterns = LibraryLoader.create(CrtExterns.class).failImmediately().library("libSystem.B.dylib").load();
} catch (UnsatisfiedLinkError e) {
crtExterns = null;
}

if (Platform.getPlatform().getOS() == OS_TYPE.LINUX) {
libCClockGetTime = LibraryLoader.create(LibCClockGetTime.class).library("c").load();
} else {
@@ -680,4 +689,16 @@ public DynamicObject createHandle(Object object) {
return Layouts.HANDLE.createHandle(coreLibrary.getHandleFactory(), object);
}

public CrtExterns getCrtExterns() {
return crtExterns;
}

public static void writeToFile(String fileName, String message) {
try (PrintStream stream = new PrintStream(fileName)) {
stream.println(message);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.runtime.platform;

import jnr.ffi.Pointer;

public interface CrtExterns {

Pointer _NSGetArgv();

}
Original file line number Diff line number Diff line change
@@ -1488,7 +1488,17 @@ public RubyNode visitGlobalAsgnNode(org.jruby.ast.GlobalAsgnNode node) {

return addNewlineIfNeeded(node, assignment);
} else {
return addNewlineIfNeeded(node, new WriteGlobalVariableNode(context, sourceSection, name, rhs));
final RubyNode writeGlobalVariableNode = new WriteGlobalVariableNode(context, sourceSection, name, rhs);

final RubyNode translated;

if (name.equals("$0")) {
translated = WriteProgramNameNodeGen.create(context, sourceSection, writeGlobalVariableNode);
} else {
translated = writeGlobalVariableNode;
}

return addNewlineIfNeeded(node, translated);
}
}