From ad778b6c41a8a78a480d6593ebdb154146650862 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Fri, 7 Jul 2023 02:30:08 +0800 Subject: [PATCH] Remove usage of std::cerr The usage of std::cerr significantly increases binary size. However, many people disable exceptions for binary size. Also, std::terminate also uses std::cerr to print an abort message and then abort. Here we manually print the abort message and thus use std::abort instead. --- src/cxx.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cxx.cc b/src/cxx.cc index 4aac64279..70ebc0b1f 100644 --- a/src/cxx.cc +++ b/src/cxx.cc @@ -1,4 +1,5 @@ #include "../include/cxx.h" +#include #include #include #include @@ -76,8 +77,8 @@ inline namespace cxxbridge1 { template void panic [[noreturn]] (const char *msg) { #if defined(RUST_CXX_NO_EXCEPTIONS) - std::cerr << "Error: " << msg << ". Aborting." << std::endl; - std::terminate(); + std::fprintf(stderr, "Error: %s. Aborting.\n", msg); + std::abort(); #else throw Exception(msg); #endif