Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Clean-up re-usable string streams

Commit
091595780e4f330f1fd74e9d8caf5d509d195491
Author
Phil Nash ·
Parents
f417995afcac

Files · Download .tar.gz

Changes

 include/internal/catch_registry_hub.cpp |  1 +
 include/internal/catch_stream.cpp       | 15 +++++++++++++--
 include/internal/catch_stream.h         |  2 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/internal/catch_registry_hub.cpp b/include/internal/catch_registry_hub.cpp
index ab5ad361..d98708c5 100644
--- a/include/internal/catch_registry_hub.cpp
+++ b/include/internal/catch_registry_hub.cpp
@@ -87,6 +87,7 @@ namespace Catch {
         delete getTheRegistryHub();
         getTheRegistryHub() = nullptr;
         cleanUpContext();
+        ReusableStringStream::cleanup();
     }
     std::string translateActiveException() {
         return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
diff --git a/include/internal/catch_stream.cpp b/include/internal/catch_stream.cpp
index 76bbc8f3..125fd471 100644
--- a/include/internal/catch_stream.cpp
+++ b/include/internal/catch_stream.cpp
@@ -145,6 +145,7 @@ namespace Catch {
         std::vector<std::unique_ptr<std::ostringstream>> m_streams;
         std::vector<std::size_t> m_unused;
         std::ostringstream m_referenceStream; // Used for copy state/ flags from
+        static StringStreams* s_instance;
 
         auto add() -> std::size_t {
             if( m_unused.empty() ) {
@@ -165,11 +166,21 @@ namespace Catch {
 
         // !TBD: put in TLS
         static auto instance() -> StringStreams& {
-            static StringStreams s_stringStreams;
-            return s_stringStreams;
+            if( !s_instance )
+                s_instance = new StringStreams();
+            return *s_instance;
+        }
+        static void cleanup() {
+            delete s_instance;
+            s_instance = nullptr;
         }
     };
 
+    StringStreams* StringStreams::s_instance = nullptr;
+
+    void ReusableStringStream::cleanup() {
+        StringStreams::cleanup();
+    }
 
     ReusableStringStream::ReusableStringStream()
     :   m_index( StringStreams::instance().add() ),
diff --git a/include/internal/catch_stream.h b/include/internal/catch_stream.h
index 2b41adbd..c5e78b22 100644
--- a/include/internal/catch_stream.h
+++ b/include/internal/catch_stream.h
@@ -43,6 +43,8 @@ namespace Catch {
             return *this;
         }
         auto get() -> std::ostream& { return *m_oss; }
+
+        static void cleanup();
     };
 }