Skip to content

Commit 6716c04

Browse files
committed
runtime: re-order environment variable lookup
Hoist the no environment case over the case with the environment. This ensures that if no environment configuration is selected, the code still builds. If no environment configuration is selected, `ENVIRON` may still be defined and that results in calls to elided functions.
1 parent b748546 commit 6716c04

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ extern "C" char **_environ;
187187
#endif
188188
#endif
189189

190-
#ifdef ENVIRON
190+
#if !SWIFT_STDLIB_HAS_ENVIRON
191+
void swift::runtime::environment::initialize(void *context) {
192+
(void)context;
193+
}
194+
#elif defined(ENVIRON)
191195
void swift::runtime::environment::initialize(void *context) {
192196
// On platforms where we have an environment variable array available, scan it
193197
// directly. This optimizes for the common case where no variables are set,
@@ -241,7 +245,7 @@ void swift::runtime::environment::initialize(void *context) {
241245
if (SWIFT_DEBUG_HELP_variable)
242246
printHelp(nullptr);
243247
}
244-
#elif SWIFT_STDLIB_HAS_ENVIRON
248+
#else
245249
void swift::runtime::environment::initialize(void *context) {
246250
// Emit a getenv call for each variable. This is less efficient but works
247251
// everywhere.
@@ -259,10 +263,6 @@ void swift::runtime::environment::initialize(void *context) {
259263
printHelp("Using getenv to read variables. Unknown SWIFT_DEBUG_ variables "
260264
"will not be flagged.");
261265
}
262-
#else
263-
void swift::runtime::environment::initialize(void *context) {
264-
(void)context;
265-
}
266266
#endif
267267

268268
SWIFT_RUNTIME_EXPORT

0 commit comments

Comments
 (0)