[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4' - common/Log.cpp common/Log.hpp

2019-04-27 Thread Libreoffice Gerrit user
 common/Log.cpp |   16 
 common/Log.hpp |   26 --
 2 files changed, 12 insertions(+), 30 deletions(-)

New commits:
commit e1e22380f285329a0838d637cf94a2c7e6973493
Author: Michael Meeks 
AuthorDate: Sat Apr 27 22:12:57 2019 +0100
Commit: Michael Meeks 
CommitDate: Sat Apr 27 22:13:25 2019 +0100

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, std::allocator 
>::str(std::__cxx11::basic_string, 
std::allocator > 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, std::allocator >::~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 bc67163a481d02d76266875372af5ff79a861d23.
This reverts commit 242df1594dd9283ba0501b141e176617b03cf3d9.

diff --git a/common/Log.cpp b/common/Log.cpp
index f1ed70dcb..a5f101e93 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -131,22 +131,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 a17509317..bf05fc7ce 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -50,9 +50,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(); }
@@ -236,19 +233,20 @@ 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)
 
-#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 

[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4' - common/Log.cpp common/Log.hpp

2019-04-27 Thread Libreoffice Gerrit user
 common/Log.cpp |3 ++-
 common/Log.hpp |4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

New commits:
commit bc67163a481d02d76266875372af5ff79a861d23
Author: Michael Meeks 
AuthorDate: Sat Apr 27 22:00:51 2019 +0100
Commit: Michael Meeks 
CommitDate: Sat Apr 27 22:04:33 2019 +0100

Reset the stringstream properly.

Avoids some N^2 log-line explosion; also make the method name
more findable.

Change-Id: I3ee8c521f1ac98a939cd4d758c720b577d3bfa57
Reviewed-on: https://gerrit.libreoffice.org/71443
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/common/Log.cpp b/common/Log.cpp
index 3bedaa82e..f1ed70dcb 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -134,10 +134,11 @@ namespace Log
 // Reuse the same buffer to minimize memory fragmentation.
 static thread_local std::ostringstream Oss;
 
-std::ostringstream& begin(const char* level)
+std::ostringstream& beginLog(const char* level)
 {
 // Reset the oss.
 Oss.clear();
+Oss.str(std::string());
 Oss.seekp(0);
 
 // Output the prefix.
diff --git a/common/Log.hpp b/common/Log.hpp
index 9ded1425a..a17509317 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -51,7 +51,7 @@ 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& begin(const char* level);
+std::ostringstream& beginLog(const char* level);
 
 inline bool traceEnabled() { return logger().trace(); }
 inline bool debugEnabled() { return logger().debug(); }
@@ -245,7 +245,7 @@ namespace Log
 
 #define LOG_BODY_(LOG, PRIO, LVL, X, FILEP)
\
 Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO);  
\
-std::ostringstream& oss_ = Log::begin(LVL);
\
+std::ostringstream& oss_ = Log::beginLog(LVL); 
   \
 oss_ << X; 
\
 LOG_END(oss_, FILEP);  
\
 m_.setText(oss_.str());
\
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits