Skip to content

Commit 85c5c2c

Browse files
committed
[test][stdlib] Add strto*_l stubs for OpenBSD.
The template defined for Cygwin and friends does not handle failure cases properly so the NumericParsing unit test fails. To get the correct test behavior, we need to use an implementation such as like in the Windows specializations or the non-Cygwin implementation that takes a function pointer. However, adding additional specializations would be too wordy, and OpenBSD doesn't have locale-dependent definitions of the relevant strto* functions. We could add a specialization for a two-argument function pointer, but that becomes too repetitive. Instead, implement a few stubs and use the preprocessor, a la the implementation for Android.
1 parent 80e2b48 commit 85c5c2c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

stdlib/public/stubs/Stubs.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,28 @@
4141
#include <cstdio>
4242
#include <cstdlib>
4343
#include <cstring>
44-
#if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__) || defined(__OpenBSD__)
44+
#if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__)
4545
#include <sstream>
4646
#include <cmath>
47+
#elif defined(__OpenBSD__)
48+
#include <locale.h>
49+
50+
static double swift_strtod_l(const char *nptr, char **endptr, locale_t loc) {
51+
return strtod(nptr, endptr);
52+
}
53+
54+
static float swift_strtof_l(const char *nptr, char **endptr, locale_t loc) {
55+
return strtof(nptr, endptr);
56+
}
57+
58+
static long double swift_strtold_l(const char *nptr, char **endptr,
59+
locale_t loc) {
60+
return strtold(nptr, endptr);
61+
}
62+
63+
#define strtod_l swift_strtod_l
64+
#define strtof_l swift_strtof_l
65+
#define strtold_l swift_strtold_l
4766
#elif defined(__ANDROID__)
4867
#include <locale.h>
4968

@@ -369,7 +388,7 @@ static bool swift_stringIsSignalingNaN(const char *nptr) {
369388
return strcasecmp(nptr, "snan") == 0;
370389
}
371390

372-
#if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__) || defined(__OpenBSD__)
391+
#if defined(__CYGWIN__) || defined(_WIN32) || defined(__HAIKU__)
373392
// Cygwin does not support uselocale(), but we can use the locale feature
374393
// in stringstream object.
375394
template <typename T>

0 commit comments

Comments
 (0)