Skip to content

Commit 66b5de1

Browse files
committed
refactor uname to use the same code paths as sys module
1 parent 26e55f0 commit 66b5de1

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ abstract static class UnameNode extends PythonBuiltinNode {
14091409
@Specialization
14101410
@TruffleBoundary(allowInlining = true)
14111411
PTuple uname() {
1412-
String sysname = System.getProperty("os.name", "");
1412+
String sysname = SysModuleBuiltins.getPythonOSName();
14131413
String nodename = "";
14141414
try {
14151415
InetAddress addr;
@@ -1419,11 +1419,7 @@ PTuple uname() {
14191419
}
14201420
String release = System.getProperty("os.version", "");
14211421
String version = "";
1422-
String machine = System.getProperty("os.arch", "");
1423-
if (machine.equals("amd64")) {
1424-
// be compatible with CPython's designation
1425-
machine = "x86_64";
1426-
}
1422+
String machine = SysModuleBuiltins.getPythonArch();
14271423
return factory().createTuple(new Object[]{sysname, nodename, release, version, machine});
14281424
}
14291425
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ public void initialize(PythonCore core) {
175175
1 // FLT_ROUNDS
176176
}));
177177

178+
String os = getPythonOSName();
179+
builtinConstants.put("platform", os);
180+
builtinConstants.put("__gmultiarch", getPythonArch() + "-" + os);
181+
182+
super.initialize(core);
183+
}
184+
185+
static String getPythonArch() {
186+
String arch = System.getProperty("os.arch", "");
187+
if (arch.equals("amd64")) {
188+
// be compatible with CPython's designation
189+
arch = "x86_64";
190+
}
191+
return arch;
192+
}
193+
194+
static String getPythonOSName() {
178195
String property = System.getProperty("os.name");
179196
String os = "java";
180197
if (property.toLowerCase().contains("cygwin")) {
@@ -190,12 +207,7 @@ public void initialize(PythonCore core) {
190207
} else if (property.toLowerCase().contains("freebsd")) {
191208
os = "freebsd";
192209
}
193-
builtinConstants.put("platform", os);
194-
195-
String architecture = System.getProperty("os.arch");
196-
builtinConstants.put("__gmultiarch", architecture + "-" + os);
197-
198-
super.initialize(core);
210+
return os;
199211
}
200212

201213
@Builtin(name = "exc_info", fixedNumOfPositionalArgs = 0)

0 commit comments

Comments
 (0)