Skip to content

Commit

Permalink
Make strtod_c compatible with different gcc abi (pytorch#21293)
Browse files Browse the repository at this point in the history
Summary:
We have encountered `std::bad_cast` error when running PyTorch binary built with cxx11 abi on CentOS7, stack trace:
```
#0  0x00007fec10160207 in raise () from /lib64/libc.so.6
#1  0x00007fec101618f8 in abort () from /lib64/libc.so.6
#2  0x00007fec015767d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007fec01574746 in ?? () from /lib64/libstdc++.so.6
pytorch#4  0x00007fec01574773 in std::terminate() () from /lib64/libstdc++.so.6
pytorch#5  0x00007fec01574993 in __cxa_throw () from /lib64/libstdc++.so.6
pytorch#6  0x00007fec015c94d2 in std::__throw_bad_cast() () from /lib64/libstdc++.so.6
pytorch#7  0x00007feb2ab3c2d7 in std::__cxx11::numpunct<char> const& std::use_facet<std::__cxx11::numpunct<char> >(std::locale const&) ()
   from /root/.local/lib/python2.7/site-packages/torch/lib/libcaffe2.so
pytorch#8  0x00007feb28643d62 in torch::jit::script::strtod_c(char const*, char**) () from /root/.local/lib/python2.7/site-packages/torch/lib/libcaffe2.so
```

We are suspecting this line will get compiled to gcc abi dependent symbol:
```
char decimal_point = std::use_facet<std::numpunct<char>>(std::locale()).decimal_point();
```
Pull Request resolved: pytorch#21293

Differential Revision: D15609910

Pulled By: bddppq

fbshipit-source-id: e247059729863868e4b36d6fec4fcbc36fbc4bb1
  • Loading branch information
bddppq authored and facebook-github-bot committed Jun 6, 2019
1 parent e07d945 commit 7e6d932
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion torch/csrc/jit/script/strtod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ C10_EXPORT double strtod_c(const char *nptr, char **endptr)
static _locale_t loc = _create_locale(LC_ALL, "C");
return _strtod_l(nptr, endptr, loc);
}
#else
#elif defined(__ANDROID__)
C10_EXPORT double strtod_c(const char *nptr, char **endptr)
{
char *fail_pos;
Expand Down Expand Up @@ -247,6 +247,12 @@ C10_EXPORT double strtod_c(const char *nptr, char **endptr)
errno = EINVAL;
return -1.0;
}
#else
C10_EXPORT double strtod_c(const char* nptr, char** endptr) {
/// NOLINTNEXTLINE(hicpp-signed-bitwise)
static locale_t loc = newlocale(LC_ALL_MASK, "C", nullptr);
return strtod_l(nptr, endptr, loc);
}
#endif


Expand Down

0 comments on commit 7e6d932

Please sign in to comment.