@@ -155,8 +155,20 @@ static inline locale_t getCLocale() {
155
155
// as C locale.
156
156
return nullptr ;
157
157
}
158
- #elif defined(__CYGWIN__) || defined(_WIN32) || defined( __HAIKU__)
158
+ #elif defined(__CYGWIN__) || defined(__HAIKU__)
159
159
// 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
+ }
160
172
#else
161
173
static locale_t makeCLocale () {
162
174
locale_t CLocale = newlocale (LC_ALL_MASK, " C" , nullptr );
@@ -373,41 +385,41 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
373
385
374
386
#if defined(_WIN32)
375
387
template <>
376
- static const char *
388
+ const char *
377
389
_swift_stdlib_strtoX_clocale_impl<float >(const char *str, float *result) {
378
390
if (swift_stringIsSignalingNaN (str)) {
379
391
*result = std::numeric_limits<float >::signaling_NaN ();
380
392
return str + std::strlen (str);
381
393
}
382
394
383
395
char *end;
384
- *result = std::strtof (str, &end);
396
+ *result = _strtof_l (str, &end, getCLocale () );
385
397
return end;
386
398
}
387
399
388
400
template <>
389
- static const char *
401
+ const char *
390
402
_swift_stdlib_strtoX_clocale_impl<double >(const char *str, double *result) {
391
403
if (swift_stringIsSignalingNaN (str)) {
392
404
*result = std::numeric_limits<double >::signaling_NaN ();
393
405
return str + std::strlen (str);
394
406
}
395
407
396
408
char *end;
397
- *result = std::strtod (str, &end);
409
+ *result = _strtod_l (str, &end, getCLocale () );
398
410
return end;
399
411
}
400
412
401
413
template <>
402
- static const char *
414
+ const char *
403
415
_swift_stdlib_strtoX_clocale_impl<long double >(const char *str, long double *result) {
404
416
if (swift_stringIsSignalingNaN (str)) {
405
417
*result = std::numeric_limits<long double >::signaling_NaN ();
406
418
return str + std::strlen (str);
407
419
}
408
420
409
421
char *end;
410
- *result = std::strtold (str, &end);
422
+ *result = _strtod_l (str, &end, getCLocale () );
411
423
return end;
412
424
}
413
425
#endif
0 commit comments