From d02c7d33ff9a0814d8ea97d10b4c840489c4e4e6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 3 Sep 2020 11:55:32 -0400 Subject: [PATCH] barectf.c.j2: use single return points Signed-off-by: Philippe Proulx --- barectf/templates/c/barectf.c.j2 | 41 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/barectf/templates/c/barectf.c.j2 b/barectf/templates/c/barectf.c.j2 index c5655f3..954df29 100644 --- a/barectf/templates/c/barectf.c.j2 +++ b/barectf/templates/c/barectf.c.j2 @@ -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 %} -- 2.34.1