@@ -155,8 +155,20 @@ static inline locale_t getCLocale() {
155155 // as C locale.
156156 return nullptr ;
157157}
158- #elif defined(__CYGWIN__) || defined(_WIN32) || defined( __HAIKU__)
158+ #elif defined(__CYGWIN__) || defined(__HAIKU__)
159159// In Cygwin, getCLocale() is not used.
160+ #elif defined(_WIN32)
161+ static _locale_t makeCLocale () {
162+ _locale_t CLocale = _create_locale (LC_ALL, " C" );
163+ if (!CLocale) {
164+ swift::crash (" makeCLocale: _create_locale() returned a null pointer" );
165+ }
166+ return CLocale;
167+ }
168+
169+ static _locale_t getCLocale () {
170+ return SWIFT_LAZY_CONSTANT (makeCLocale ());
171+ }
160172#else
161173static locale_t makeCLocale () {
162174 locale_t CLocale = newlocale (LC_ALL_MASK, " C" , nullptr );
@@ -373,41 +385,41 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
373385
374386#if defined(_WIN32)
375387template <>
376- static const char *
388+ const char *
377389_swift_stdlib_strtoX_clocale_impl<float >(const char *str, float *result) {
378390 if (swift_stringIsSignalingNaN (str)) {
379391 *result = std::numeric_limits<float >::signaling_NaN ();
380392 return str + std::strlen (str);
381393 }
382394
383395 char *end;
384- *result = std::strtof (str, &end);
396+ *result = _strtof_l (str, &end, getCLocale () );
385397 return end;
386398}
387399
388400template <>
389- static const char *
401+ const char *
390402_swift_stdlib_strtoX_clocale_impl<double >(const char *str, double *result) {
391403 if (swift_stringIsSignalingNaN (str)) {
392404 *result = std::numeric_limits<double >::signaling_NaN ();
393405 return str + std::strlen (str);
394406 }
395407
396408 char *end;
397- *result = std::strtod (str, &end);
409+ *result = _strtod_l (str, &end, getCLocale () );
398410 return end;
399411}
400412
401413template <>
402- static const char *
414+ const char *
403415_swift_stdlib_strtoX_clocale_impl<long double >(const char *str, long double *result) {
404416 if (swift_stringIsSignalingNaN (str)) {
405417 *result = std::numeric_limits<long double >::signaling_NaN ();
406418 return str + std::strlen (str);
407419 }
408420
409421 char *end;
410- *result = std::strtold (str, &end);
422+ *result = _strtod_l (str, &end, getCLocale () );
411423 return end;
412424}
413425#endif
0 commit comments