X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=lib%2Fctf-ir%2Ffield-path.c;h=ceb54bf5dc2e2db09d9cc71745bc377b401a66e1;hb=7b33a0e0d8f23d90285ea7c7820a725bcbd96c6b;hp=bc991f4070943d5d0c901bdbb81ac5b0d634b5ff;hpb=9ac68eb139149d2768848dae5e263cc5a755d439;p=babeltrace.git diff --git a/lib/ctf-ir/field-path.c b/lib/ctf-ir/field-path.c index bc991f40..ceb54bf5 100644 --- a/lib/ctf-ir/field-path.c +++ b/lib/ctf-ir/field-path.c @@ -25,114 +25,77 @@ * SOFTWARE. */ +#define BT_LOG_TAG "FIELD-PATH" +#include + +#include #include +#include #include #include #include #include +#include +#include #include static -void field_path_destroy(struct bt_object *obj) +void destroy_field_path(struct bt_object *obj) { - struct bt_ctf_field_path *field_path = (struct bt_ctf_field_path *) obj; + struct bt_field_path *field_path = (struct bt_field_path *) obj; - if (!field_path) { - return; - } - - if (field_path->indexes) { - g_array_free(field_path->indexes, TRUE); - } + BT_ASSERT(field_path); + BT_LIB_LOGD("Destroying field path: %!+P", field_path); + g_array_free(field_path->indexes, TRUE); g_free(field_path); } BT_HIDDEN -struct bt_ctf_field_path *bt_ctf_field_path_create(void) +struct bt_field_path *bt_field_path_create(void) { - struct bt_ctf_field_path *field_path = NULL; + struct bt_field_path *field_path = NULL; - field_path = g_new0(struct bt_ctf_field_path, 1); + BT_LOGD_STR("Creating empty field path object."); + + field_path = g_new0(struct bt_field_path, 1); if (!field_path) { + BT_LOGE_STR("Failed to allocate one field path."); goto error; } - bt_object_init(field_path, field_path_destroy); - field_path->root = BT_CTF_SCOPE_UNKNOWN; - field_path->indexes = g_array_new(TRUE, FALSE, sizeof(int)); + bt_object_init_shared(&field_path->base, destroy_field_path); + field_path->indexes = g_array_new(FALSE, FALSE, sizeof(uint64_t)); if (!field_path->indexes) { + BT_LOGE_STR("Failed to allocate a GArray."); goto error; } - return field_path; + BT_LIB_LOGD("Created empty field path object: %!+P", field_path); + goto end; error: BT_PUT(field_path); - return NULL; -} -BT_HIDDEN -void bt_ctf_field_path_clear(struct bt_ctf_field_path *field_path) -{ - if (field_path->indexes->len > 0) { - g_array_remove_range(field_path->indexes, 0, - field_path->indexes->len); - } -} - -BT_HIDDEN -struct bt_ctf_field_path *bt_ctf_field_path_copy( - struct bt_ctf_field_path *path) -{ - struct bt_ctf_field_path *new_path = bt_ctf_field_path_create(); - - if (!new_path) { - goto end; - } - - new_path->root = path->root; - g_array_insert_vals(new_path->indexes, 0, - path->indexes->data, path->indexes->len); end: - return new_path; + return field_path; } -enum bt_ctf_scope bt_ctf_field_path_get_root_scope( - const struct bt_ctf_field_path *field_path) +enum bt_scope bt_field_path_get_root_scope(struct bt_field_path *field_path) { - enum bt_ctf_scope scope = BT_CTF_SCOPE_UNKNOWN; - - if (!field_path) { - goto end; - } - - scope = field_path->root; - -end: - return scope; + BT_ASSERT_PRE_NON_NULL(field_path, "Field path"); + return field_path->root; } -int64_t bt_ctf_field_path_get_index_count( - const struct bt_ctf_field_path *field_path) +uint64_t bt_field_path_get_index_count(struct bt_field_path *field_path) { - return field_path ? (int64_t) field_path->indexes->len : (int64_t) -1; + BT_ASSERT_PRE_NON_NULL(field_path, "Field path"); + return (uint64_t) field_path->indexes->len; } -int bt_ctf_field_path_get_index(const struct bt_ctf_field_path *field_path, +uint64_t bt_field_path_get_index_by_index(struct bt_field_path *field_path, uint64_t index) { - int ret = INT_MIN; - - if (!field_path) { - goto end; - } - - if (index >= field_path->indexes->len) { - goto end; - } - - ret = g_array_index(field_path->indexes, int, index); - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(field_path, "Field path"); + BT_ASSERT_PRE_VALID_INDEX(index, field_path->indexes->len); + return bt_field_path_get_index_by_index_inline(field_path, index); }