Skip to content

Commit

Permalink
Merge pull request #2276 from AntelopeIO/set_new_handler_war_llvm
Browse files Browse the repository at this point in the history
don't do `set_new_handler()` workaround for LLVM 9+ where it's unnecessary
  • Loading branch information
spoonincode authored Mar 3, 2024
2 parents 35c8563 + bbc092a commit 006583a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,18 @@ struct controller_impl {
// Read-write tasks are not being executed.
};

// LLVM sets the new handler, we need to reset this to throw a bad_alloc exception so we can possibly exit cleanly
// and not just abort.
#if LLVM_VERSION_MAJOR < 9
// LLVM versions prior to 9 do a set_new_handler() in a static global initializer. Reset LLVM's custom handler
// back to the default behavior of throwing bad_alloc so we can possibly exit cleanly and not just abort as LLVM's
// handler does.
// LLVM 9+ doesn't install this handler unless calling InitLLVM(), which we don't.
// See https://reviews.llvm.org/D64505
struct reset_new_handler {
reset_new_handler() { std::set_new_handler([](){ throw std::bad_alloc(); }); }
};

reset_new_handler rnh; // placed here to allow for this to be set before constructing the other fields
#endif
controller& self;
std::function<void()> shutdown;
chainbase::database db;
Expand Down

0 comments on commit 006583a

Please sign in to comment.