]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-131032: Add support.linked_to_musl() function (#131071) (#131179)
authorVictor Stinner <vstinner@python.org>
Thu, 13 Mar 2025 09:59:57 +0000 (10:59 +0100)
committerGitHub <noreply@github.com>
Thu, 13 Mar 2025 09:59:57 +0000 (09:59 +0000)
gh-131032: Add support.linked_to_musl() function (#131071)

Skip test_math.test_fma_zero_result() if Python is linked to the musl
C library.

(cherry picked from commit 68922ace4dabb6635e6d5b51bbe6485ef2e9dad2)

Lib/test/support/__init__.py
Lib/test/test_math.py
Lib/test/test_support.py

index ff450c7f9142afaa136cb54046419f85323b25c6..f5036dd18b64ea29ff31f15ffcf742c4c9918832 100644 (file)
@@ -2767,3 +2767,22 @@ class BrokenIter:
         if self.iter_raises:
             1/0
         return self
+
+
+def linked_to_musl():
+    """
+    Test if the Python executable is linked to the musl C library.
+    """
+    if sys.platform != 'linux':
+        return False
+
+    import subprocess
+    exe = getattr(sys, '_base_executable', sys.executable)
+    cmd = ['ldd', exe]
+    try:
+        stdout = subprocess.check_output(cmd,
+                                         text=True,
+                                         stderr=subprocess.STDOUT)
+    except (OSError, subprocess.CalledProcessError):
+        return False
+    return ('musl' in stdout)
index 36b96b4c31d635485a4e10f95cfeb9afaab9973a..d309e8c1c41f1825ee997bfcf9b83e1e42c0b570 100644 (file)
@@ -2712,8 +2712,9 @@ class FMATests(unittest.TestCase):
     # gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
     # properly: it doesn't use the right sign when the result is zero.
     @unittest.skipIf(
-        sys.platform.startswith(("freebsd", "wasi", "netbsd"))
-        or (sys.platform == "android" and platform.machine() == "x86_64"),
+        sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
+        or (sys.platform == "android" and platform.machine() == "x86_64")
+        or support.linked_to_musl(),  # gh-131032
         f"this platform doesn't implement IEE 754-2008 properly")
     def test_fma_zero_result(self):
         nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]
index 4310f06924a89dc289c9020837571ed6f45c7c24..11670b06fb7664d7df535cba39738d3f9f8a19ad 100644 (file)
@@ -733,6 +733,10 @@ class TestSupport(unittest.TestCase):
         self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
                          ignored)
 
+    def test_linked_to_musl(self):
+        linked = support.linked_to_musl()
+        self.assertIsInstance(linked, bool)
+
     # XXX -follows a list of untested API
     # make_legacy_pyc
     # is_resource_enabled