Wrap warning handler in a function to avoid siof (#30800)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30800

SparseNN benchmark crashed due to this.
Wrap warning handler in a function to avoid siof.

Test Plan: Tested locally, SparseNN benchmark no longer crashes.

Reviewed By: yinghai

Differential Revision: D18826731

fbshipit-source-id: 8fcab8a3f38cc20f775409c0686363af3c27d0a6
This commit is contained in:
Qi Zhou 2019-12-05 11:20:17 -08:00 committed by Facebook Github Bot
parent bf1b4b6fef
commit 9617d07bd5

View File

@ -66,8 +66,12 @@ void Error::AppendMessage(const std::string& new_msg) {
namespace Warning {
namespace {
static WarningHandler base_warning_handler_ = WarningHandler();
static thread_local WarningHandler* warning_handler_ = &base_warning_handler_;
WarningHandler* getHandler() {
static WarningHandler base_warning_handler_ = WarningHandler();
return &base_warning_handler_;
};
static thread_local WarningHandler* warning_handler_ = getHandler();
}
void warn(SourceLocation source_location, const std::string& msg) {