@@ -387,9 +387,25 @@ static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) {
387
387
#define strtod_l swift_strtod_l
388
388
#define strtof_l swift_strtof_l
389
389
#endif
390
+ #elif defined(_WIN32)
391
+ static double swift_strtod_l (const char *nptr, char **endptr, locale_t loc) {
392
+ return _strtod_l (str, &end, getCLocale ());
393
+ }
394
+
395
+ static float swift_strtof_l (const char *nptr, char **endptr, locale_t loc) {
396
+ return _strtof_l (str, &end, getCLocale ());
397
+ }
398
+
399
+ static long double swift_strtold_l (const char *nptr, char **endptr,
400
+ locale_t loc) {
401
+ return _strtod_l (str, &end, getCLocale ());
402
+ }
403
+ #define strtod_l swift_strtod_l
404
+ #define strtof_l swift_strtof_l
405
+ #define strtold_l swift_strtold_l
390
406
#endif
391
407
392
- #if defined(__CYGWIN__) || defined(_WIN32) || defined( __HAIKU__)
408
+ #if defined(__CYGWIN__) || defined(__HAIKU__)
393
409
// Cygwin does not support uselocale(), but we can use the locale feature
394
410
// in stringstream object.
395
411
template <typename T>
@@ -415,62 +431,6 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
415
431
return nptr + pos;
416
432
}
417
433
418
- #if defined(_WIN32)
419
- template <>
420
- const char *
421
- _swift_stdlib_strtoX_clocale_impl<float >(const char *str, float *result) {
422
- if (swift_stringIsSignalingNaN (str)) {
423
- *result = std::numeric_limits<float >::signaling_NaN ();
424
- return str + std::strlen (str);
425
- }
426
-
427
- char *end;
428
- _set_errno (0 );
429
- *result = _strtof_l (str, &end, getCLocale ());
430
- if (*result == HUGE_VALF || *result == -HUGE_VALF || *result == 0.0 || *result == -0.0 ) {
431
- if (errno == ERANGE)
432
- end = nullptr ;
433
- }
434
- return end;
435
- }
436
-
437
- template <>
438
- const char *
439
- _swift_stdlib_strtoX_clocale_impl<double >(const char *str, double *result) {
440
- if (swift_stringIsSignalingNaN (str)) {
441
- *result = std::numeric_limits<double >::signaling_NaN ();
442
- return str + std::strlen (str);
443
- }
444
-
445
- char *end;
446
- _set_errno (0 );
447
- *result = _strtod_l (str, &end, getCLocale ());
448
- if (*result == HUGE_VAL || *result == -HUGE_VAL || *result == 0.0 || *result == -0.0 ) {
449
- if (errno == ERANGE)
450
- end = nullptr ;
451
- }
452
- return end;
453
- }
454
-
455
- template <>
456
- const char *
457
- _swift_stdlib_strtoX_clocale_impl<long double >(const char *str, long double *result) {
458
- if (swift_stringIsSignalingNaN (str)) {
459
- *result = std::numeric_limits<long double >::signaling_NaN ();
460
- return str + std::strlen (str);
461
- }
462
-
463
- char *end;
464
- _set_errno (0 );
465
- *result = _strtod_l (str, &end, getCLocale ());
466
- if (*result == HUGE_VALL || *result == -HUGE_VALL || *result == 0.0 || *result == -0.0 ) {
467
- if (errno == ERANGE)
468
- end = nullptr ;
469
- }
470
- return end;
471
- }
472
- #endif
473
-
474
434
const char *swift::_swift_stdlib_strtold_clocale (
475
435
const char *nptr, void *outResult) {
476
436
return _swift_stdlib_strtoX_clocale_impl (
@@ -488,6 +448,14 @@ const char *swift::_swift_stdlib_strtof_clocale(
488
448
}
489
449
#else
490
450
451
+ static inline void _swift_set_errno (int to) {
452
+ #if defined(_WIN32)
453
+ _set_errno (0 );
454
+ #else
455
+ errno = 0 ;
456
+ #endif
457
+ }
458
+
491
459
// We can't return Float80, but we can receive a pointer to one, so
492
460
// switch the return type and the out parameter on strtold.
493
461
template <typename T>
@@ -503,7 +471,7 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
503
471
}
504
472
505
473
char *EndPtr;
506
- errno = 0 ;
474
+ _swift_set_errno ( 0 ) ;
507
475
const auto result = posixImpl (nptr, &EndPtr, getCLocale ());
508
476
*outResult = result;
509
477
if (result == huge || result == -huge || result == 0.0 || result == -0.0 ) {
0 commit comments