From 0d23acbeeb27ebede2278c50c2c7e0fe0b1ae8d2 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 19 Mar 2015 15:07:32 -0400 Subject: [PATCH] Fix: ir: make duplicate event classes check smarter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch makes bt_ctf_stream_class_add_event_class() compare not only event classes pointers when checking for duplicate, but also equal names and equal IDs. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/stream-class.c | 47 ++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 0f823ea7..9ef5ca79 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -220,6 +220,50 @@ end: return ret; } +static +void event_class_exists(gpointer element, gpointer query) +{ + struct bt_ctf_event_class *event_class_a = element; + struct search_query *search_query = query; + struct bt_ctf_event_class *event_class_b = search_query->value; + int64_t id_a, id_b; + + if (search_query->value == element) { + search_query->found = 1; + 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. + */ + id_a = bt_ctf_event_class_get_id(event_class_a); + id_b = bt_ctf_event_class_get_id(event_class_b); + + if (id_a < 0 || id_b < 0) { + /* at least one ID is not set: will be automatically set later */ + goto end; + } + + if (id_a == id_b) { + search_query->found = 1; + goto end; + } + +end: + return; +} + int bt_ctf_stream_class_add_event_class( struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class) @@ -234,7 +278,8 @@ int bt_ctf_stream_class_add_event_class( /* Check for duplicate event classes */ struct search_query query = { .value = event_class, .found = 0 }; - g_ptr_array_foreach(stream_class->event_classes, value_exists, &query); + g_ptr_array_foreach(stream_class->event_classes, event_class_exists, + &query); if (query.found) { ret = -1; goto end; -- 2.34.1