Skip to content

Commit

Permalink
Showing 3 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1822,27 +1822,6 @@ private void undefMethod(VirtualFrame frame, RubyModule module, String name) {

}

@CoreMethod(names = "get_user_home", needsSelf = false, required = 1)
public abstract static class GetUserHomeNode extends CoreMethodArrayArgumentsNode {

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

@Specialization
public RubyBasicObject userHome(RubyString uname) {
CompilerDirectives.transferToInterpreter();
// TODO BJF 30-APR-2015 Review the more robust getHomeDirectoryPath implementation
final Passwd passwd = getContext().getPosix().getpwnam(uname.toString());
if (passwd == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("user " + uname.toString() + " does not exist", this));
}
return createString(passwd.getHome());
}

}

@NodeChildren({ @NodeChild(value = "module"), @NodeChild(value = "names") })
public abstract static class SetVisibilityNode extends RubyNode {

Original file line number Diff line number Diff line change
@@ -42,8 +42,11 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import jnr.constants.platform.Sysconf;
import jnr.posix.Passwd;
import jnr.posix.Times;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.*;
@@ -62,6 +65,7 @@
import org.jruby.truffle.runtime.signal.SignalOperations;
import org.jruby.truffle.runtime.subsystems.ThreadManager;
import org.jruby.util.io.PosixShim;

import sun.misc.Signal;

import java.lang.management.ManagementFactory;
@@ -165,6 +169,27 @@ public RubyBasicObject vmGetModuleName(RubyModule module) {

}

@RubiniusPrimitive(name = "vm_get_user_home", needsSelf = false)
public abstract static class VMGetUserHomePrimitiveNode extends RubiniusPrimitiveNode {

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

@Specialization
public RubyBasicObject vmGetUserHome(RubyString username) {
CompilerDirectives.transferToInterpreter();
// TODO BJF 30-APR-2015 Review the more robust getHomeDirectoryPath implementation
final Passwd passwd = getContext().getPosix().getpwnam(username.toString());
if (passwd == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("user " + username.toString() + " does not exist", this));
}
return createString(passwd.getHome());
}

}

@RubiniusPrimitive(name = "vm_object_class", needsSelf = false)
public static abstract class VMObjectClassPrimitiveNode extends RubiniusPrimitiveNode {

5 changes: 5 additions & 0 deletions truffle/src/main/ruby/core/rubinius/bootstrap/rubinius.rb
Original file line number Diff line number Diff line change
@@ -58,4 +58,9 @@ def self.set_class(obj, cls)
raise ArgumentError, "Class #{cls} is not compatible with #{obj.inspect}"
end
end

def self.get_user_home(name)
Rubinius.primitive :vm_get_user_home
raise PrimitiveFailure, "Rubinius.get_user_home primitive failed"
end
end

0 comments on commit bae6fd0

Please sign in to comment.