barectf.c.j2: use single return points
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:55:32 +0000 (11:55 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:55:32 +0000 (11:55 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/templates/c/barectf.c.j2

index c5655f34aad6f56a12cfaa99add8e263a1038cc8..954df29aa191eeb41a952cc8c3b1ec65bb808c7d 100644 (file)
@@ -148,12 +148,12 @@ void _write_c_str(struct {{ ctx_struct_name }} * const ctx, const char * const s
 static
 int _reserve_ev_space(void * const vctx, const uint32_t ev_size)
 {
+       int ret;
        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)) {
-               ctx->events_discarded++;
-               return 0;
+               goto no_space;
        }
 
        /* Packet is full? */
@@ -161,8 +161,7 @@ int _reserve_ev_space(void * const vctx, const uint32_t ev_size)
                /* Yes: is the back-end full? */
                if (ctx->cbs.is_backend_full(ctx->data)) {
                        /* Yes: discard event */
-                       ctx->events_discarded++;
-                       return 0;
+                       goto no_space;
                }
 
                /* Back-end is _not_ full: open new packet */
@@ -181,8 +180,7 @@ int _reserve_ev_space(void * const vctx, const uint32_t ev_size)
                /* Is the back-end full? */
                if (ctx->cbs.is_backend_full(ctx->data)) {
                        /* Yes: discard event */
-                       ctx->events_discarded++;
-                       return 0;
+                       goto no_space;
                }
 
                /* Back-end is _not_ full: open new packet */
@@ -192,7 +190,15 @@ int _reserve_ev_space(void * const vctx, const uint32_t ev_size)
                assert(ev_size <= (ctx->packet_size - ctx->at));
        }
 
-       return 1;
+       ret = 1;
+       goto end;
+
+no_space:
+       ctx->events_discarded++;
+       ret = 0;
+
+end:
+       return ret;
 }
 
 static
@@ -249,7 +255,7 @@ void _commit_ev(void * const vctx)
         */
        if (!ctx->is_tracing_enabled && !saved_in_tracing_section) {
                ctx->in_tracing_section = 0;
-               return;
+               goto end;
        }
 
        /* We can alter the packet */
@@ -258,7 +264,7 @@ void _commit_ev(void * const vctx)
        /* Do not open a packet that is already open */
        if (ctx->packet_is_open) {
                ctx->in_tracing_section = saved_in_tracing_section;
-               return;
+               goto end;
        }
 
        ctx->at = 0;
@@ -290,6 +296,9 @@ void _commit_ev(void * const vctx)
 
        /* Not tracing anymore */
        ctx->in_tracing_section = saved_in_tracing_section;
+
+end:
+       return;
 }
 
        {% include 'c/close-func-proto.j2' %}
@@ -314,7 +323,7 @@ void _commit_ev(void * const vctx)
         */
        if (!ctx->is_tracing_enabled && !saved_in_tracing_section) {
                ctx->in_tracing_section = 0;
-               return;
+               goto end;
        }
 
        /* We can alter the packet */
@@ -323,7 +332,7 @@ void _commit_ev(void * const vctx)
        /* Do not close a packet that is not open */
        if (!ctx->packet_is_open) {
                ctx->in_tracing_section = saved_in_tracing_section;
-               return;
+               goto end;
        }
 
        /* Save content size */
@@ -376,6 +385,9 @@ void _commit_ev(void * const vctx)
 
        /* Not tracing anymore */
        ctx->in_tracing_section = saved_in_tracing_section;
+
+end:
+       return;
 }
        {% if stream_type._ev_header_ft %}
 
@@ -520,7 +532,7 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const
                {% endif %}
 
        if (!ctx->is_tracing_enabled) {
-               return;
+               goto end;
        }
 
        /* We can alter the packet */
@@ -537,7 +549,7 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const
        if (!_reserve_ev_space(_TO_VOID_PTR(ctx), ev_size)) {
                /* no: forget this */
                ctx->in_tracing_section = 0;
-               return;
+               goto end;
        }
 
        /* Serialize event */
@@ -552,6 +564,9 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const
 
        /* Not tracing anymore */
        ctx->in_tracing_section = 0;
+
+end:
+       return;
 }
        {% endfor %}
 {% endfor %}
This page took 0.026278 seconds and 4 git commands to generate.