From 8ad8107c8d40fca68dbb901b728223fec946f16d Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 5 Nov 2025 23:42:35 -0500 Subject: [PATCH] Mark `earlyCWD` (OpenBSD-only) `constinit` and fix some comments/style. --- Sources/_TestingInternals/ExecutablePath.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/_TestingInternals/ExecutablePath.cpp b/Sources/_TestingInternals/ExecutablePath.cpp index 0d23653f6..7213cfa75 100644 --- a/Sources/_TestingInternals/ExecutablePath.cpp +++ b/Sources/_TestingInternals/ExecutablePath.cpp @@ -1,7 +1,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -13,7 +13,8 @@ #include #if defined(__OpenBSD__) -static std::atomic earlyCWD { nullptr }; +/// Storage for ``swt_getEarlyCWD()``. +static constinit std::atomic earlyCWD { nullptr }; /// At process start (before `main()` is called), capture the current working /// directory. @@ -22,7 +23,7 @@ static std::atomic earlyCWD { nullptr }; /// possible) resolve the executable path when the first argument is a relative /// path (which can occur when manually invoking the test executable.) __attribute__((__constructor__(101), __used__)) -static void swt_captureEarlyCWD(void) { +static void captureEarlyCWD(void) { static char buffer[PATH_MAX * 2]; if (getcwd(buffer, sizeof(buffer))) { earlyCWD.store(buffer);