aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2023-07-03 04:27:49 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2023-07-03 04:27:49 +0300
commit41a02591b9d199a82bb24c23f3828102375137de (patch)
treed09d8a10eb2ed5d180a945421b933f673ce7a95c
parent69b4bbb8341cfda5d8456ccbf951034d63e4340c (diff)
downloadsciteco-41a02591b9d199a82bb24c23f3828102375137de.tar.gz
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.
-rw-r--r--TODO4
-rw-r--r--src/cmdline.c4
-rw-r--r--src/error.c5
-rw-r--r--src/expressions.c4
-rw-r--r--src/help.c4
-rw-r--r--src/memory.c4
-rw-r--r--src/parser.c4
-rw-r--r--src/sciteco.h10
-rw-r--r--src/spawn.c4
-rwxr-xr-xsrc/symbols-extract.tes5
10 files changed, 19 insertions, 29 deletions
diff --git a/TODO b/TODO
index e0d22e8..ee0cd91 100644
--- a/TODO
+++ b/TODO
@@ -473,10 +473,6 @@ Optimizations:
* Add a configure-switch for LTO (--enable-lto).
* undo__teco_interface_ssm() could always include the check for
teco_current_doc_must_undo().
- * Define TECO_DESTRUCTOR depending on NDEBUG instead
- of ifdefing all __attribute__((destructors)).
- This also avoids warning for symbols referenced only in
- the constructors.
Documentation:
* Code docs (Doxygen). It's slowly getting better...
diff --git a/src/cmdline.c b/src/cmdline.c
index 58d48b4..361940d 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -316,15 +316,13 @@ teco_cmdline_fnmacro(const gchar *name, GError **error)
return TRUE;
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_cmdline_cleanup(void)
{
teco_machine_main_clear(&teco_cmdline.machine);
teco_string_clear(&teco_cmdline.str);
teco_string_clear(&teco_last_cmdline);
}
-#endif
/*
* Commandline key processing.
diff --git a/src/error.c b/src/error.c
index 7c4e151..45428df 100644
--- a/src/error.c
+++ b/src/error.c
@@ -161,10 +161,7 @@ teco_error_add_frame_toplevel(void)
teco_error_add_frame(TECO_FRAME_TOPLEVEL, 0);
}
-#ifndef NDEBUG
-__attribute__((destructor))
-#endif
-void
+void TECO_DEBUG_CLEANUP
teco_error_clear_frames(void)
{
teco_stailq_entry_t *entry;
diff --git a/src/expressions.c b/src/expressions.c
index 57e2f71..1f5740f 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -374,11 +374,9 @@ teco_expressions_format(gchar *buffer, teco_int_t number)
return p;
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_expressions_cleanup(void)
{
g_array_free(teco_numbers, TRUE);
g_array_free(teco_operators, TRUE);
}
-#endif
diff --git a/src/help.c b/src/help.c
index e06bda4..f69ba6f 100644
--- a/src/help.c
+++ b/src/help.c
@@ -235,8 +235,7 @@ teco_help_auto_complete(const gchar *topic_name, teco_string_t *insert)
topic_name ? strlen(topic_name) : 0, 0, insert);
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_help_cleanup(void)
{
if (!teco_help_chunk)
@@ -251,7 +250,6 @@ teco_help_cleanup(void)
teco_help_topic_free((teco_help_topic_t *)cur);
}
}
-#endif
/*
* Command states
diff --git a/src/memory.c b/src/memory.c
index 6d7645c..d26b794 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -628,8 +628,7 @@ teco_memory_stop_limiting(void)
g_mutex_unlock(&teco_memory_mutex);
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_memory_cleanup(void)
{
if (!teco_memory_thread)
@@ -642,7 +641,6 @@ teco_memory_cleanup(void)
g_thread_join(teco_memory_thread);
}
-#endif
#else /* !NEED_POLL_THREAD */
diff --git a/src/parser.c b/src/parser.c
index 910fc7f..7bc683e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -52,13 +52,11 @@ teco_loop_stack_init(void)
TECO_DEFINE_ARRAY_UNDO_INSERT_VAL(teco_loop_stack, teco_loop_context_t);
TECO_DEFINE_ARRAY_UNDO_REMOVE_INDEX(teco_loop_stack);
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_loop_stack_cleanup(void)
{
g_array_free(teco_loop_stack, TRUE);
}
-#endif
gboolean
teco_machine_input(teco_machine_t *ctx, gchar chr, GError **error)
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 */
diff --git a/src/spawn.c b/src/spawn.c
index a30e6b2..7515fd6 100644
--- a/src/spawn.c
+++ b/src/spawn.c
@@ -789,8 +789,7 @@ teco_spawn_idle_cb(gpointer user_data)
return G_SOURCE_CONTINUE;
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_spawn_cleanup(void)
{
g_source_unref(teco_spawn_ctx.idle_src);
@@ -801,4 +800,3 @@ teco_spawn_cleanup(void)
if (teco_spawn_ctx.error)
g_error_free(teco_spawn_ctx.error);
}
-#endif
diff --git a/src/symbols-extract.tes b/src/symbols-extract.tes
index 9f43fa6..9b55e93 100755
--- a/src/symbols-extract.tes
+++ b/src/symbols-extract.tes
@@ -48,13 +48,12 @@ teco_symbols_init(void)
teco_symbol_list_init(&Q[getopt.n], entries, G_N_ELEMENTS(entries), FALSE);
}
-#ifndef NDEBUG
-static void __attribute__((destructor))
+static void TECO_DEBUG_CLEANUP
teco_cmdline_cleanup(void)
{
teco_symbol_list_clear(&Q[getopt.n]);
}
-#endif^J
+
!* write output file *!
2EL EWQ#ou