From 5f1431107de1dcd2775acd5becf7220d6bcd1fc9 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 17 Apr 2022 14:31:35 -0700 Subject: [PATCH] cgraph: also flush C++ iostreams in exit wrapper This exit wrapper works around an issue where processes running under MinGW can exit with unbuffered data remaining in their stdout and stderr internal buffers without being flushed. The C stdio and C++ iostreams implementations can have separate buffers. Thus when using this wrapper in C++ code in combination with C++ iostreams (e.g. cmd/mingle/minglemain.cpp) we need to additionally flush the C++ buffers as well. Gitlab: #2178 --- lib/cgraph/exit.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cgraph/exit.h b/lib/cgraph/exit.h index 650951b28..e9fd3b9d7 100644 --- a/lib/cgraph/exit.h +++ b/lib/cgraph/exit.h @@ -4,6 +4,8 @@ #include #ifdef __cplusplus +#include + extern "C" { #endif @@ -21,6 +23,10 @@ static inline NORETURN void graphviz_exit(int status) { // workaround for https://gitlab.com/graphviz/graphviz/-/issues/2178 fflush(stdout); fflush(stderr); +#ifdef __cplusplus + std::cout.flush(); + std::cerr.flush(); +#endif #endif exit(status); } -- 2.40.0