barectf.c.j2: only declare `ts` variable when needed
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 24 Sep 2020 21:28:15 +0000 (17:28 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 24 Sep 2020 21:46:31 +0000 (17:46 -0400)
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 <eeppeliteloop@gmail.com>
barectf/templates/c/barectf.c-macros.j2
barectf/templates/c/barectf.c.j2

index ee14024eefcd8945d9bc24bc712872ae4fc28bd4..de91e93bbe8d3436830c041b7640366d15111474 100644 (file)
@@ -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);
index 5207f64d23d837a22fbe3b5a31ea218ed4474fd2..d4b4ee0ed40971d89aa43195845d9a5781a6c2f6 100644 (file)
@@ -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 %}
This page took 0.025095 seconds and 4 git commands to generate.