|
From: openocd-gerrit <ope...@us...> - 2026-03-08 10:20:55
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via c3b4bcc6e62e2bb8b09835c27f7dc34aa1c73be3 (commit)
from a5a9121ad66b2d2ead1c3d44a7d10a19d9e98fac (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c3b4bcc6e62e2bb8b09835c27f7dc34aa1c73be3
Author: Antonio Borneo <bor...@gm...>
Date: Sun Feb 15 21:04:09 2026 +0100
log: simplify handling of mallinfo()
Simplify the use of C preprocessor conditionals by adding a new
function get_free_memory_space().
Change-Id: I795bd13284d06844f976a5264ca4d54ad887983c
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9463
Reviewed-by: R. Diez <rdi...@rd...>
Tested-by: jenkins
diff --git a/src/helper/log.c b/src/helper/log.c
index 06d381055..0976f4e0f 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -62,6 +62,28 @@ static void log_forward(const char *file, unsigned int line, const char *functio
}
}
+// whitespace + SIZE_MAX + zero termination
+#define MEM_STR_LEN (1 + 21 + 1)
+static void get_free_memory_space(char *s)
+{
+#if defined(HAVE_MALLINFO2)
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_MALLOC)) {
+ struct mallinfo2 info = mallinfo2();
+ snprintf(s, MEM_STR_LEN, " %zu", info.fordblks);
+ return;
+ }
+#elif defined(HAVE_MALLINFO)
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_MALLOC)) {
+ struct mallinfo info = mallinfo();
+ snprintf(s, MEM_STR_LEN, " %d", info.fordblks);
+ return;
+ }
+#endif
+
+ // empty string
+ *s = 0;
+}
+
/* The log_puts() serves two somewhat different goals:
*
* - logging
@@ -102,34 +124,12 @@ static void log_puts(enum log_levels level,
/* print with count and time information */
int64_t t = timeval_ms() - start;
-#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
- const int should_use_mallinfo = LOG_LEVEL_IS(LOG_LVL_DEBUG_MALLOC);
+ char free_memory[MEM_STR_LEN];
+ get_free_memory_space(free_memory);
- if (should_use_mallinfo) {
-#ifdef HAVE_MALLINFO2
- struct mallinfo2 info = mallinfo2();
-#else
- struct mallinfo info = mallinfo();
-#endif
-
- fprintf(log_output, "%s%u %" PRId64 " %s:%d %s()"
-#ifdef HAVE_MALLINFO2
- " %zu"
-#else
- " %d"
-#endif
- ": %s", log_strings[level + 1], count, t, file, line, function,
- info.fordblks,
- string);
- }
-#else
- const int should_use_mallinfo = 0;
-#endif
- if (!should_use_mallinfo) {
- fprintf(log_output, "%s%u %" PRId64 " %s:%d %s()"
- ": %s", log_strings[level + 1], count, t, file, line, function,
- string);
- }
+ fprintf(log_output, "%s%u %" PRId64 " %s:%d %s()%s: %s",
+ log_strings[level + 1], count, t, file, line, function,
+ free_memory, string);
} else {
/* if we are using gdb through pipes then we do not want any output
* to the pipe otherwise we get repeated strings */
-----------------------------------------------------------------------
Summary of changes:
src/helper/log.c | 54 +++++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|