From a9f0d01b276e2bb637ad4bea1e8863e144911f55 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 27 Apr 2017 19:06:09 -0400 Subject: [PATCH] Remove bt_ctf_stream_class_get_event_class_by_name() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit CTF allows two event classes of the same stream class to have the same name, but all event classes must have a unique ID. Remove bt_ctf_stream_class_get_event_class_by_name() because this would need to return a set of event classes, not just one, and this feature is not strictly needed for the 2.0 target. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/stream-class.h | 25 ------------- lib/ctf-ir/stream-class.c | 36 ------------------- .../ctf/common/metadata/visitor-generate-ir.c | 10 ------ plugins/debug-info/copy.c | 4 +-- plugins/writer/write.c | 4 +-- tests/lib/test_ctf_writer.c | 17 ++------- 6 files changed, 7 insertions(+), 89 deletions(-) diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index 6a0e2e13..63d7e7d0 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -496,32 +496,10 @@ extern int64_t bt_ctf_stream_class_get_event_class_count( @sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class by ID. -@sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class - by name. */ extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index( struct bt_ctf_stream_class *stream_class, uint64_t index); -/** -@brief Returns the event class named \c name found in the CTF IR stream - class \p stream_class. - -@param[in] stream_class Stream class of which to get the event class. -@param[in] name Name of the event class to find. -@returns Event class named \p name, or \c NULL - on error. - -@prenotnull{stream_class} -@prenotnull{name} -@postrefcountsame{stream_class} -@postsuccessrefcountretinc - -@sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class - by ID. -*/ -extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( - struct bt_ctf_stream_class *stream_class, const char *name); - /** @brief Returns the event class with ID \c id found in the CTF IR stream class \p stream_class. @@ -534,9 +512,6 @@ extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( @prenotnull{stream_class} @postrefcountsame{stream_class} @postsuccessrefcountretinc - -@sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class - by name. */ extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( struct bt_ctf_stream_class *stream_class, uint64_t id); diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index f9d91aaf..97b6e659 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -284,16 +284,6 @@ void event_class_exists(gpointer element, gpointer query) goto end; } - /* - * Two event classes cannot share the same name in a given - * stream class. - */ - if (!strcmp(bt_ctf_event_class_get_name(event_class_a), - bt_ctf_event_class_get_name(event_class_b))) { - search_query->found = 1; - goto end; - } - /* * Two event classes cannot share the same ID in a given * stream class. @@ -520,32 +510,6 @@ end: return event_class; } -struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( - struct bt_ctf_stream_class *stream_class, const char *name) -{ - size_t i; - struct bt_ctf_event_class *event_class = NULL; - - if (!stream_class || !name) { - goto end; - } - - for (i = 0; i < stream_class->event_classes->len; i++) { - struct bt_ctf_event_class *cur_event_class = - g_ptr_array_index(stream_class->event_classes, i); - const char *cur_event_class_name = - bt_ctf_event_class_get_name(cur_event_class); - - if (!strcmp(name, cur_event_class_name)) { - event_class = cur_event_class; - bt_get(event_class); - goto end; - } - } -end: - return event_class; -} - struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( struct bt_ctf_stream_class *stream_class, uint64_t id) { diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index cb50a7e7..1572206c 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -3506,16 +3506,6 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - eevent_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, - event_name); - if (eevent_class) { - BT_PUT(eevent_class); - _PERROR("%s", - "duplicate event with name \"%s\" in same stream"); - ret = -EEXIST; - goto error; - } - ret = bt_ctf_stream_class_add_event_class(stream_class, event_class); BT_PUT(event_class); if (ret) { diff --git a/plugins/debug-info/copy.c b/plugins/debug-info/copy.c index 55cf1351..824774ff 100644 --- a/plugins/debug-info/copy.c +++ b/plugins/debug-info/copy.c @@ -981,8 +981,8 @@ struct bt_ctf_event_class *get_event_class(struct debug_info_iterator *debug_it, struct bt_ctf_stream_class *writer_stream_class, struct bt_ctf_event_class *event_class) { - return bt_ctf_stream_class_get_event_class_by_name(writer_stream_class, - bt_ctf_event_class_get_name(event_class)); + return bt_ctf_stream_class_get_event_class_by_id(writer_stream_class, + bt_ctf_event_class_get_id(event_class)); } static diff --git a/plugins/writer/write.c b/plugins/writer/write.c index cd692db2..91b92899 100644 --- a/plugins/writer/write.c +++ b/plugins/writer/write.c @@ -155,8 +155,8 @@ struct bt_ctf_event_class *get_event_class(struct writer_component *writer_compo struct bt_ctf_stream_class *writer_stream_class, struct bt_ctf_event_class *event_class) { - return bt_ctf_stream_class_get_event_class_by_name(writer_stream_class, - bt_ctf_event_class_get_name(event_class)); + return bt_ctf_stream_class_get_event_class_by_id(writer_stream_class, + bt_ctf_event_class_get_id(event_class)); } struct bt_ctf_writer *insert_new_writer( diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 7ea4b583..9a790bbc 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -61,7 +61,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 611 +#define NR_TESTS 607 static int64_t current_time = 42; @@ -434,17 +434,6 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, "bt_ctf_stream_class_get_event_class_by_id returns a correct event class"); bt_put(ret_event_class); - ok(bt_ctf_stream_class_get_event_class_by_name(NULL, "some event name") == NULL, - "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly"); - ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, NULL) == NULL, - "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly"); - ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, "some event name") == NULL, - "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly"); - ret_event_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, "Simple Event"); - ok(ret_event_class == simple_event_class, - "bt_ctf_stream_class_get_event_class_by_name returns a correct event class"); - bt_put(ret_event_class); - simple_event = bt_ctf_event_create(simple_event_class); ok(simple_event, "Instantiate an event containing a single integer field"); @@ -2500,8 +2489,8 @@ void append_existing_event_class(struct bt_ctf_stream_class *stream_class) event_class = bt_ctf_event_class_create("Simple Event"); assert(event_class); - ok(bt_ctf_stream_class_add_event_class(stream_class, event_class), - "two event classes with the same name cannot cohabit within the same stream class"); + ok(bt_ctf_stream_class_add_event_class(stream_class, event_class) == 0, + "two event classes with the same name may cohabit within the same stream class"); bt_put(event_class); event_class = bt_ctf_event_class_create("different name, ok"); -- 2.34.1