Skip to content

Commit 5fa1a84

Browse files
committed
Implement os.getegid
Fixes #370
1 parent ddaf26c commit 5fa1a84

7 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ public void postInitialize(Python3Core core) {
372372
if (posixLib.getBackend(posixSupport).toJavaStringUncached().equals("java")) {
373373
posix.setAttribute(toTruffleStringUncached("statvfs"), PNone.NO_VALUE);
374374
posix.setAttribute(toTruffleStringUncached("geteuid"), PNone.NO_VALUE);
375+
posix.setAttribute(toTruffleStringUncached("getegid"), PNone.NO_VALUE);
375376
}
376377
}
377378

@@ -611,6 +612,15 @@ long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
611612
}
612613
}
613614

615+
@Builtin(name = "getegid", minNumOfPositionalArgs = 0)
616+
@GenerateNodeFactory
617+
public abstract static class GetEGidNode extends PythonBuiltinNode {
618+
@Specialization
619+
long getGid(@CachedLibrary(limit = "1") PosixSupportLibrary posixLib) {
620+
return posixLib.getegid(getPosixSupport());
621+
}
622+
}
623+
614624
@Builtin(name = "getppid", minNumOfPositionalArgs = 0)
615625
@GenerateNodeFactory
616626
public abstract static class GetPpidNode extends PythonBuiltinNode {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,13 @@ public long getgid() {
20472047
return 1000;
20482048
}
20492049

2050+
@ExportMessage
2051+
@SuppressWarnings("static-method")
2052+
@TruffleBoundary
2053+
public long getegid() {
2054+
throw new UnsupportedPosixFeatureException("Emulated getegid not supported");
2055+
}
2056+
20502057
@ExportMessage
20512058
@SuppressWarnings("static-method")
20522059
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
@@ -666,6 +666,12 @@ final long getgid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary
666666
return nativeLib.getgid(nativePosixSupport);
667667
}
668668

669+
@ExportMessage
670+
final long getegid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
671+
checkNotInImageBuildtime();
672+
return nativeLib.getegid(nativePosixSupport);
673+
}
674+
669675
@ExportMessage
670676
final long getppid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
671677
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
@@ -856,6 +856,13 @@ final long getgid(
856856
return logExit("getgid", "%d", lib.getgid(delegate));
857857
}
858858

859+
@ExportMessage
860+
final long getegid(
861+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
862+
logEnter("getegid", "");
863+
return logExit("getegid", "%d", lib.getegid(delegate));
864+
}
865+
859866
@ExportMessage
860867
final long getppid(
861868
@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
@@ -236,6 +236,7 @@ private enum PosixNativeFunction {
236236
call_getuid("():sint64"),
237237
call_geteuid("():sint64"),
238238
call_getgid("():sint64"),
239+
call_getegid("():sint64"),
239240
call_getppid("():sint64"),
240241
call_getpgid("(sint64):sint64"),
241242
call_setpgid("(sint64,sint64):sint32"),
@@ -1196,6 +1197,11 @@ public long getgid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
11961197
return invokeNode.callLong(this, PosixNativeFunction.call_getgid);
11971198
}
11981199

1200+
@ExportMessage
1201+
public long getegid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
1202+
return invokeNode.callLong(this, PosixNativeFunction.call_getegid);
1203+
}
1204+
11991205
@ExportMessage
12001206
public long getppid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
12011207
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
@@ -282,6 +282,8 @@ public abstract class PosixSupportLibrary extends Library {
282282

283283
public abstract long getgid(Object receiver);
284284

285+
public abstract long getegid(Object receiver);
286+
285287
public abstract long getppid(Object receiver);
286288

287289
public abstract long getpgid(Object receiver, long pid) throws PosixException;

graalpython/python-libposix/src/posix.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ int64_t call_getgid() {
581581
return getgid();
582582
}
583583

584+
int64_t call_getegid() {
585+
return getegid();
586+
}
587+
584588
int64_t call_getppid() {
585589
return getppid();
586590
}

0 commit comments

Comments
 (0)