GeezerVison is showing github.com — Implement native sys.getwindowsversion · oracle/graalpython@558531e
File treeExpand file treeCollapse file tree Open diff view settings com.oracle.graal.python.test/src/tests com.oracle.graal.python/src/com/oracle/graal/python
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +135Lines changed: 135 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | | 2 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | | 3 | +# | | 4 | +# The Universal Permissive License (UPL), Version 1.0 | | 5 | +# | | 6 | +# Subject to the condition set forth below, permission is hereby granted to any | | 7 | +# person obtaining a copy of this software, associated documentation and/or | | 8 | +# data (collectively the "Software"), free of charge and under any and all | | 9 | +# copyright rights in the Software, and any and all patent rights owned or | | 10 | +# freely licensable by each licensor hereunder covering either (i) the | | 11 | +# unmodified Software as contributed to or provided by such licensor, or (ii) | | 12 | +# the Larger Works (as defined below), to deal in both | | 13 | +# | | 14 | +# (a) the Software, and | | 15 | +# | | 16 | +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | | 17 | +# one is included with the Software each a "Larger Work" to which the Software | | 18 | +# is contributed by such licensors), | | 19 | +# | | 20 | +# without restriction, including without limitation the rights to copy, create | | 21 | +# derivative works of, display, perform, and distribute the Software and make, | | 22 | +# use, sell, offer for sale, import, export, have made, and have sold the | | 23 | +# Software and the Larger Work(s), and to sublicense the foregoing rights on | | 24 | +# either these or other terms. | | 25 | +# | | 26 | +# This license is subject to the following condition: | | 27 | +# | | 28 | +# The above copyright notice and either this complete permission notice or at a | | 29 | +# minimum a reference to the UPL must be included in all copies or substantial | | 30 | +# portions of the Software. | | 31 | +# | | 32 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | | 33 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | | 34 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | | 35 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | | 36 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | | 37 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | | 38 | +# SOFTWARE. | | 39 | + | | 40 | +import subprocess | | 41 | +import sys | | 42 | +import unittest | | 43 | + | | 44 | + | | 45 | +@unittest.skipUnless(sys.platform == "win32", "Windows only") | | 46 | +class WindowsVersionTests(unittest.TestCase): | | 47 | + def test_getwindowsversion_matches_os(self): | | 48 | + if sys.implementation.name == "graalpy" and __graalpython__.posix_module_backend() == "java": | | 49 | + self.skipTest("The Java backend uses the Java OS version property") | | 50 | + import ctypes | | 51 | + from ctypes import wintypes | | 52 | + | | 53 | + class VersionInfo(ctypes.Structure): | | 54 | + _fields_ = [ | | 55 | + ("size", wintypes.DWORD), | | 56 | + ("major", wintypes.DWORD), | | 57 | + ("minor", wintypes.DWORD), | | 58 | + ("build", wintypes.DWORD), | | 59 | + ("platform", wintypes.DWORD), | | 60 | + ("service_pack", wintypes.WCHAR * 128), | | 61 | + ("service_pack_major", wintypes.WORD), | | 62 | + ("service_pack_minor", wintypes.WORD), | | 63 | + ("suite_mask", wintypes.WORD), | | 64 | + ("product_type", wintypes.BYTE), | | 65 | + ("reserved", wintypes.BYTE), | | 66 | + ] | | 67 | + | | 68 | + kernel32 = ctypes.WinDLL("kernel32", use_last_error=True) | | 69 | + get_version = kernel32.GetVersionExW | | 70 | + get_version.argtypes = [ctypes.POINTER(VersionInfo)] | | 71 | + get_version.restype = wintypes.BOOL | | 72 | + native_version = VersionInfo() | | 73 | + native_version.size = ctypes.sizeof(native_version) | | 74 | + self.assertTrue(get_version(ctypes.byref(native_version))) | | 75 | + | | 76 | + version = sys.getwindowsversion() | | 77 | + expected = (native_version.major, native_version.minor, native_version.build) | | 78 | + self.assertEqual(version[:3], expected) | | 79 | + self.assertEqual(version.platform, native_version.platform) | | 80 | + self.assertEqual(version.service_pack, native_version.service_pack) | | 81 | + self.assertEqual(version.service_pack_major, native_version.service_pack_major) | | 82 | + self.assertEqual(version.service_pack_minor, native_version.service_pack_minor) | | 83 | + self.assertEqual(version.suite_mask, native_version.suite_mask) | | 84 | + self.assertEqual(version.product_type, native_version.product_type) | | 85 | + self.assertGreater(version.build, 0) | | 86 | + | | 87 | + class FixedFileInfo(ctypes.Structure): | | 88 | + _fields_ = [(name, wintypes.DWORD) for name in ( | | 89 | + "signature", "struc_version", "file_version_ms", "file_version_ls", | | 90 | + "product_version_ms", "product_version_ls", "file_flags_mask", "file_flags", | | 91 | + "file_os", "file_type", "file_subtype", "file_date_ms", "file_date_ls", | | 92 | + )] | | 93 | + | | 94 | + get_module_handle = kernel32.GetModuleHandleW | | 95 | + get_module_handle.argtypes = [wintypes.LPCWSTR] | | 96 | + get_module_handle.restype = wintypes.HMODULE | | 97 | + get_module_filename = kernel32.GetModuleFileNameW | | 98 | + get_module_filename.argtypes = [wintypes.HMODULE, wintypes.LPWSTR, wintypes.DWORD] | | 99 | + get_module_filename.restype = wintypes.DWORD | | 100 | + path = ctypes.create_unicode_buffer(260) | | 101 | + self.assertTrue(get_module_filename(get_module_handle("kernel32.dll"), path, len(path))) | | 102 | + version_dll = ctypes.WinDLL("version", use_last_error=True) | | 103 | + get_size = version_dll.GetFileVersionInfoSizeW | | 104 | + get_size.argtypes = [wintypes.LPCWSTR, ctypes.POINTER(wintypes.DWORD)] | | 105 | + get_size.restype = wintypes.DWORD | | 106 | + size = get_size(path.value, None) | | 107 | + self.assertGreater(size, 0) | | 108 | + block = ctypes.create_string_buffer(size) | | 109 | + get_info = version_dll.GetFileVersionInfoW | | 110 | + get_info.argtypes = [wintypes.LPCWSTR, wintypes.DWORD, wintypes.DWORD, wintypes.LPVOID] | | 111 | + get_info.restype = wintypes.BOOL | | 112 | + self.assertTrue(get_info(path.value, 0, size, block)) | | 113 | + query_value = version_dll.VerQueryValueW | | 114 | + query_value.argtypes = [wintypes.LPCVOID, wintypes.LPCWSTR, ctypes.POINTER(ctypes.c_void_p), | | 115 | + ctypes.POINTER(wintypes.UINT)] | | 116 | + query_value.restype = wintypes.BOOL | | 117 | + value = ctypes.c_void_p() | | 118 | + length = wintypes.UINT() | | 119 | + self.assertTrue(query_value(block, "", ctypes.byref(value), ctypes.byref(length))) | | 120 | + info = ctypes.cast(value, ctypes.POINTER(FixedFileInfo)).contents | | 121 | + self.assertEqual(version.platform_version, ( | | 122 | + info.product_version_ms >> 16, info.product_version_ms & 0xffff, info.product_version_ls >> 16, | | 123 | + )) | | 124 | + | | 125 | + @unittest.skipUnless(sys.implementation.name == "graalpy", "GraalPy backend selection") | | 126 | + def test_getwindowsversion_java_backend(self): | | 127 | + for java_version, expected in [("10.0", (10, 0, 0)), ("10.0.12345", (10, 0, 12345))]: | | 128 | + with self.subTest(java_version=java_version): | | 129 | + result = subprocess.run( | | 130 | + [sys.executable, "--experimental-options", "--python.PosixModuleBackend=java", | | 131 | + "--vm.Dos.version=" + java_version, "-c", | | 132 | + "import sys; print(sys.getwindowsversion()[:3]); print(sys.getwindowsversion().platform_version)"], | | 133 | + capture_output=True, text=True, check=True, | | 134 | + ) | | 135 | + self.assertEqual(result.stdout.splitlines(), [str(expected), str(expected)]) |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 82 | 82 | import com.oracle.graal.python.compiler.ParserCallbacksImpl; | 83 | 83 | import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler; | 84 | 84 | import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler.BytecodeDSLCompilerResult; | | 85 | +import com.oracle.graal.python.nodes.PConstructAndRaiseNode; | 85 | 86 | import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; | 86 | 87 | import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; | 87 | 88 | import com.oracle.graal.python.nodes.call.CallDispatchers; | | 102 | 103 | import com.oracle.graal.python.runtime.GilNode; | 103 | 104 | import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; | 104 | 105 | import com.oracle.graal.python.runtime.IndirectCallData.InteropCallData; | | 106 | +import com.oracle.graal.python.runtime.PosixSupportLibrary; | | 107 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.PosixException; | | 108 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.WindowsVersion; | 105 | 109 | import com.oracle.graal.python.runtime.PythonContext; | 106 | 110 | import com.oracle.graal.python.runtime.PythonContext.PythonThreadState; | 107 | 111 | import com.oracle.graal.python.runtime.PythonImageBuildOptions; | | 140 | 144 | import com.oracle.truffle.api.library.ExportLibrary; | 141 | 145 | import com.oracle.truffle.api.library.ExportMessage; | 142 | 146 | import com.oracle.truffle.api.nodes.DirectCallNode; | | 147 | +import com.oracle.truffle.api.nodes.EncapsulatingNodeReference; | 143 | 148 | import com.oracle.truffle.api.nodes.ExecutableNode; | 144 | 149 | import com.oracle.truffle.api.nodes.Node; | 145 | 150 | import com.oracle.truffle.api.nodes.RootNode; | @@ -1063,6 +1068,27 @@ public CaseMap.Title getCachedICUTitleCaser() { | 1063 | 1068 | return cachedICUTitleCaser; | 1064 | 1069 | } | 1065 | 1070 |
| | 1071 | + @CompilationFinal private WindowsVersion windowsVersion; | | 1072 | + | | 1073 | + public WindowsVersion getWindowsVersion(Node node) { | | 1074 | + if (windowsVersion == null) { | | 1075 | + CompilerDirectives.transferToInterpreterAndInvalidate(); | | 1076 | + assert !ImageInfo.inImageBuildtimeCode(); | | 1077 | + try { | | 1078 | + windowsVersion = PosixSupportLibrary.getUncached().getWindowsVersion(PythonContext.get(node).getPosixSupport()); | | 1079 | + } catch (PosixException e) { | | 1080 | + EncapsulatingNodeReference encapsulating = EncapsulatingNodeReference.getCurrent(); | | 1081 | + Node previousNode = encapsulating.set(node); | | 1082 | + try { | | 1083 | + throw PConstructAndRaiseNode.getUncached().raiseOSErrorFromPosixException(null, e); | | 1084 | + } finally { | | 1085 | + encapsulating.set(previousNode); | | 1086 | + } | | 1087 | + } | | 1088 | + } | | 1089 | + return windowsVersion; | | 1090 | + } | | 1091 | + | 1066 | 1092 | @Override | 1067 | 1093 | protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) { | 1068 | 1094 | if (singleThreaded) { | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java +15-41Lines changed: 15 additions & 41 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 255 | 255 | import com.oracle.graal.python.runtime.GilNode; | 256 | 256 | import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; | 257 | 257 | import com.oracle.graal.python.runtime.PosixSupportLibrary; | | 258 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.WindowsVersion; | 258 | 259 | import com.oracle.graal.python.runtime.PythonContext; | 259 | 260 | import com.oracle.graal.python.runtime.PythonContext.CApiState; | 260 | 261 | import com.oracle.graal.python.runtime.PythonOptions; | @@ -2432,50 +2433,23 @@ protected ArgumentClinicProvider getArgumentClinic() { | 2432 | 2433 |
| 2433 | 2434 | @Builtin(name = "getwindowsversion", minNumOfPositionalArgs = 0, os = PLATFORM_WIN32) | 2434 | 2435 | @GenerateNodeFactory | 2435 | | - abstract static class Getwindowsversion extends PythonBuiltinNode { | 2436 | | - static int[] CACHED_VERSION_INFO = null; | 2437 | | - static int PLATFORM = 2; | | 2436 | + abstract static class GetWindowsVersion extends PythonBuiltinNode { | | 2437 | + @Specialization(guards = "isSingleContext()") | | 2438 | + static PTuple getVersionCached( | | 2439 | + @Bind PythonLanguage language, | | 2440 | + @Cached(value = "getVersion($node, language)", neverDefault = true) PTuple version) { | | 2441 | + return version; | | 2442 | + } | 2438 | 2443 |
| 2439 | | - @Specialization | 2440 | | - PTuple getVersion( | | 2444 | + @Specialization(replaces = "getVersionCached") | | 2445 | + static PTuple getVersion( | | 2446 | + @Bind Node inliningTarget, | 2441 | 2447 | @Bind PythonLanguage language) { | 2442 | | - if (CACHED_VERSION_INFO == null) { | 2443 | | - cacheVersion(); | 2444 | | - } | | 2448 | + WindowsVersion versionInfo = language.getWindowsVersion(inliningTarget); | 2445 | 2449 | return PFactory.createStructSeq(language, WINDOWS_VER_DESC, | 2446 | | - CACHED_VERSION_INFO[0], CACHED_VERSION_INFO[1], CACHED_VERSION_INFO[2], | 2447 | | - PLATFORM, T_EMPTY_STRING, 0, 0, 0, 1, | 2448 | | - PFactory.createTuple(language, CACHED_VERSION_INFO)); | 2449 | | - } | 2450 | | - | 2451 | | - @TruffleBoundary | 2452 | | - static void cacheVersion() { | 2453 | | - String[] winvers = System.getProperty("os.version", "10.0.20000").split("\\."); | 2454 | | - int major = 0; | 2455 | | - int minor = 0; | 2456 | | - int build = 0; | 2457 | | - if (winvers.length > 0) { | 2458 | | - try { | 2459 | | - major = Integer.parseInt(winvers[0]); | 2460 | | - } catch (NumberFormatException e) { | 2461 | | - // use default | 2462 | | - } | 2463 | | - } | 2464 | | - if (winvers.length > 1) { | 2465 | | - try { | 2466 | | - minor = Integer.parseInt(winvers[1]); | 2467 | | - } catch (NumberFormatException e) { | 2468 | | - // use default | 2469 | | - } | 2470 | | - } | 2471 | | - if (winvers.length > 2) { | 2472 | | - try { | 2473 | | - build = Integer.parseInt(winvers[2]); | 2474 | | - } catch (NumberFormatException e) { | 2475 | | - // use default | 2476 | | - } | 2477 | | - } | 2478 | | - CACHED_VERSION_INFO = new int[]{major, minor, build}; | | 2450 | + versionInfo.major(), versionInfo.minor(), versionInfo.build(), | | 2451 | + versionInfo.platform(), versionInfo.servicePack(), versionInfo.servicePackMajor(), versionInfo.servicePackMinor(), versionInfo.suiteMask(), versionInfo.productType(), | | 2452 | + PFactory.createTuple(language, new int[]{versionInfo.platformMajor(), versionInfo.platformMinor(), versionInfo.platformBuild()})); | 2479 | 2453 | } | 2480 | 2454 | } | 2481 | 2455 | } |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 250 | 250 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddrLibrary; | 251 | 251 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UnixSockAddr; | 252 | 252 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UnsupportedPosixFeatureException; | | 253 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.WindowsVersion; | 253 | 254 | import com.oracle.graal.python.runtime.exception.PythonExitException; | 254 | 255 | import com.oracle.graal.python.util.FileDeleteShutdownHook; | 255 | 256 | import com.oracle.graal.python.util.IPAddressUtil; | @@ -1515,6 +1516,38 @@ public Object[] uname( | 1515 | 1516 | }; | 1516 | 1517 | } | 1517 | 1518 |
| | 1519 | + @ExportMessage | | 1520 | + @TruffleBoundary | | 1521 | + @SuppressWarnings("static-method") | | 1522 | + public WindowsVersion getWindowsVersion() { | | 1523 | + String[] winvers = System.getProperty("os.version", "10.0.20000").split("\\."); | | 1524 | + int major = 0; | | 1525 | + int minor = 0; | | 1526 | + int build = 0; | | 1527 | + if (winvers.length > 0) { | | 1528 | + try { | | 1529 | + major = Integer.parseInt(winvers[0]); | | 1530 | + } catch (NumberFormatException e) { | | 1531 | + // use default | | 1532 | + } | | 1533 | + } | | 1534 | + if (winvers.length > 1) { | | 1535 | + try { | | 1536 | + minor = Integer.parseInt(winvers[1]); | | 1537 | + } catch (NumberFormatException e) { | | 1538 | + // use default | | 1539 | + } | | 1540 | + } | | 1541 | + if (winvers.length > 2) { | | 1542 | + try { | | 1543 | + build = Integer.parseInt(winvers[2]); | | 1544 | + } catch (NumberFormatException e) { | | 1545 | + // use default | | 1546 | + } | | 1547 | + } | | 1548 | + return new WindowsVersion(major, minor, build, 2, T_EMPTY_STRING, 0, 0, 0, 1, major, minor, build); | | 1549 | + } | | 1550 | + | 1518 | 1551 | @TruffleBoundary | 1519 | 1552 | private static String getOsVersion() { | 1520 | 1553 | return System.getProperty("os.version", ""); | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/LoggingPosixSupport.java +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 65 | 65 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddr; | 66 | 66 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UnixSockAddr; | 67 | 67 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UnsupportedPosixFeatureException; | | 68 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.WindowsVersion; | 68 | 69 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | 69 | 70 | import com.oracle.truffle.api.RootCallTarget; | 70 | 71 | import com.oracle.truffle.api.Truffle; | @@ -485,6 +486,17 @@ final Object[] uname( | 485 | 486 | } | 486 | 487 | } | 487 | 488 |
| | 489 | + @ExportMessage | | 490 | + final WindowsVersion getWindowsVersion( | | 491 | + @CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException { | | 492 | + logEnter("getWindowsVersion", ""); | | 493 | + try { | | 494 | + return logExit("getWindowsVersion", "%s", lib.getWindowsVersion(delegate)); | | 495 | + } catch (PosixException e) { | | 496 | + throw logException("getWindowsVersion", e); | | 497 | + } | | 498 | + } | | 499 | + | 488 | 500 | @ExportMessage | 489 | 501 | final void unlinkat(int dirFd, Object pathname, boolean rmdir, | 490 | 502 | @CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException { | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 123 | 123 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddr; | 124 | 124 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UniversalSockAddrLibrary; | 125 | 125 | import com.oracle.graal.python.runtime.PosixSupportLibrary.UnixSockAddr; | | 126 | +import com.oracle.graal.python.runtime.PosixSupportLibrary.WindowsVersion; | 126 | 127 | import com.oracle.graal.python.runtime.exception.PException; | 127 | 128 | import com.oracle.graal.python.runtime.nativeaccess.NativeLibrary; | 128 | 129 | import com.oracle.graal.python.runtime.nativeaccess.NativeLibraryLoadException; | @@ -290,6 +291,9 @@ abstract static class PosixNativeFunctionInvoker { | 290 | 291 | @DowncallSignature(returnType = SINT32, argumentTypes = {POINTER, POINTER, POINTER, POINTER, POINTER, SINT32}) | 291 | 292 | abstract int call_uname(long sysname, long nodename, long release, long version, long machine, int size); | 292 | 293 |
| | 294 | + @DowncallSignature(returnType = SINT32, argumentTypes = {POINTER, POINTER}) | | 295 | + abstract int call_get_windows_version(long out, long servicePack); | | 296 | + | 293 | 297 | @DowncallSignature(returnType = SINT32, argumentTypes = {SINT32, POINTER, SINT32}) | 294 | 298 | abstract int call_unlinkat(int dirFd, long pathname, int rmdir); | 295 | 299 |
| @@ -1176,6 +1180,27 @@ public Object[] uname( | 1176 | 1180 | } | 1177 | 1181 | } | 1178 | 1182 |
| | 1183 | + @ExportMessage | | 1184 | + @TruffleBoundary | | 1185 | + public WindowsVersion getWindowsVersion() throws PosixException { | | 1186 | + long out = NativeMemory.mallocIntArray(11); | | 1187 | + // OSVERSIONINFOEXW.szCSDVersion contains 128 UTF-16 code units. | | 1188 | + long servicePack = NativeMemory.mallocByteArray(256); | | 1189 | + try { | | 1190 | + if (posixNativeFunctionInvoker.call_get_windows_version(out, servicePack) != 0) { | | 1191 | + throw getErrnoAndThrowPosixException(); | | 1192 | + } | | 1193 | + int[] info = NativeMemory.readIntArrayElements(out, 0, 11); | | 1194 | + byte[] buffer = new byte[256]; | | 1195 | + NativeMemory.readByteArrayElements(servicePack, 0, buffer, 0, buffer.length); | | 1196 | + TruffleString servicePackString = TruffleString.fromByteArrayUncached(buffer, 0, findWideZero(buffer), UTF_16LE, false).switchEncodingUncached(TS_ENCODING); | | 1197 | + return new WindowsVersion(info[0], info[1], info[2], info[3], servicePackString, info[4], info[5], info[6], info[7], info[8], info[9], info[10]); | | 1198 | + } finally { | | 1199 | + NativeMemory.free(servicePack); | | 1200 | + NativeMemory.free(out); | | 1201 | + } | | 1202 | + } | | 1203 | + | 1179 | 1204 | @ExportMessage | 1180 | 1205 | public void unlinkat(int dirFd, Object pathname, boolean rmdir) throws PosixException { | 1181 | 1206 | long pathnamePtr = pathToNativeCString(pathname); | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixSupportLibrary.java +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -158,6 +158,14 @@ public abstract class PosixSupportLibrary extends Library { | 158 | 158 |
| 159 | 159 | public abstract Object[] uname(Object receiver) throws PosixException; | 160 | 160 |
| | 161 | + public record WindowsVersion(int major, int minor, int build, int platform, TruffleString servicePack, | | 162 | + int servicePackMajor, int servicePackMinor, int suiteMask, int productType, | | 163 | + int platformMajor, int platformMinor, int platformBuild) { | | 164 | + } | | 165 | + | | 166 | + /** Returns the Windows version and product information. */ | | 167 | + public abstract WindowsVersion getWindowsVersion(Object receiver) throws PosixException; | | 168 | + | 161 | 169 | public abstract void unlinkat(Object receiver, int dirFd, Object pathname, boolean rmdir) throws PosixException; | 162 | 170 |
| 163 | 171 | public abstract void linkat(Object receiver, int oldFdDir, Object oldPath, int newFdDir, Object newPath, int flags) throws PosixException; | |
|