From cc527df652f9f85880fb4a032903742bd555f431 Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Sun, 16 Jan 2022 16:40:29 +0100 Subject: [PATCH] cgraph: add a graphviz_exit function in a new header file exit.h Towards https://gitlab.com/graphviz/graphviz/-/issues/2178. --- lib/cgraph/CMakeLists.txt | 1 + lib/cgraph/Makefile.am | 2 +- lib/cgraph/cgraph.vcxproj | 1 + lib/cgraph/cgraph.vcxproj.filters | 3 +++ lib/cgraph/exit.h | 32 +++++++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/cgraph/exit.h diff --git a/lib/cgraph/CMakeLists.txt b/lib/cgraph/CMakeLists.txt index 81edb03d7..ab411429a 100644 --- a/lib/cgraph/CMakeLists.txt +++ b/lib/cgraph/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(cgraph SHARED bitarray.h cghdr.h cgraph.h + exit.h itos.h likely.h prisize_t.h diff --git a/lib/cgraph/Makefile.am b/lib/cgraph/Makefile.am index 795c975ce..d7272fda8 100644 --- a/lib/cgraph/Makefile.am +++ b/lib/cgraph/Makefile.am @@ -12,7 +12,7 @@ AM_CFLAGS = -DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR endif pkginclude_HEADERS = cgraph.h -noinst_HEADERS = agxbuf.h bitarray.h cghdr.h itos.h likely.h prisize_t.h \ +noinst_HEADERS = agxbuf.h bitarray.h cghdr.h exit.h itos.h likely.h prisize_t.h \ sprint.h strcasecmp.h unreachable.h noinst_LTLIBRARIES = libcgraph_C.la lib_LTLIBRARIES = libcgraph.la diff --git a/lib/cgraph/cgraph.vcxproj b/lib/cgraph/cgraph.vcxproj index 052a3bba7..99b9de621 100644 --- a/lib/cgraph/cgraph.vcxproj +++ b/lib/cgraph/cgraph.vcxproj @@ -101,6 +101,7 @@ win_flex -oscan.c scan.l + diff --git a/lib/cgraph/cgraph.vcxproj.filters b/lib/cgraph/cgraph.vcxproj.filters index a20bf8fa7..8c83513d3 100644 --- a/lib/cgraph/cgraph.vcxproj.filters +++ b/lib/cgraph/cgraph.vcxproj.filters @@ -27,6 +27,9 @@ Header Files + + Header Files + Header Files diff --git a/lib/cgraph/exit.h b/lib/cgraph/exit.h new file mode 100644 index 000000000..650951b28 --- /dev/null +++ b/lib/cgraph/exit.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __GNUC__ +// FIXME: use _Noreturn for all compilers when we move to C11 +#define NORETURN __attribute__((noreturn)) +#elif defined(_MSC_VER) +#define NORETURN __declspec(noreturn) +#else +#define NORETURN /* nothing */ +#endif + +static inline NORETURN void graphviz_exit(int status) { +#ifdef __MINGW32__ + // workaround for https://gitlab.com/graphviz/graphviz/-/issues/2178 + fflush(stdout); + fflush(stderr); +#endif + exit(status); +} + +#undef NORETURN + +#ifdef __cplusplus +} +#endif -- 2.40.0