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

Commits on Apr 17, 2015

  1. Unverified

    No user is associated with the committer email.
    Copy the full SHA
    87be3a7 View commit details
  2. Copy the full SHA
    bb94fb0 View commit details
  3. Copy the full SHA
    0484d31 View commit details
  4. Copy the full SHA
    210148c View commit details
Original file line number Diff line number Diff line change
@@ -69,7 +69,6 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, BindingNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, BignumNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ClassNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, DirNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ExceptionNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, FalseClassNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, FiberNodesFactory.getFactories());
136 changes: 0 additions & 136 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/DirNodes.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@
import org.jruby.util.unsafe.UnsafeHolder;
import sun.misc.Unsafe;

import java.nio.charset.StandardCharsets;

@CoreClass(name = "Rubinius::FFI::Platform::POSIX")
public abstract class PosixNodes {

@@ -187,4 +189,70 @@ public int mkdir(RubyString path, int mode) {

}

@CoreMethod(names = "chdir", isModuleFunction = true, required = 1)
public abstract static class ChdirNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {

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

public ChdirNode(ChdirNode prev) {
super(prev);
}

@Specialization
public int chdir(RubyString path) {
final String pathString = path.toString();

final int result = getContext().getRuntime().getPosix().chdir(pathString);

if (result == 0) {
getContext().getRuntime().setCurrentDirectory(pathString);
}

return result;
}

}

@CoreMethod(names = "rmdir", isModuleFunction = true, required = 1)
public abstract static class RmdirNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {

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

public RmdirNode(RmdirNode prev) {
super(prev);
}

@Specialization
public int rmdir(RubyString path) {
return getContext().getRuntime().getPosix().rmdir(path.toString());
}

}

@CoreMethod(names = "getcwd", isModuleFunction = true, required = 2)
public abstract static class GetcwdNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {

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

public GetcwdNode(GetcwdNode prev) {
super(prev);
}

@Specialization
public RubyString getcwd(RubyString resultPath, int maxSize) {
// We just ignore maxSize - I think this is ok

final String path = getContext().getRuntime().getCurrentDirectory();
resultPath.getByteList().replace(path.getBytes(StandardCharsets.UTF_8));
return resultPath;
}

}

}
Original file line number Diff line number Diff line change
@@ -1115,6 +1115,18 @@ public StringPatternPrimitiveNode(StringPatternPrimitiveNode prev) {
super(prev);
}

@Specialization(guards = "isZero(arguments[1]))")
public RubyString stringPatternZero(RubyClass stringClass, int size, int value) {
return new RubyString(stringClass, new ByteList(new byte[size]));
}

@Specialization(guards = "!isZero(arguments[1]))")
public RubyString stringPattern(RubyClass stringClass, int size, int value) {
final byte[] bytes = new byte[size];
Arrays.fill(bytes, (byte) value);
return new RubyString(stringClass, new ByteList(bytes));
}

@Specialization
public RubyString stringPattern(RubyClass stringClass, int size, RubyString string) {
final byte[] bytes = new byte[size];
@@ -1129,6 +1141,10 @@ public RubyString stringPattern(RubyClass stringClass, int size, RubyString stri
return new RubyString(stringClass, new ByteList(bytes));
}

protected boolean isZero(int value) {
return value == 0;
}

}

@RubiniusPrimitive(name = "string_to_inum")
3 changes: 3 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/rubinius.rb
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ class DynamicLibrary
end
end

# jnr-posix hard codes this value
PATH_MAX = 1024

end

class PrimitiveFailure < StandardError
54 changes: 54 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/dir.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@

class Dir

# This seems silly, I know. But we do this to make Dir more resistent to people
# screwing with ::File later (ie, fakefs)
PrivateFile = ::File

FFI = Rubinius::FFI

def self.[](*patterns)
@@ -90,4 +94,54 @@ def self.mkdir(path, mode = 0777)
error
end

def self.chdir(path = ENV['HOME'])
path = Rubinius::Type.coerce_to_path path

if block_given?
original_path = self.getwd
error = FFI::Platform::POSIX.chdir path
Errno.handle(path) if error != 0

begin
value = yield path
ensure
error = FFI::Platform::POSIX.chdir original_path
Errno.handle(original_path) if error != 0
end

return value
else
error = FFI::Platform::POSIX.chdir path
Errno.handle path if error != 0
error
end
end

def self.rmdir(path)
error = FFI::Platform::POSIX.rmdir(Rubinius::Type.coerce_to_path(path))
Errno.handle path if error != 0
error
end

def self.getwd
buf = String.pattern Rubinius::PATH_MAX, 0
wd = FFI::Platform::POSIX.getcwd(buf, buf.length)
Errno.handle unless wd
Rubinius::Type.external_string wd
end

class << self
alias_method :pwd, :getwd
alias_method :delete, :rmdir
alias_method :unlink, :rmdir
end

def self.exist?(path)
PrivateFile.directory?(path)
end

class << self
alias_method :exists?, :exist?
end

end