Skip to content

Commit db160d5

Browse files
committed
runtime: tweak the environment handling
We would previously enable "environment variables" on Android via global properties. Re-order the macros a bit to make it more explicit that the environment handling is required for that and remove it when environment variables are unsupported.
1 parent 23a049c commit db160d5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ void printHelp(const char *extra) {
173173
// Initialization code.
174174
swift::once_t swift::runtime::environment::initializeToken;
175175

176-
#if SWIFT_STDLIB_HAS_ENVIRON && (defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__))
176+
#if SWIFT_STDLIB_HAS_ENVIRON
177+
178+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
177179
extern "C" char **environ;
178180
#define ENVIRON environ
179181
#elif defined(_WIN32)
@@ -213,11 +215,11 @@ static void platformInitialize(void *context) {
213215
}
214216
#endif
215217

216-
#if !SWIFT_STDLIB_HAS_ENVIRON
217-
void swift::runtime::environment::initialize(void *context) {
218-
platformInitialize(context);
219-
}
220-
#elif defined(ENVIRON)
218+
#endif
219+
220+
#if SWIFT_STDLIB_HAS_ENVIRON
221+
222+
#if defined(ENVIRON)
221223
void swift::runtime::environment::initialize(void *context) {
222224
// On platforms where we have an environment variable array available, scan it
223225
// directly. This optimizes for the common case where no variables are set,
@@ -295,6 +297,11 @@ void swift::runtime::environment::initialize(void *context) {
295297
}
296298
#endif
297299

300+
#else
301+
void swift::runtime::environment::initialize(void *context) {
302+
}
303+
#endif
304+
298305
SWIFT_RUNTIME_EXPORT
299306
bool swift_COWChecksEnabled() {
300307
return runtime::environment::SWIFT_DEBUG_ENABLE_COW_CHECKS();

0 commit comments

Comments
 (0)