https://github.com/python/cpython/commit/11a5fc82381308f0b6060b8c06af89fd197516e1
commit: 11a5fc82381308f0b6060b8c06af89fd197516e1
branch: main
author: Hood Chatham <[email protected]>
committer: freakboy3742 <[email protected]>
date: 2025-09-01T06:50:29+08:00
summary:

gh-138130: Fix return value of libc_ver() on Emscripten (#138132)

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.

files:
M Lib/platform.py
M Lib/test/test_platform.py

diff --git a/Lib/platform.py b/Lib/platform.py
index da15bb4717bb96..762f5d06099cf0 100644
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -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')
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index 2e26134bae8323..73d4f3cbdb689d 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -532,8 +532,10 @@ def test_ios_ver(self):
             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'):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to