Skip to content

Commit

Permalink
[Truffle] Re-simplify Process.getgroups.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 6, 2017
1 parent 1812176 commit 6ca6030
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
Expand Up @@ -182,29 +182,13 @@ public int getGID() {

}

@CoreMethod(names = "getgroups", isModuleFunction = true, required = 2, lowerFixnum = 1, unsafe = {UnsafeGroup.MEMORY, UnsafeGroup.PROCESSES})
@CoreMethod(names = "getgroups", isModuleFunction = true, unsafe = { UnsafeGroup.MEMORY, UnsafeGroup.PROCESSES })
public abstract static class GetGroupsNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isNil(pointer)")
public int getGroupsNil(int max, DynamicObject pointer) {
return getContext().getNativePlatform().getPosix().getgroups().length;
}

@TruffleBoundary
@Specialization(guards = "isRubyPointer(pointer)")
public int getGroups(int max, DynamicObject pointer) {
@Specialization
public DynamicObject getGroups() {
final long[] groups = getContext().getNativePlatform().getPosix().getgroups();

final Pointer pointerValue = Layouts.POINTER.getPointer(pointer);

for (int n = 0; n < groups.length && n < max; n++) {
// TODO CS 16-May-15 this is platform dependent
pointerValue.putInt(4 * n, (int) groups[n]);

}

return groups.length;
return createArray(groups, groups.length);
}

}
Expand Down
9 changes: 1 addition & 8 deletions truffle/src/main/ruby/core/process.rb
Expand Up @@ -431,14 +431,7 @@ def self.setpriority(kind, id, priority)
end

def self.groups
g = []
count = Truffle::POSIX.getgroups(0, nil)
FFI::MemoryPointer.new(:int, count) do |p|
num_groups = Truffle::POSIX.getgroups(count, p)
Errno.handle if num_groups == -1
g = p.read_array_of_int(num_groups)
end
g
Truffle::POSIX.getgroups
end

def self.groups=(g)
Expand Down

0 comments on commit 6ca6030

Please sign in to comment.