common/Log.cpp | 16 ---------------- common/Log.hpp | 35 +++++++++++++++++------------------ 2 files changed, 17 insertions(+), 34 deletions(-)
New commits: commit 685709080d27d87ccb0f9bd5c8663003ea3cfb78 Author: Michael Meeks <[email protected]> AuthorDate: Sat Apr 27 22:15:48 2019 +0100 Commit: Michael Meeks <[email protected]> CommitDate: Sat Apr 27 23:18:11 2019 +0200 Revert attempts at re-using ostringstream Cleaning up the thread variable with the shared string stream is something of a nightmare, for a rather marginal gain. ==9296== Invalid write of size 1 ... ==9296== by 0x738C092: str (sstream:195) ==9296== by 0x738C092: std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::str(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (sstream:649) ==9296== by 0x65383A: Log::beginLog[abi:cxx11](char const*) (Log.cpp:141) ==9296== by 0x551823: Admin::~Admin() (Admin.cpp:381) ==9296== by 0x7D9ECF7: __run_exit_handlers (exit.c:83) ==9296== by 0x7D9ED49: exit (exit.c:105) ==9296== by 0x7D86F50: (below main) (libc-start.c:342) ==9296== Address 0x8ba41c0 is 0 bytes inside a block of size 513 free'd ==9296== at 0x4C2FA1D: operator delete(void*) (vg_replace_malloc.c:576) ... ==9296== by 0x738784A: ~basic_stringbuf (sstream:65) ==9296== by 0x738784A: std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream() (sstream:591) ==9296== by 0x7D9F27E: __call_tls_dtors (cxa_thread_atexit_impl.c:155) ==9296== by 0x7D9EC0A: __run_exit_handlers (exit.c:41) ==9296== by 0x7D9ED49: exit (exit.c:105) ==9296== by 0x7D86F50: (below main) (libc-start.c:342) Good to log during shutdown / exit. This reverts commit c315d219d5967f23fb1769e78021f61b8f9da6ec. This reverts commit ce78fec310ab5ab6aecabb73cad7d782afcb885f. Change-Id: Ia4a15be336d89d8d883530943724d48e4b0ec9fe Reviewed-on: https://gerrit.libreoffice.org/71444 Reviewed-by: Michael Meeks <[email protected]> Tested-by: Michael Meeks <[email protected]> diff --git a/common/Log.cpp b/common/Log.cpp index 6b263263a..b892c5b4b 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -126,22 +126,6 @@ namespace Log return buffer; } - // Reuse the same buffer to minimize memory fragmentation. - static thread_local std::ostringstream Oss; - - std::ostringstream& beginLog(const char* level) - { - // Reset the oss. - Oss.clear(); - Oss.str(std::string()); - Oss.seekp(0); - - // Output the prefix. - char buffer[1024]; - Oss << Log::prefix(buffer, sizeof(buffer) - 1, level) << std::boolalpha; - return Oss; - } - void signalLogPrefix() { char buffer[1024]; diff --git a/common/Log.hpp b/common/Log.hpp index cc4ef9d83..bdc654b39 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -54,9 +54,6 @@ namespace Log char* prefix(char* buffer, std::size_t len, const char* level); - /// Starts logging by generating the prefix and returning an oss. - std::ostringstream& beginLog(const char* level); - inline bool traceEnabled() { return logger().trace(); } inline bool debugEnabled() { return logger().debug(); } inline bool infoEnabled() { return logger().information(); } @@ -240,29 +237,31 @@ namespace Log #define LOG_FILE_NAME(f) (strrchr(f, '/')+1) #endif -#define LOG_END(LOG, FILEP) \ - do \ - { \ - if (FILEP) \ - LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ +#define LOG_END(LOG, FILEP) \ + do \ + { \ + if (FILEP) \ + LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ } while (false) #ifdef __ANDROID__ -#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ - std::ostringstream& oss_ = Log::beginLog(LVL); \ - oss_ << X; \ - LOG_END(oss_, FILEP); \ +#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ + char b_[1024]; \ + std::ostringstream oss_(Log::prefix(b_, sizeof(b_) - 1, LVL), std::ostringstream::ate); \ + oss_ << std::boolalpha << X; \ + LOG_END(oss_, FILEP); \ ((void)__android_log_print(ANDROID_LOG_DEBUG, "loolwsd", "%s %s", LVL, oss_.str().c_str())) #else -#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ - Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO); \ - std::ostringstream& oss_ = Log::beginLog(LVL); \ - oss_ << X; \ - LOG_END(oss_, FILEP); \ - m_.setText(oss_.str()); \ +#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ + Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO); \ + char b_[1024]; \ + std::ostringstream oss_(Log::prefix(b_, sizeof(b_) - 1, LVL), std::ostringstream::ate); \ + oss_ << std::boolalpha << X; \ + LOG_END(oss_, FILEP); \ + m_.setText(oss_.str()); \ LOG.log(m_); #endif _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
