]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-118943: Fix a race condition when generating jit_stencils.h (GH-118957)
authorBrandt Bucher <brandtbucher@microsoft.com>
Thu, 16 May 2024 16:11:42 +0000 (12:11 -0400)
committerGitHub <noreply@github.com>
Thu, 16 May 2024 16:11:42 +0000 (12:11 -0400)
Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst [new file with mode: 0644]
Tools/jit/_targets.py

diff --git a/Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst b/Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst
new file mode 100644 (file)
index 0000000..4e886be
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a possible race condition affecting parallel builds configured with
+``--enable-experimental-jit``, in which compilation errors could be caused
+by an incompletely-generated header file.
index b020f49cf4a2c175cefb285547bd9ebbd9e6a684..5604c429bcf8ad8f29f1ea0b03aab48ab2d93353 100644 (file)
@@ -212,13 +212,18 @@ class _Target(typing.Generic[_S, _R]):
         ):
             return
         stencil_groups = asyncio.run(self._build_stencils())
-        with jit_stencils.open("w") as file:
-            file.write(digest)
-            if comment:
-                file.write(f"// {comment}\n\n")
-            file.write("")
-            for line in _writer.dump(stencil_groups):
-                file.write(f"{line}\n")
+        jit_stencils_new = out / "jit_stencils.h.new"
+        try:
+            with jit_stencils_new.open("w") as file:
+                file.write(digest)
+                if comment:
+                    file.write(f"// {comment}\n")
+                file.write("\n")
+                for line in _writer.dump(stencil_groups):
+                    file.write(f"{line}\n")
+            jit_stencils_new.replace(jit_stencils)
+        finally:
+            jit_stencils_new.unlink(missing_ok=True)
 
 
 class _COFF(