Change that field to be a unique_ptr. Adjust some functions in fs.cpp
around that.
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ie2cdfe0b81f1d817093de74faf6c12ef2e6169a1
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8252
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12290
- ctf_fs_ds_index_destroy(ds_file_group->index);
-
bt_stream_put_ref(ds_file_group->stream);
delete ds_file_group;
}
bt_stream_put_ref(ds_file_group->stream);
delete ds_file_group;
}
ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_stream_class *sc,
uint64_t stream_instance_id,
ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_stream_class *sc,
uint64_t stream_instance_id,
- struct ctf_fs_ds_index *index)
+ ctf_fs_ds_index::UP index)
{
ctf_fs_ds_file_group::UP ds_file_group {new ctf_fs_ds_file_group};
{
ctf_fs_ds_file_group::UP ds_file_group {new ctf_fs_ds_file_group};
- ds_file_group->index = index;
+ ds_file_group->index = std::move(index);
ds_file_group->stream_id = stream_instance_id;
BT_ASSERT(sc);
ds_file_group->stream_id = stream_instance_id;
BT_ASSERT(sc);
/* Weak, belongs to component */
struct ctf_fs_trace *ctf_fs_trace = nullptr;
/* Weak, belongs to component */
struct ctf_fs_trace *ctf_fs_trace = nullptr;
- /*
- * Owned by this.
- */
- struct ctf_fs_ds_index *index = nullptr;
+ ctf_fs_ds_index::UP index;
};
struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
};
struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_stream_class *sc,
uint64_t stream_instance_id,
ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_stream_class *sc,
uint64_t stream_instance_id,
- struct ctf_fs_ds_index *index);
+ ctf_fs_ds_index::UP index);
/*
* Medium operations to iterate on a single ctf_fs_ds_file.
/*
* Medium operations to iterate on a single ctf_fs_ds_file.
-static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, struct ctf_fs_ds_index *src)
+static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index::UP src)
int ret;
struct ctf_fs_ds_file *ds_file = NULL;
ctf_fs_ds_file_info::UP ds_file_info;
int ret;
struct ctf_fs_ds_file *ds_file = NULL;
ctf_fs_ds_file_info::UP ds_file_info;
- struct ctf_fs_ds_index *index = NULL;
+ ctf_fs_ds_index::UP index;
struct ctf_msg_iter *msg_iter = NULL;
struct ctf_stream_class *sc = NULL;
struct ctf_msg_iter_packet_properties props;
struct ctf_msg_iter *msg_iter = NULL;
struct ctf_stream_class *sc = NULL;
struct ctf_msg_iter_packet_properties props;
- index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter).release();
+ index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter);
if (!index) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'",
ds_file->file->path->str);
if (!index) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'",
ds_file->file->path->str);
* there's no timestamp to order the file within its
* group.
*/
* there's no timestamp to order the file within its
* group.
*/
- new_ds_file_group = ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), index);
-
- /* Ownership of index is transferred. */
- index = NULL;
+ new_ds_file_group =
+ ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), std::move(index));
if (!new_ds_file_group) {
goto error;
if (!new_ds_file_group) {
goto error;
if (!ds_file_group) {
new_ds_file_group =
if (!ds_file_group) {
new_ds_file_group =
- ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, index);
- /* Ownership of index is transferred. */
- index = NULL;
+ ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, std::move(index));
if (!new_ds_file_group) {
goto error;
}
if (!new_ds_file_group) {
goto error;
}
ds_file_group = new_ds_file_group.get();
ctf_fs_trace->ds_file_groups.emplace_back(std::move(new_ds_file_group));
} else {
ds_file_group = new_ds_file_group.get();
ctf_fs_trace->ds_file_groups.emplace_back(std::move(new_ds_file_group));
} else {
- merge_ctf_fs_ds_indexes(ds_file_group->index, index);
+ merge_ctf_fs_ds_indexes(ds_file_group->index.get(), std::move(index));
}
ds_file_group_insert_ds_file_info_sorted(ds_file_group, std::move(ds_file_info));
}
ds_file_group_insert_ds_file_info_sorted(ds_file_group, std::move(ds_file_info));
ctf_msg_iter_destroy(msg_iter);
}
ctf_msg_iter_destroy(msg_iter);
}
- ctf_fs_ds_index_destroy(index);
}
/* Merge both indexes. */
}
/* Merge both indexes. */
- merge_ctf_fs_ds_indexes(dest->index, src->index);
+ merge_ctf_fs_ds_indexes(dest->index.get(), std::move(src->index));
}
/* Merge src_trace's data stream file groups into dest_trace's. */
}
/* Merge src_trace's data stream file groups into dest_trace's. */
src_group->sc->id);
BT_ASSERT(sc);
src_group->sc->id);
BT_ASSERT(sc);
- auto index = ctf_fs_ds_index_create(dest_trace->logger).release();
+ auto index = ctf_fs_ds_index_create(dest_trace->logger);
if (!index) {
ret = -1;
goto end;
}
auto new_dest_group =
if (!index) {
ret = -1;
goto end;
}
auto new_dest_group =
- ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, index);
+ ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, std::move(index));
- /* Ownership of index is transferred. */
- index = NULL;
if (!new_dest_group) {
ret = -1;
goto end;
if (!new_dest_group) {
ret = -1;
goto end;
guint entry_i;
struct ctf_clock_class *default_cc;
struct ctf_fs_ds_index_entry *last_entry;
guint entry_i;
struct ctf_clock_class *default_cc;
struct ctf_fs_ds_index_entry *last_entry;
- struct ctf_fs_ds_index *index;
BT_ASSERT(ds_file_group);
BT_ASSERT(ds_file_group);
- index = ds_file_group->index;
+ const auto index = ds_file_group->index.get();
BT_ASSERT(index);
BT_ASSERT(index->entries);
BT_ASSERT(index);
BT_ASSERT(index->entries);
for (const auto& ds_file_group : trace->ds_file_groups) {
guint entry_i;
struct ctf_clock_class *default_cc;
for (const auto& ds_file_group : trace->ds_file_groups) {
guint entry_i;
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index *index = ds_file_group->index;
+ const auto index = ds_file_group->index.get();
BT_ASSERT(index);
BT_ASSERT(index->entries);
BT_ASSERT(index);
BT_ASSERT(index->entries);
for (const auto& ds_file_group : trace->ds_file_groups) {
guint entry_idx;
struct ctf_clock_class *default_cc;
for (const auto& ds_file_group : trace->ds_file_groups) {
guint entry_idx;
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index *index;
BT_ASSERT(ds_file_group);
BT_ASSERT(ds_file_group);
- index = ds_file_group->index;
+ const auto index = ds_file_group->index.get();
BT_ASSERT(ds_file_group->sc->default_clock_class);
default_cc = ds_file_group->sc->default_clock_class;
BT_ASSERT(ds_file_group->sc->default_clock_class);
default_cc = ds_file_group->sc->default_clock_class;