Skip to content

Commit

Permalink
[Truffle] Simplify POSIX#getgroups.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Dec 15, 2016
1 parent e750435 commit 1717c08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +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})

This comment has been minimized.

Copy link
@nirvdrum

nirvdrum Dec 16, 2016

Contributor

Is this still unsafe then, since we're using a JDK method. At the very least, I'd think it's memory-safe.

This comment has been minimized.

Copy link
@eregon

eregon Dec 16, 2016

Author Member

I am not sure. @chrisseaton
We will probably switch back to using jnr posix's getgroups once it's fixed and released. Is it BTW?

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Dec 16, 2016

Contributor

Yeah the point is it does something that leaves the sandbox, so it's still unsafe.

public abstract static class GetGroupsNode extends CoreMethodArrayArgumentsNode {

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

@TruffleBoundary
@Specialization(guards = "isRubyPointer(pointer)")
public int getGroups(int max, DynamicObject pointer) {
final Pointer pointerValue = Layouts.POINTER.getPointer(pointer);
@Specialization
public DynamicObject getgroups() {
final long[] groups = getGroups();
for (int n = 0; n < groups.length; n++) {
pointerValue.putInt(4 * n, (int) groups[n]);
}
return groups.length;
return createArray(groups, groups.length);
}

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

Please sign in to comment.