From 97f261eb8a2edd7861534455b3ddd3d35fdbded2 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 14 Apr 2020 14:33:24 -0400 Subject: [PATCH] sink.text.pretty: simplify error handling in pretty_consume Replace the switch with a simple condition. On _END, it is not necessary to put the message iterator, that will be done in pretty_finalize. Change-Id: Ia0bd20e0d119cae155c03cc5d7656a5c4619ebb8 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/3406 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/text/pretty/pretty.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/plugins/text/pretty/pretty.c b/src/plugins/text/pretty/pretty.c index 480f0fcb..a114818f 100644 --- a/src/plugins/text/pretty/pretty.c +++ b/src/plugins/text/pretty/pretty.c @@ -162,8 +162,7 @@ BT_HIDDEN bt_component_class_sink_consume_method_status pretty_consume( bt_self_component_sink *comp) { - bt_component_class_sink_consume_method_status ret = - BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; + bt_component_class_sink_consume_method_status status; bt_message_array_const msgs; bt_message_iterator *it; struct pretty_component *pretty = bt_self_component_get_data( @@ -175,29 +174,14 @@ bt_component_class_sink_consume_method_status pretty_consume( it = pretty->iterator; next_status = bt_message_iterator_next(it, &msgs, &count); - - switch (next_status) { - case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: - break; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: - case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: - ret = (int) next_status; - goto end; - case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: - ret = (int) next_status; - BT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( - pretty->iterator); - goto end; - default: - ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + if (next_status != BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) { + status = (int) next_status; goto end; } - BT_ASSERT_DBG(next_status == BT_MESSAGE_ITERATOR_NEXT_STATUS_OK); - for (i = 0; i < count; i++) { - ret = (int) handle_message(pretty, msgs[i]); - if (ret) { + status = (int) handle_message(pretty, msgs[i]); + if (status) { goto end; } @@ -209,7 +193,7 @@ end: bt_message_put_ref(msgs[i]); } - return ret; + return status; } static -- 2.34.1