From 41a02591b9d199a82bb24c23f3828102375137de Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 3 Jul 2023 04:27:49 +0300 Subject: introduced TECO_DEBUG_CLEANUP to mark destructors that should only be used for debug builds * There is cleanup that is not strictly necessary, because it only frees memory which is freed on program termination anyway. * However, it helps to explicitly free everything for debugging memory leaks via Valgrind. * The new macro reduces the number of #ifdef statements. * On NDEBUG, the code of these functions will still be eliminated. * If functions are referenced only from the destructor, there will be no unused function warnings, even in NDEBUG. --- src/sciteco.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sciteco.h') diff --git a/src/sciteco.h b/src/sciteco.h index 87bd973..5734c57 100644 --- a/src/sciteco.h +++ b/src/sciteco.h @@ -58,6 +58,16 @@ teco_is_failure(teco_bool_t x) return x >= 0; } +/** + * Call function as destructor on debug builds. + * This should be used only if the cleanup is optional. + */ +#ifdef NDEBUG +#define TECO_DEBUG_CLEANUP __attribute__((unused)) +#else +#define TECO_DEBUG_CLEANUP __attribute__((destructor)) +#endif + /** TRUE if C is a control character */ #define TECO_IS_CTL(C) ((C) < ' ') /** ASCII character to echo control character C */ -- cgit v1.2.3