Skip to content

Commit 34df17b

Browse files
authored
Merge pull request swiftlang#34524 from apple/stdlib-Conditionally-compile-swift_strto-wrappers
[stdlib] Conditionally compile swift_strto* wrappers
2 parents 15d566d + 25ad42f commit 34df17b

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

stdlib/public/stubs/Stubs.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ T _swift_strto(const char *nptr, char **endptr) {
378378
return ParsedValue;
379379
}
380380

381+
#if defined(__OpenBSD__) || defined(_WIN32) || defined(__CYGWIN__) || defined(__HAIKU__)
382+
#define NEED_SWIFT_STRTOD_L
383+
#define strtod_l swift_strtod_l
384+
#define NEED_SWIFT_STRTOF_L
385+
#define strtof_l swift_strtof_l
386+
#define NEED_SWIFT_STRTOLD_L
387+
#define strtold_l swift_strtold_l
388+
#elif defined(__ANDROID__)
389+
#if __ANDROID_API__ < 21 // Introduced in Android API 21 - L
390+
#define NEED_SWIFT_STRTOLD_L
391+
#define strtold_l swift_strtold_l
392+
#endif
393+
394+
#if __ANDROID_API__ < 26 // Introduced in Android API 26 - O
395+
#define NEED_SWIFT_STRTOD_L
396+
#define strtod_l swift_strtod_l
397+
#define NEED_SWIFT_STRTOF_L
398+
#define strtof_l swift_strtof_l
399+
#endif
400+
#endif
401+
402+
#if defined(NEED_SWIFT_STRTOD_L)
381403
static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) {
382404
#if defined(_WIN32)
383405
return _strtod_l(nptr, endptr, getCLocale());
@@ -387,7 +409,9 @@ static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) {
387409
return strtod(nptr, endptr);
388410
#endif
389411
}
412+
#endif
390413

414+
#if defined(NEED_SWIFT_STRTOF_L)
391415
static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) {
392416
#if defined(_WIN32)
393417
return _strtof_l(nptr, endptr, getCLocale());
@@ -397,7 +421,9 @@ static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) {
397421
return strtof(nptr, endptr);
398422
#endif
399423
}
424+
#endif
400425

426+
#if defined(NEED_SWIFT_STRTOLD_L)
401427
static long double swift_strtold_l(const char *nptr, char **endptr,
402428
locale_t loc) {
403429
#if defined(_WIN32)
@@ -410,21 +436,11 @@ static long double swift_strtold_l(const char *nptr, char **endptr,
410436
return strtold(nptr, endptr);
411437
#endif
412438
}
413-
414-
#if defined(__OpenBSD__) || defined(_WIN32) || defined(__CYGWIN__) || defined(__HAIKU__)
415-
#define strtod_l swift_strtod_l
416-
#define strtof_l swift_strtof_l
417-
#define strtold_l swift_strtold_l
418-
#elif defined(__ANDROID__)
419-
#if __ANDROID_API__ < 21 // Introduced in Android API 21 - L
420-
#define strtold_l swift_strtold_l
421439
#endif
422440

423-
#if __ANDROID_API__ < 26 // Introduced in Android API 26 - O
424-
#define strtod_l swift_strtod_l
425-
#define strtof_l swift_strtof_l
426-
#endif
427-
#endif
441+
#undef NEED_SWIFT_STRTOD_L
442+
#undef NEED_SWIFT_STRTOF_L
443+
#undef NEED_SWIFT_STRTOLD_L
428444

429445
static inline void _swift_set_errno(int to) {
430446
#if defined(_WIN32)

0 commit comments

Comments
 (0)