Skip to content

Commit 181b384

Browse files
committed
[GR-45308] Add os.getgid()
PullRequest: graalpython/2709
2 parents e235634 + 85d300e commit 181b384

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

graalpython/com.oracle.graal.python.cext/posix/posix.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ int64_t call_getuid() {
545545
return getuid();
546546
}
547547

548+
int64_t call_getgid() {
549+
return getgid();
550+
}
551+
548552
int64_t call_getppid() {
549553
return getppid();
550554
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
559559
}
560560
}
561561

562+
@Builtin(name = "getgid", minNumOfPositionalArgs = 0)
563+
@GenerateNodeFactory
564+
public abstract static class GetGidNode extends PythonBuiltinNode {
565+
@Specialization
566+
long getGid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
567+
return posixLib.getgid(getPosixSupport());
568+
}
569+
}
570+
562571
@Builtin(name = "getppid", minNumOfPositionalArgs = 0)
563572
@GenerateNodeFactory
564573
public abstract static class GetPpidNode extends PythonBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,19 @@ public long getuid() {
19411941
return 1000;
19421942
}
19431943

1944+
@ExportMessage
1945+
@SuppressWarnings("static-method")
1946+
@TruffleBoundary
1947+
public long getgid() {
1948+
if (!PythonOptions.WITHOUT_PLATFORM_ACCESS) {
1949+
String osName = System.getProperty("os.name");
1950+
if (osName.contains("Linux")) {
1951+
return new UnixSystem().getGid();
1952+
}
1953+
}
1954+
return 1000;
1955+
}
1956+
19441957
@ExportMessage
19451958
@SuppressWarnings("static-method")
19461959
public long getppid() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ImageBuildtimePosixSupport.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ final long getuid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary
622622
return nativeLib.getuid(nativePosixSupport);
623623
}
624624

625+
@ExportMessage
626+
final long getgid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
627+
checkNotInImageBuildtime();
628+
return nativeLib.getgid(nativePosixSupport);
629+
}
630+
625631
@ExportMessage
626632
final long getppid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
627633
checkNotInImageBuildtime();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/LoggingPosixSupport.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,13 @@ final long getuid(
794794
return logExit("getuid", "%d", lib.getuid(delegate));
795795
}
796796

797+
@ExportMessage
798+
final long getgid(
799+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
800+
logEnter("getgid", "");
801+
return logExit("getgid", "%d", lib.getgid(delegate));
802+
}
803+
797804
@ExportMessage
798805
final long getppid(
799806
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIPosixSupport.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ private enum PosixNativeFunction {
205205
call_wtermsig("(sint32):sint32"),
206206
call_wstopsig("(sint32):sint32"),
207207
call_getuid("():sint64"),
208+
call_getgid("():sint64"),
208209
call_getppid("():sint64"),
209210
call_getsid("(sint64):sint64"),
210211
call_ctermid("([sint8]):sint32"),
@@ -1090,6 +1091,11 @@ public long getuid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
10901091
return invokeNode.callLong(this, PosixNativeFunction.call_getuid);
10911092
}
10921093

1094+
@ExportMessage
1095+
public long getgid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
1096+
return invokeNode.callLong(this, PosixNativeFunction.call_getgid);
1097+
}
1098+
10931099
@ExportMessage
10941100
public long getppid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
10951101
return invokeNode.callLong(this, PosixNativeFunction.call_getppid);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixSupportLibrary.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ public abstract class PosixSupportLibrary extends Library {
270270

271271
public abstract long getuid(Object receiver);
272272

273+
public abstract long getgid(Object receiver);
274+
273275
public abstract long getppid(Object receiver);
274276

275277
public abstract long getsid(Object receiver, long pid) throws PosixException;

0 commit comments

Comments
 (0)