Skip to content

Commit 9a76e84

Browse files
zdevitofacebook-github-bot
authored andcommitted
Use C locale in lexer (pytorch#12739)
Summary: Possible fix for pytorch#11326. Testing in CI for windows code. Pull Request resolved: pytorch#12739 Differential Revision: D10417038 Pulled By: zdevito fbshipit-source-id: 1d5f2f9a24eceef7047dc218669faca8a187c65c
1 parent 459cff9 commit 9a76e84

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

torch/csrc/jit/script/lexer.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
#include <sstream>
66
#include <string>
77
#include <unordered_map>
8+
#ifdef _WIN32
9+
#include <locale.h>
10+
#else
11+
#include <xlocale.h>
12+
#endif
13+
814
#include <vector>
915
#include "torch/csrc/jit/assertions.h"
1016
#include "torch/csrc/jit/source_range.h"
@@ -146,6 +152,17 @@ struct SharedParserData {
146152
TC_FORALL_TOKEN_KINDS(ADD_CASE)
147153
#undef ADD_CASE
148154
}
155+
#ifdef _WIN32
156+
double strtod_c(const char * str, char** end) {
157+
static _locale_t loc = _create_locale(LC_ALL, "C");
158+
return _strtod_l(str, end, loc);
159+
}
160+
#else
161+
double strtod_c(const char * str, char** end) {
162+
static locale_t loc = newlocale(LC_ALL_MASK, "C", nullptr);
163+
return strtod_l(str, end, loc);
164+
}
165+
#endif
149166
// 1. skip whitespace
150167
// 2. handle comment or newline
151168
//
@@ -159,7 +176,7 @@ struct SharedParserData {
159176
return false;
160177
const char* startptr = str.c_str() + start;
161178
char* endptr;
162-
std::strtod(startptr, &endptr);
179+
strtod_c(startptr, &endptr);
163180
*len = endptr - startptr;
164181
return *len > 0;
165182
}

0 commit comments

Comments
 (0)