From f5c70e1ee7f6116e26bc908903edd080cb826c07 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 24 Sep 2020 17:28:15 -0400 Subject: [PATCH] barectf.c.j2: only declare `ts` variable when needed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch changes the `barectf.c.j2` template so that, for the packet opening, packet closing, and event record header serialization functions, the `ts` variable is only declared when it's used. Without this patch, the C compiler can report such a warning: warning: unused variable ‘ts’ [-Wunused-variable] In `barectf.c-macros.j2`, the open_close_func_preamble() macro is changed to accept the timestamp packet feature in order to check either the packet beginning or end timestamp field type feature. Signed-off-by: Philippe Proulx --- barectf/templates/c/barectf.c-macros.j2 | 4 ++-- barectf/templates/c/barectf.c.j2 | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/barectf/templates/c/barectf.c-macros.j2 b/barectf/templates/c/barectf.c-macros.j2 index ee14024..de91e93 100644 --- a/barectf/templates/c/barectf.c-macros.j2 +++ b/barectf/templates/c/barectf.c-macros.j2 @@ -33,9 +33,9 @@ # Generates the preamble of the packet opening/closing functions for # the data stream type `dst`. #} -{% macro open_close_func_preamble(dst) %} +{% macro open_close_func_preamble(dst, ts_feature) %} struct {{ prefix }}ctx * const ctx = &sctx->parent; -{% if dst.default_clock_type %} +{% if dst.default_clock_type and ts_feature %} const {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} ts = ctx->use_cur_last_event_ts ? sctx->cur_last_event_ts : ctx->cbs.{{ dst.default_clock_type.name }}_clock_get_value(ctx->data); diff --git a/barectf/templates/c/barectf.c.j2 b/barectf/templates/c/barectf.c.j2 index 5207f64..d4b4ee0 100644 --- a/barectf/templates/c/barectf.c.j2 +++ b/barectf/templates/c/barectf.c.j2 @@ -246,7 +246,7 @@ void _commit_er(void * const vctx) {% include 'c/open-func-proto.j2' %} { - {{ macros.open_close_func_preamble(dst) | indent_tab }} + {{ macros.open_close_func_preamble(dst, dst.features.packet_features.beginning_timestamp_field_type) | indent_tab }} /* * This function is either called by a tracing function, or @@ -302,7 +302,7 @@ end: {% include 'c/close-func-proto.j2' %} { - {{ macros.open_close_func_preamble(dst) | indent_tab }} + {{ macros.open_close_func_preamble(dst, dst.features.packet_features.end_timestamp_field_type) | indent_tab }} /* * This function is either called by a tracing function, or @@ -393,7 +393,7 @@ static void _serialize_er_header_{{ dst.name }}(void * const vctx, const uint32_t ert_id) { struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); - {% if def_clk_type %} + {% if def_clk_type and dst.features.event_record_features.timestamp_field_type %} struct {{ sctx_name }}_ctx * const sctx = _FROM_VOID_PTR(struct {{ sctx_name }}_ctx, vctx); const {{ cg_opts.clock_type_c_types[def_clk_type] }} ts = sctx->cur_last_event_ts; {% endif %} -- 2.34.1