Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Re-simplify Process.getgroups.
Browse files Browse the repository at this point in the history
eregon committed Jan 6, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1812176 commit 6ca6030
Showing 2 changed files with 5 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
9 changes: 1 addition & 8 deletions truffle/src/main/ruby/core/process.rb
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6ca6030

Please sign in to comment.