lib: internal: graph.h: require logging and BT_ASSERT_{PRE,POST}()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 20:52:42 +0000 (16:52 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 29 Jun 2019 06:04:08 +0000 (02:04 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: I157809be7b56720b2f4a241c45491413f5b8366d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1577
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/lib/graph/connection.c
src/lib/graph/graph.h
src/lib/graph/message/event.c
src/lib/graph/message/message.c
src/lib/graph/message/packet.c
src/lib/lib-logging.c

index 98379daf5150556ab3adc085dab1679e28eb5c31..4fa97a40f7fb012fc1aed5ab8ff8c8653da43a7d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "common/assert.h"
 #include "lib/assert-pre.h"
+#include "lib/assert-post.h"
 #include <babeltrace2/graph/connection-const.h>
 #include "lib/object.h"
 #include "compat/compiler.h"
index f22b5800c7fe2bc2bc441a1156ba2242ea3f58ec..ace6ca2edabf9d7765b764359626c6f9289d7b27 100644 (file)
 #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 */
index 57f8c42999c74b2aeb5ee94f3529c082df24250e..06370c0ba69cb502b8318e0debcb0f32ca98f28f 100644 (file)
@@ -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 <babeltrace2/trace-ir/event.h>
index d720a3bdbfc23549c8f8c58250ec981f07db3b3d..285bf8f8367e88d46ab17748d70766ab3aee9ca5 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "common/assert.h"
 #include "lib/assert-pre.h"
+#include "lib/assert-post.h"
 #include <babeltrace2/graph/message-const.h>
 #include "lib/graph/message/message.h"
 #include "lib/graph/graph.h"
index 88de665b79a656584cfb7d8b002f51ef3c3052c6..13882395d610bf7f9a9c4e15052ccfc21ea08e9b 100644 (file)
@@ -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 <babeltrace2/trace-ir/packet.h>
 #include "lib/trace-ir/packet.h"
@@ -37,7 +39,6 @@
 #include <babeltrace2/graph/message-packet-beginning.h>
 #include <babeltrace2/graph/message-packet-end.h>
 #include "common/assert.h"
-#include "lib/assert-pre.h"
 #include "lib/object.h"
 #include <inttypes.h>
 
index 60ed8b6b82bafc2d6522537da4d6cd2dad470ddf..93a2c989f5aa0adf7b9d911741e127bedc214b92 100644 (file)
 #include <wchar.h>
 #include <glib.h>
 #include "common/common.h"
-#include "lib/value.h"
-#include "lib/value.h"
-#include "lib/object-pool.h"
 #include <babeltrace2/trace-ir/event-const.h>
 #include <babeltrace2/trace-ir/packet-const.h>
 #include <babeltrace2/trace-ir/stream-const.h>
 
+#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)
 
This page took 0.02794 seconds and 4 git commands to generate.