From: Philippe Proulx Date: Fri, 28 Jun 2019 20:52:42 +0000 (-0400) Subject: lib: internal: graph.h: require logging and BT_ASSERT_{PRE,POST}() X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=51375aa95adf2f601f74a5a1f1665ca685584388 lib: internal: graph.h: require logging and BT_ASSERT_{PRE,POST}() This patch makes the internal `graph.h` require what it needs instead of using the macros only if they exist. This makes it impossible to skip logging or precondition/postcondition validation in this header. Signed-off-by: Philippe Proulx Change-Id: I157809be7b56720b2f4a241c45491413f5b8366d Reviewed-on: https://review.lttng.org/c/babeltrace/+/1577 Tested-by: jenkins Reviewed-by: Simon Marchi --- diff --git a/src/lib/graph/connection.c b/src/lib/graph/connection.c index 98379daf..4fa97a40 100644 --- a/src/lib/graph/connection.c +++ b/src/lib/graph/connection.c @@ -26,6 +26,7 @@ #include "common/assert.h" #include "lib/assert-pre.h" +#include "lib/assert-post.h" #include #include "lib/object.h" #include "compat/compiler.h" diff --git a/src/lib/graph/graph.h b/src/lib/graph/graph.h index f22b5800..ace6ca2e 100644 --- a/src/lib/graph/graph.h +++ b/src/lib/graph/graph.h @@ -38,6 +38,21 @@ #include "component-sink.h" #include "connection.h" +/* Protection: this file uses BT_LIB_LOG*() macros directly */ +#ifndef BT_LIB_LOG_SUPPORTED +# error Please include "lib/logging.h" before including this file. +#endif + +/* Protection: this file uses BT_ASSERT_PRE*() macros directly */ +#ifndef BT_ASSERT_PRE_SUPPORTED +# error Please include "lib/assert-pre.h" before including this file. +#endif + +/* Protection: this file uses BT_ASSERT_POST*() macros directly */ +#ifndef BT_ASSERT_POST_SUPPORTED +# error Please include "lib/assert-post.h" before including this file. +#endif + struct bt_component; struct bt_port; @@ -219,10 +234,7 @@ enum bt_graph_status bt_graph_configure(struct bt_graph *graph) goto end; } -#ifdef BT_ASSERT_PRE BT_ASSERT_PRE(graph->has_sink, "Graph has no sink component: %!+g", graph); -#endif - graph->config_state = BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED; for (i = 0; i < graph->components->len; i++) { @@ -242,38 +254,26 @@ enum bt_graph_status bt_graph_configure(struct bt_graph *graph) if (comp_cls_sink->methods.graph_is_configured) { enum bt_self_component_status comp_status; -#ifdef BT_LIB_LOGD BT_LIB_LOGD("Calling user's \"graph is configured\" method: " "%![graph-]+g, %![comp-]+c", graph, comp); -#endif - comp_status = comp_cls_sink->methods.graph_is_configured( (void *) comp_sink); - -#ifdef BT_LIB_LOGD BT_LIB_LOGD("User method returned: status=%s", bt_self_component_status_string(comp_status)); -#endif - -#ifdef BT_ASSERT_POST BT_ASSERT_POST(comp_status == BT_SELF_COMPONENT_STATUS_OK || comp_status == BT_SELF_COMPONENT_STATUS_ERROR || comp_status == BT_SELF_COMPONENT_STATUS_NOMEM, "Unexpected returned status: status=%s", bt_self_component_status_string(comp_status)); -#endif if (comp_status != BT_SELF_COMPONENT_STATUS_OK) { status = BT_GRAPH_STATUS_ERROR; -#ifdef BT_LIB_LOGW BT_LIB_LOGW("User's \"graph is configured\" method failed: " "%![comp-]+c, status=%s", comp, bt_self_component_status_string( comp_status)); -#endif - goto end; } } @@ -291,9 +291,7 @@ static inline void bt_graph_make_faulty(struct bt_graph *graph) { graph->config_state = BT_GRAPH_CONFIGURATION_STATE_FAULTY; -#ifdef BT_LIB_LOGI BT_LIB_LOGI("Set graph's state to faulty: %![graph-]+g", graph); -#endif } #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */ diff --git a/src/lib/graph/message/event.c b/src/lib/graph/message/event.c index 57f8c429..06370c0b 100644 --- a/src/lib/graph/message/event.c +++ b/src/lib/graph/message/event.c @@ -26,6 +26,7 @@ #include "common/assert.h" #include "lib/assert-pre.h" +#include "lib/assert-post.h" #include "compat/compiler.h" #include "lib/object.h" #include diff --git a/src/lib/graph/message/message.c b/src/lib/graph/message/message.c index d720a3bd..285bf8f8 100644 --- a/src/lib/graph/message/message.c +++ b/src/lib/graph/message/message.c @@ -26,6 +26,7 @@ #include "common/assert.h" #include "lib/assert-pre.h" +#include "lib/assert-post.h" #include #include "lib/graph/message/message.h" #include "lib/graph/graph.h" diff --git a/src/lib/graph/message/packet.c b/src/lib/graph/message/packet.c index 88de665b..13882395 100644 --- a/src/lib/graph/message/packet.c +++ b/src/lib/graph/message/packet.c @@ -24,6 +24,8 @@ #define BT_LOG_TAG "LIB/MSG-PACKET" #include "lib/logging.h" +#include "lib/assert-pre.h" +#include "lib/assert-post.h" #include "compat/compiler.h" #include #include "lib/trace-ir/packet.h" @@ -37,7 +39,6 @@ #include #include #include "common/assert.h" -#include "lib/assert-pre.h" #include "lib/object.h" #include diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 60ed8b6b..93a2c989 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -35,13 +35,15 @@ #include #include #include "common/common.h" -#include "lib/value.h" -#include "lib/value.h" -#include "lib/object-pool.h" #include #include #include +#include "logging.h" +#include "assert-pre.h" +#include "assert-post.h" +#include "value.h" +#include "object-pool.h" #include "graph/component-class.h" #include "graph/component-class-sink-colander.h" #include "graph/component-filter.h" @@ -59,7 +61,6 @@ #include "graph/message/stream-activity.h" #include "graph/message/stream.h" #include "graph/port.h" -#include "logging.h" #include "plugin/plugin.h" #include "plugin/plugin-so.h" #include "trace-ir/clock-class.h" @@ -75,7 +76,6 @@ #include "trace-ir/trace-class.h" #include "trace-ir/trace.h" #include "trace-ir/utils.h" -#include "assert-pre.h" #define LIB_LOGGING_BUF_SIZE (4096 * 4)