Make generated C code as `const` as possible
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:19:36 +0000 (11:19 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:23:03 +0000 (11:23 -0400)
This patch changes `gen.py` and many C-generating templates to make
barectf generate C code with as many `const` variables as possible.

The Jinja 2 `ft_c_type` filter now accepts a parameter to make the
returned C type `const`.

All the `*_params_str` filters also do; the reason is that I don't want
the public header to show those useless `const` parameters (for
variables), but I want the same parameters to be `const` in the C source
file.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
12 files changed:
barectf/gen.py
barectf/templates/c/barectf.c-macros.j2
barectf/templates/c/barectf.c.j2
barectf/templates/c/barectf.h.j2
barectf/templates/c/close-func-proto.j2
barectf/templates/c/common.j2
barectf/templates/c/ctx-init-func-proto.j2
barectf/templates/c/func-proto-params.j2
barectf/templates/c/open-func-proto.j2
barectf/templates/c/serialize-write-bit-array-statements.j2
barectf/templates/c/serialize-write-uuid-statements.j2
barectf/templates/c/trace-func-proto.j2

index ae36036207ce70e95ceb58cdea94cb1fd6a6af23..073f328aae8d79d4d9ee8b3e3d96ed8caa42df1c 100644 (file)
@@ -453,8 +453,11 @@ class _CCodeGenerator:
     def _trace_type(self):
         return self._cfg.trace.type
 
-    # Returns the C type for the field type `ft`.
-    def _ft_c_type(self, ft):
+    # Returns the C type for the field type `ft`, returning a `const` C
+    # type if `is_const` is `True`.
+    def _ft_c_type(self, ft, is_const=False):
+        const_beg_str = 'const '
+
         if isinstance(ft, barectf_config._IntegerFieldType):
             sign_prefix = 'u' if isinstance(ft, barectf_config.UnsignedIntegerFieldType) else ''
 
@@ -468,17 +471,19 @@ class _CCodeGenerator:
                 assert ft.size <= 64
                 sz = 64
 
-            return f'{sign_prefix}int{sz}_t'
+            return f'{const_beg_str if is_const else ""}{sign_prefix}int{sz}_t'
         elif type(ft) is barectf_config.RealFieldType:
             if ft.size == 32 and ft.alignment == 32:
-                return 'float'
+                c_type = 'float'
             elif ft.size == 64 and ft.alignment == 64:
-                return 'double'
+                c_type = 'double'
             else:
-                return 'uint64_t'
+                c_type = 'uint64_t'
+
+            return f'{const_beg_str if is_const else ""}{c_type}'
         else:
             assert type(ft) is barectf_config.StringFieldType
-            return 'const char *'
+            return f'const char *{" const" if is_const else ""}'
 
     # Returns the function prototype parameters for the members of the
     # root structure field type `root_ft`.
@@ -486,7 +491,7 @@ class _CCodeGenerator:
     # Each parameter has the prefix `name_prefix` followed with `_`.
     #
     # Members of which the name is in `exclude_set` are excluded.
-    def _proto_params_str(self, root_ft, name_prefix, exclude_set=None):
+    def _proto_params_str(self, root_ft, name_prefix, const_params, exclude_set=None):
         if root_ft is None:
             return
 
@@ -501,14 +506,15 @@ class _CCodeGenerator:
 
             params.append(_FtParam(member.field_type, member_name))
 
-        return self._func_proto_params_templ.render(params=params, prefix=name_prefix)
+        return self._func_proto_params_templ.render(params=params, prefix=name_prefix,
+                                                    const_params=const_params)
 
     # Returns the packet opening function prototype parameters for the
     # stream type `stream_type`.
-    def _open_func_params_str(self, stream_type):
+    def _open_func_params_str(self, stream_type, const_params):
         parts = []
         parts.append(self._proto_params_str(self._trace_type._pkt_header_ft, _RootFtPrefixes.PH,
-                                            {'magic', 'stream_id', 'uuid'}))
+                                            const_params, {'magic', 'stream_id', 'uuid'}))
 
         exclude_set = {
             'timestamp_begin',
@@ -518,38 +524,39 @@ class _CCodeGenerator:
             'events_discarded',
         }
         parts.append(self._proto_params_str(stream_type._pkt_ctx_ft, _RootFtPrefixes.PC,
-                                            exclude_set))
+                                            const_params, exclude_set))
         return ''.join(parts)
 
     # Returns the tracing function prototype parameters for the stream
     # and event types `stream_ev_types`.
-    def _trace_func_params_str(self, stream_ev_types):
+    def _trace_func_params_str(self, stream_ev_types, const_params):
         stream_type = stream_ev_types[0]
         ev_type = stream_ev_types[1]
         parts = []
 
         if stream_type._ev_header_ft is not None:
             parts.append(self._proto_params_str(stream_type._ev_header_ft, _RootFtPrefixes.EH,
-                                                {'id', 'timestamp'}))
+                                                const_params, {'id', 'timestamp'}))
 
         if stream_type.event_common_context_field_type is not None:
             parts.append(self._proto_params_str(stream_type.event_common_context_field_type,
-                                                _RootFtPrefixes.ECC))
+                                                _RootFtPrefixes.ECC, const_params))
 
         if ev_type.specific_context_field_type is not None:
             parts.append(self._proto_params_str(ev_type.specific_context_field_type,
-                                                _RootFtPrefixes.SC))
+                                                _RootFtPrefixes.SC, const_params))
 
         if ev_type.payload_field_type is not None:
-            parts.append(self._proto_params_str(ev_type.payload_field_type, _RootFtPrefixes.P))
+            parts.append(self._proto_params_str(ev_type.payload_field_type, _RootFtPrefixes.P,
+                                                const_params))
 
         return ''.join(parts)
 
     # Returns the event header serialization function prototype
     # parameters for the stream type `stream_type`.
-    def _serialize_ev_common_ctx_func_params_str(self, stream_type):
+    def _serialize_ev_common_ctx_func_params_str(self, stream_type, const_params):
         return self._proto_params_str(stream_type.event_common_context_field_type,
-                                      _RootFtPrefixes.ECC);
+                                      _RootFtPrefixes.ECC, const_params);
 
     # Generates the bitfield header file contents.
     def generate_bitfield_header(self):
index b890faa1293a63be3e73f49d4279e62c5e0332ed..4ed0add297d38b13b9db5b682bad559fdd2f73a7 100644 (file)
@@ -34,7 +34,7 @@
  # the stream type `stream_type`.
  #}
 {% macro open_close_func_preamble(stream_type) %}
-struct {{ prefix }}ctx *ctx = &sctx->parent;
+struct {{ prefix }}ctx * const ctx = &sctx->parent;
 {% if stream_type.default_clock_type %}
 const {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} ts = ctx->use_cur_last_event_ts ?
        sctx->cur_last_event_ts :
index 88573e1b02a78f993e7712c050d7b857983056e3..6e7d54791c5c0f9b53d326dfd66dd62f99d9e1c6 100644 (file)
@@ -29,6 +29,7 @@
 {% set ucprefix = common.ucprefix %}
 {% set ctx_struct_name = c_common.ctx_struct_name %}
 {% set cg_opts = cfg.options.code_generation_options %}
+{% set const_params = true %}
 {% include 'licence-header.j2' %}
 
 
@@ -65,88 +66,89 @@ union _d2u {
        uint64_t u;
 };
 
-uint32_t {{ prefix }}packet_size(void *ctx)
+uint32_t {{ prefix }}packet_size(const void * const ctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, ctx)->packet_size;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, ctx)->packet_size;
 }
 
-int {{ prefix }}packet_is_full(void *vctx)
+int {{ prefix }}packet_is_full(const void * const vctx)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx);
 
        return ctx->at == ctx->packet_size;
 }
 
-int {{ prefix }}packet_is_empty(void *vctx)
+int {{ prefix }}packet_is_empty(const void * const vctx)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx);
 
        return ctx->at <= ctx->off_content;
 }
 
-uint32_t {{ prefix }}packet_events_discarded(void *vctx)
+uint32_t {{ prefix }}packet_events_discarded(const void * const vctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->events_discarded;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->events_discarded;
 }
 
-uint8_t *{{ prefix }}packet_buf(void *vctx)
+uint8_t *{{ prefix }}packet_buf(const void * const vctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->buf;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->buf;
 }
 
-uint32_t {{ prefix }}packet_buf_size(void *vctx)
+uint32_t {{ prefix }}packet_buf_size(const void * const vctx)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx);
 
        return _BITS_TO_BYTES(ctx->packet_size);
 }
 
-void {{ prefix }}packet_set_buf(void *vctx, uint8_t *buf, uint32_t buf_size)
+void {{ prefix }}packet_set_buf(void * const vctx, uint8_t * const buf,
+               const uint32_t buf_size)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
 
        ctx->buf = buf;
        ctx->packet_size = _BYTES_TO_BITS(buf_size);
 }
 
-int {{ prefix }}packet_is_open(void *vctx)
+int {{ prefix }}packet_is_open(const void * const vctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->packet_is_open;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->packet_is_open;
 }
 
-int {{ prefix }}is_in_tracing_section(void *vctx)
+int {{ prefix }}is_in_tracing_section(const void * const vctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->in_tracing_section;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->in_tracing_section;
 }
 
-volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *vctx)
+volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void * const vctx)
 {
-       return &_FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->in_tracing_section;
+       return &_FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->in_tracing_section;
 }
 
-int {{ prefix }}is_tracing_enabled(void *vctx)
+int {{ prefix }}is_tracing_enabled(const void * const vctx)
 {
-       return _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->is_tracing_enabled;
+       return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->is_tracing_enabled;
 }
 
-void {{ prefix }}enable_tracing(void *vctx, int enable)
+void {{ prefix }}enable_tracing(void * const vctx, const int enable)
 {
        _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->is_tracing_enabled = enable;
 }
 
 static
-void _write_c_str(struct {{ ctx_struct_name }} *ctx, const char *src)
+void _write_c_str(struct {{ ctx_struct_name }} * const ctx, const char * const src)
 {
-       uint32_t sz = strlen(src) + 1;
+       const uint32_t sz = strlen(src) + 1;
 
        memcpy(&ctx->buf[_BITS_TO_BYTES(ctx->at)], src, sz);
        ctx->at += _BYTES_TO_BITS(sz);
 }
 
 static
-int _reserve_ev_space(void *vctx, uint32_t ev_size)
+int _reserve_ev_space(void * const vctx, const uint32_t ev_size)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
 
        /* event _cannot_ fit? */
        if (ev_size > (ctx->packet_size - ctx->off_content)) {
@@ -194,9 +196,9 @@ int _reserve_ev_space(void *vctx, uint32_t ev_size)
 }
 
 static
-void _commit_ev(void *vctx)
+void _commit_ev(void * const vctx)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
 
        /* is packet full? */
        if ({{ prefix }}packet_is_full(ctx)) {
@@ -208,7 +210,7 @@ void _commit_ev(void *vctx)
 {% include 'c/ctx-init-func-proto.j2' %}
 
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
        ctx->cbs = cbs;
        ctx->data = data;
        ctx->buf = buf;
@@ -377,12 +379,12 @@ void _commit_ev(void *vctx)
 }
        {% if stream_type._ev_header_ft %}
 
-static void _serialize_ev_header_{{ stream_type.name }}(void *vctx,
-       uint32_t ev_type_id)
+static void _serialize_ev_header_{{ stream_type.name }}(void * const vctx,
+       const uint32_t ev_type_id)
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
                {% if def_clk_type %}
-       struct {{ sctx_name }}_ctx *sctx = _FROM_VOID_PTR(struct {{ sctx_name }}_ctx, vctx);
+       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 %}
 
@@ -397,9 +399,9 @@ static void _serialize_ev_header_{{ stream_type.name }}(void *vctx,
        {% endif %}
        {% if stream_type.event_common_context_field_type %}
 
-static void _serialize_ev_common_ctx_{{ stream_type.name }}(void *vctx{{ stream_type | serialize_ev_common_ctx_func_params_str }})
+static void _serialize_ev_common_ctx_{{ stream_type.name }}(void * const vctx{{ stream_type | serialize_ev_common_ctx_func_params_str(const_params) }})
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
 
        /* serialize event common context */
        {
@@ -413,9 +415,9 @@ static void _serialize_ev_common_ctx_{{ stream_type.name }}(void *vctx{{ stream
        {# internal serialization functions #}
        {% for ev_type in stream_type.event_types | sort %}
 
-static void _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(void *vctx{{ (stream_type, ev_type) | trace_func_params_str }})
+static void _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params) }})
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
                {% if stream_type._ev_header_ft %}
 
        /* serialize header */
@@ -454,9 +456,9 @@ static void _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(void *vctx{{
        {% for ev_type in stream_type.event_types | sort %}
                {% set this_ev_ops = this_stream_ops.ev_ops[ev_type] %}
 
-static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void *vctx{{ (stream_type, ev_type) | trace_func_params_str }})
+static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params) }})
 {
-       struct {{ ctx_struct_name }} *ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
+       struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
        uint32_t at = ctx->at;
                {% if this_stream_ops.ev_header_ops %}
 
@@ -508,7 +510,7 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void *vctx{{
                {% include 'c/trace-func-proto.j2' %}
 
 {
-       struct {{ ctx_struct_name }} *ctx = &sctx->parent;
+       struct {{ ctx_struct_name }} * const ctx = &sctx->parent;
        uint32_t ev_size;
 
                {% if def_clk_type %}
index 6c75a131c3803236f821548da172edc84b0dbf55..b6f18e2fd53b00ba10e4b077a4d41e5f8cef68ad 100644 (file)
@@ -30,6 +30,7 @@
 {% set cg_opts = cfg.options.code_generation_options %}
 {% set def_stream_type = cg_opts.default_stream_type %}
 {% set header_opts = cg_opts.header_options %}
+{% set const_params = false %}
 #ifndef _{{ ucprefix }}H
 #define _{{ ucprefix }}H
 
@@ -57,17 +58,17 @@ extern "C" {
 
 struct {{ prefix }}ctx;
 
-uint32_t {{ prefix }}packet_size(void *ctx);
-int {{ prefix }}packet_is_full(void *ctx);
-int {{ prefix }}packet_is_empty(void *ctx);
-uint32_t {{ prefix }}packet_events_discarded(void *ctx);
-uint8_t *{{ prefix }}packet_buf(void *ctx);
+uint32_t {{ prefix }}packet_size(const void *ctx);
+int {{ prefix }}packet_is_full(const void *ctx);
+int {{ prefix }}packet_is_empty(const void *ctx);
+uint32_t {{ prefix }}packet_events_discarded(const void *ctx);
+uint8_t *{{ prefix }}packet_buf(const void *ctx);
 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
-uint32_t {{ prefix }}packet_buf_size(void *ctx);
-int {{ prefix }}packet_is_open(void *ctx);
-int {{ prefix }}is_in_tracing_section(void *ctx);
-volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx);
-int {{ prefix }}is_tracing_enabled(void *ctx);
+uint32_t {{ prefix }}packet_buf_size(const void *ctx);
+int {{ prefix }}packet_is_open(const void *ctx);
+int {{ prefix }}is_in_tracing_section(const void *ctx);
+volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void *ctx);
+int {{ prefix }}is_tracing_enabled(const void *ctx);
 void {{ prefix }}enable_tracing(void *ctx, int enable);
 
 /* barectf platform callbacks */
index a7b9f9819878ce64f30d1b96e58cd99072013db0..51ba42dec813d28fcc959e8c3aa9d7ea532aae83 100644 (file)
@@ -23,5 +23,6 @@
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  #}
 {% import 'common.j2' as common %}
+{% import 'c/common.j2' as c_common %}
 /* close packet for stream type `{{ stream_type.name }}` */
-void {{ common.prefix }}{{ stream_type.name }}_close_packet(struct {{ common.prefix }}{{ stream_type.name }}_ctx *sctx)
+void {{ common.prefix }}{{ stream_type.name }}_close_packet(struct {{ common.prefix }}{{ stream_type.name }}_ctx *{{ c_common.const_ptr_str(const_params) }}sctx)
index 6715a78b6d142f2f78352c3c88ee99b6911e9276..96e8dfb0e4e7fe53a6ecd1d0d3cf9f03c94555b7 100644 (file)
 {% macro op_src(op) %}
 {{ op.names | join('_') }}
 {%- endmacro %}
+
+{#
+ # Generates:
+ #
+ # If `is_const` is `true`:
+ #     The string ` const `.
+ #
+ # Otherwise:
+ #     An empty string.
+ #}
+{% macro const_ptr_str(is_const) %}
+{{ ' const ' if is_const else '' }}
+{%- endmacro %}
+
+{#
+ # Generates:
+ #
+ # If `is_const` is `true`:
+ #     The string `const `.
+ #
+ # Otherwise:
+ #     An empty string.
+ #}
+{% macro const_str(is_const) %}
+{{ 'const ' if is_const else '' }}
+{%- endmacro %}
index a99732fa7045485db9a85a2eab392b04caf8a7b2..c7a1405aa02c83b3c580d968336739a70fc7207f 100644 (file)
@@ -23,7 +23,8 @@
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  #}
 {% import 'common.j2' as common %}
+{% import 'c/common.j2' as c_common %}
 /* initialize context */
 void {{ common.prefix }}init(void *vctx,
-       uint8_t *buf, uint32_t buf_size,
-       struct {{ common.prefix }}platform_callbacks cbs, void *data)
+       uint8_t *{{ c_common.const_ptr_str(const_params) }}buf, {{ c_common.const_str(const_params) }}uint32_t buf_size,
+       const struct {{ common.prefix }}platform_callbacks cbs, void *{{ c_common.const_ptr_str(const_params) }}data)
index 5d30cc599bcfec671f3c459a7272f60dd4bed243..10af15061a58c199a1ccf5b10ac419fb828edc4d 100644 (file)
@@ -23,6 +23,6 @@
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  #}
 {% for param in params %}
-    {% set c_type = param.ft | ft_c_type %},
+       {% set c_type = param.ft | ft_c_type(const_params) %},
        {{ c_type }}{{ ' ' if not c_type.endswith('*') }}{{ prefix }}_{{ param.name }}
 {%- endfor %}
index 919543b1e9e605f05560b8614e0fc78bb559b07d..60cd3a4aa3edaff0409f9b391b6f86828f3b2127 100644 (file)
@@ -23,6 +23,7 @@
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  #}
 {% import 'common.j2' as common %}
+{% import 'c/common.j2' as c_common %}
 /* open packet for stream type `{{ stream_type.name }}` */
 void {{ common.prefix }}{{ stream_type.name }}_open_packet(
-       struct {{ common.prefix }}{{ stream_type.name }}_ctx *sctx{{ stream_type | open_func_params_str }})
+       struct {{ common.prefix }}{{ stream_type.name }}_ctx *{{ c_common.const_ptr_str(const_params) }}sctx{{ stream_type | open_func_params_str(const_params) }})
index 285cd464adc46d9a7db9790272d5c675c4daec7c..006ab769355e2a33aeae61d6bd379bc4bfa60ecc 100644 (file)
@@ -24,7 +24,8 @@
  #}
 {% import 'common.j2' as common %}
 {% set bo = 'le' if op.ft.byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' %}
+{% set c_type_non_const = c_type | replace('const ', '') %}
 bt_bitfield_write_{{ bo }}(&ctx->buf[_BITS_TO_BYTES(ctx->at)],
-       uint8_t, {{ op.offset_in_byte }}, {{ op.ft.size }}, {{ c_type }},
-       ({{ c_type }}) {{ src }});
+       uint8_t, {{ op.offset_in_byte }}, {{ op.ft.size }}, {{ c_type_non_const }},
+       ({{ c_type_non_const }}) {{ src }});
 ctx->at += {{ op.ft.size }};
index 825b5a8e6550d8767fd2301fa50cc272afa5c671..e4ade0c5d228bde9e2805333f6d9777588435260 100644 (file)
@@ -24,7 +24,7 @@
  #}
 /* write UUID */
 {
-       static uint8_t uuid[] = {
+       static const uint8_t uuid[] = {
 {% for row in cfg.trace.type.uuid.bytes | batch(4) %}
                {{ row | join(', ') }},
 {% endfor %}
index 9b221ef4a36c09f794cfa5ea8ac5ea4dd8deef14..a25cd67bb29d2b13c75782439aa271fc01132e43 100644 (file)
@@ -23,5 +23,6 @@
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  #}
 {% import 'common.j2' as common %}
+{% import 'c/common.j2' as c_common %}
 /* trace (stream type `{{ stream_type.name }}`, event type `{{ ev_type.name }}`) */
-void {{ common.prefix }}{{ stream_type.name }}_trace_{{ ev_type.name }}(struct {{ common.prefix }}{{ stream_type.name }}_ctx *sctx{{ (stream_type, ev_type) | trace_func_params_str }})
+void {{ common.prefix }}{{ stream_type.name }}_trace_{{ ev_type.name }}(struct {{ common.prefix }}{{ stream_type.name }}_ctx *{{ c_common.const_ptr_str(const_params) }}sctx{{ (stream_type, ev_type) | trace_func_params_str(const_params) }})
This page took 0.034592 seconds and 4 git commands to generate.