]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-138130: Fix return value of libc_ver() on Emscripten (#138132)
authorHood Chatham <roberthoodchatham@gmail.com>
Sun, 31 Aug 2025 22:50:29 +0000 (00:50 +0200)
committerGitHub <noreply@github.com>
Sun, 31 Aug 2025 22:50:29 +0000 (06:50 +0800)
Emscripten's libc is a hybrid of musl and llvm libc; but it reports that it is
"glibc". This modifies the return value of `platform.libc_ver()` to return
something that is Emscripten-specific.

Lib/platform.py
Lib/test/test_platform.py

index da15bb4717bb96e26edfa41327e0383c586a0ae0..762f5d06099cf0f8d6f8af756938df9d8341f02f 100644 (file)
@@ -173,6 +173,11 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
 
     """
     if not executable:
+        if sys.platform == "emscripten":
+            # Emscripten's os.confstr reports that it is glibc, so special case
+            # it.
+            ver = ".".join(str(x) for x in sys._emscripten_info.emscripten_version)
+            return ("emscripten", ver)
         try:
             ver = os.confstr('CS_GNU_LIBC_VERSION')
             # parse 'glibc 2.28' as ('glibc', '2.28')
index 2e26134bae83231c59c20b155e2ab6083b659c2a..73d4f3cbdb689d570818f9f91d4c6eb1356b550e 100644 (file)
@@ -532,8 +532,10 @@ class PlatformTest(unittest.TestCase):
             self.assertEqual(override.model, "Whiz")
             self.assertTrue(override.is_simulator)
 
-    @unittest.skipIf(support.is_emscripten, "Does not apply to Emscripten")
     def test_libc_ver(self):
+        if support.is_emscripten:
+            assert platform.libc_ver() == ("emscripten", "4.0.12")
+            return
         # check that libc_ver(executable) doesn't raise an exception
         if os.path.isdir(sys.executable) and \
            os.path.exists(sys.executable+'.exe'):