src.ctf.fs: make ctf_fs_ds_index_entry_create return a unique_ptr
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Dec 2023 21:13:53 +0000 (21:13 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Introduce ctf_fs_ds_index_entry::UP and make
ctf_fs_ds_index_entry_create return that.  Modify a few functions in
data-stream-file.cpp that deal with this.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I39598d860327cff5af32804f75b68b58e4ee0821
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8253
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12291

src/plugins/ctf/fs-src/data-stream-file.cpp
src/plugins/ctf/fs-src/data-stream-file.hpp

index 11dee041004afdc967333ebe34fbcb54c459657e..63140e45ce8339836baf219dc84e8a72d839550d 100644 (file)
@@ -443,10 +443,10 @@ static void ctf_fs_ds_index_entry_destroy(ctf_fs_ds_index_entry *entry)
     delete entry;
 }
 
-static struct ctf_fs_ds_index_entry *ctf_fs_ds_index_entry_create(const bt2c::DataLen offset,
-                                                                  const bt2c::DataLen packetSize)
+static ctf_fs_ds_index_entry::UP ctf_fs_ds_index_entry_create(const bt2c::DataLen offset,
+                                                              const bt2c::DataLen packetSize)
 {
-    ctf_fs_ds_index_entry *entry = new ctf_fs_ds_index_entry {offset, packetSize};
+    ctf_fs_ds_index_entry::UP entry = bt2s::make_unique<ctf_fs_ds_index_entry>(offset, packetSize);
 
     entry->packet_seq_num = UINT64_MAX;
 
@@ -474,7 +474,8 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     const char *mmap_begin = NULL, *file_pos = NULL;
     const struct ctf_packet_index_file_hdr *header = NULL;
     ctf_fs_ds_index::UP index;
-    struct ctf_fs_ds_index_entry *index_entry = NULL, *prev_index_entry = NULL;
+    ctf_fs_ds_index_entry::UP index_entry;
+    ctf_fs_ds_index_entry *prev_index_entry = NULL;
     auto totalPacketsSize = bt2c::DataLen::fromBytes(0);
     size_t file_index_entry_size;
     size_t file_entry_count;
@@ -652,11 +653,10 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
         totalPacketsSize += packetSize;
         file_pos += file_index_entry_size;
 
-        prev_index_entry = index_entry;
+        prev_index_entry = index_entry.get();
 
         /* Give ownership of `index_entry` to `index->entries`. */
-        g_ptr_array_add(index->entries, index_entry);
-        index_entry = NULL;
+        g_ptr_array_add(index->entries, index_entry.release());
     }
 
     /* Validate that the index addresses the complete stream. */
@@ -680,7 +680,6 @@ end:
     return index;
 error:
     index.reset();
-    ctf_fs_ds_index_entry_destroy(index_entry);
     goto end;
 }
 
@@ -786,8 +785,7 @@ static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *d
             goto error;
         }
 
-        const auto index_entry =
-            ctf_fs_ds_index_entry_create(currentPacketOffset, currentPacketSize);
+        auto index_entry = ctf_fs_ds_index_entry_create(currentPacketOffset, currentPacketSize);
         if (!index_entry) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ds_file->logger,
                                          "Failed to create a ctf_fs_ds_index_entry.");
@@ -797,13 +795,12 @@ static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *d
         /* Set path to stream file. */
         index_entry->path = file_info->path.c_str();
 
-        ret = init_index_entry(index_entry, ds_file, &props);
+        ret = init_index_entry(index_entry.get(), ds_file, &props);
         if (ret) {
-            ctf_fs_ds_index_entry_destroy(index_entry);
             goto error;
         }
 
-        g_ptr_array_add(index->entries, index_entry);
+        g_ptr_array_add(index->entries, index_entry.release());
 
         currentPacketOffset += currentPacketSize;
         BT_CPPLOGD_SPEC(ds_file->logger,
index 9e8696e4b7cd1f167d605e11f33b4d4b26073e9a..df0c0c78261cbc57aafe9d4b4994ad9d346b5c6a 100644 (file)
@@ -72,6 +72,8 @@ struct ctf_fs_ds_file
 
 struct ctf_fs_ds_index_entry
 {
+    using UP = std::unique_ptr<ctf_fs_ds_index_entry>;
+
     explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
                                    const bt2c::DataLen packetSizeParam) noexcept :
         offset(offsetParam),
This page took 0.025836 seconds and 4 git commands to generate.