ggml.cpp 738 B

1234567891011121314151617181920212223242526
  1. #include "ggml-impl.h"
  2. #include <cstdlib>
  3. #include <exception>
  4. static std::terminate_handler previous_terminate_handler;
  5. GGML_NORETURN static void ggml_uncaught_exception() {
  6. ggml_print_backtrace();
  7. if (previous_terminate_handler) {
  8. previous_terminate_handler();
  9. }
  10. abort(); // unreachable unless previous_terminate_handler was nullptr
  11. }
  12. static bool ggml_uncaught_exception_init = []{
  13. const char * GGML_NO_BACKTRACE = getenv("GGML_NO_BACKTRACE");
  14. if (GGML_NO_BACKTRACE) {
  15. return false;
  16. }
  17. const auto prev{std::get_terminate()};
  18. GGML_ASSERT(prev != ggml_uncaught_exception);
  19. previous_terminate_handler = prev;
  20. std::set_terminate(ggml_uncaught_exception);
  21. return true;
  22. }();