From 0d86cd5ce5f7955199baf52f840417629457acba Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Tue, 5 May 2026 15:08:35 -0500 Subject: [PATCH] trace: Move assertions into individual annotation functions The int, string, and float annotators will become our atoms when we start logging larger structs. The functions for complex annotations will call these many times for a single annotation. So we should assert in the int, string, and float annotators before adding there, so the big functions are implicitly checked. Signed-off-by: Derek Foreman --- libweston/perfetto/annotations.c | 8 ++++++++ libweston/weston-trace.h | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libweston/perfetto/annotations.c b/libweston/perfetto/annotations.c index 7cee650a3..f383a699f 100644 --- a/libweston/perfetto/annotations.c +++ b/libweston/perfetto/annotations.c @@ -23,9 +23,11 @@ * SOFTWARE. */ +#include "config.h" #include #include "perfetto/annotations.h" +#include "shared/weston-assert.h" #include "weston-trace.h" WL_EXPORT int @@ -34,6 +36,8 @@ perfetto_annotate_int(struct weston_debug_annotation *annots, const char *key, int value) { + weston_assert_u32_gt(NULL, WESTON_MAX_DEBUG_ANNOTS, count); + annots[count].type = WESTON_DEBUG_ANNOTATION_INT_VAL; annots[count].ivalue = value; annots[count].key = key; @@ -47,6 +51,8 @@ perfetto_annotate_float(struct weston_debug_annotation *annots, const char *key, float value) { + weston_assert_u32_gt(NULL, WESTON_MAX_DEBUG_ANNOTS, count); + annots[count].type = WESTON_DEBUG_ANNOTATION_FLOAT_VAL; annots[count].fvalue = value; annots[count].key = key; @@ -60,6 +66,8 @@ perfetto_annotate_string(struct weston_debug_annotation *annots, const char *key, const char *value) { + weston_assert_u32_gt(NULL, WESTON_MAX_DEBUG_ANNOTS, count); + annots[count].type = WESTON_DEBUG_ANNOTATION_STR_VAL; annots[count].svalue = value; annots[count].key = key; diff --git a/libweston/weston-trace.h b/libweston/weston-trace.h index b8b4f582a..f19eae457 100644 --- a/libweston/weston-trace.h +++ b/libweston/weston-trace.h @@ -79,7 +79,6 @@ unsigned int __pd_i = 0 #define _WESTON_TRACE_DO_ANNOTATE_ADD(k, v) \ - weston_assert_u32_gt(NULL, WESTON_MAX_DEBUG_ANNOTS, __pd_i); \ __pd_i += _Generic((v), \ int: perfetto_annotate_int, \ unsigned int: perfetto_annotate_int, \