src.ctf.fs: make ctf_fs_ds_file_create return a unique_ptr
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 9 Dec 2023 14:37:28 +0000 (14:37 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Introduce ctf_fs_ds_file::UP, make ctf_fs_ds_file_create return it.

Change-Id: I0139e9504d65425bf53fb21a5b81a4e48da4fe4e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8268
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12306
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/data-stream-file.cpp
src/plugins/ctf/fs-src/data-stream-file.hpp
src/plugins/ctf/fs-src/fs.cpp

index 9f5c5410e6eccab5a65b39a5f9bd1bc037cad833..c3114a69cd1ef21e13e9ffc919acbf447a503e18 100644 (file)
@@ -329,7 +329,8 @@ ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data,
         /* Create the new file. */
         data->file =
             ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, data->ds_file_group->stream,
-                                  index_entry->path, data->logger);
+                                  index_entry->path, data->logger)
+                .release();
         if (!data->file) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(data->logger, "failed to create ctf_fs_ds_file.");
             status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
@@ -811,17 +812,13 @@ error:
     goto end;
 }
 
-struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
-                                             bt2::Stream::Shared stream, const char *path,
-                                             const bt2c::Logger& parentLogger)
+ctf_fs_ds_file::UP ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
+                                         bt2::Stream::Shared stream, const char *path,
+                                         const bt2c::Logger& parentLogger)
 {
     int ret;
+    auto ds_file = bt2s::make_unique<ctf_fs_ds_file>(parentLogger);
     size_t offset_align;
-    ctf_fs_ds_file *ds_file = new ctf_fs_ds_file {parentLogger};
-
-    if (!ds_file) {
-        goto error;
-    }
 
     ds_file->file = ctf_fs_file_create(parentLogger);
     if (!ds_file->file) {
@@ -843,8 +840,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
 
 error:
     /* Do not touch "borrowed" file. */
-    delete ds_file;
-    ds_file = NULL;
+    ds_file.reset();
 
 end:
     return ds_file;
index 8ffc670d948d9aa9639eefdb6e90598dcac09d07..71c31e23b03b622b3f37f7fb361e8be343a2cbc1 100644 (file)
@@ -35,6 +35,8 @@ struct ctf_fs_ds_file_info
 
 struct ctf_fs_ds_file
 {
+    using UP = std::unique_ptr<ctf_fs_ds_file>;
+
     explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) :
         logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"}
     {
@@ -146,8 +148,8 @@ struct ctf_fs_ds_file_group
     ctf_fs_ds_index::UP index;
 };
 
-struct ctf_fs_ds_file *ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream,
-                                             const char *path, const bt2c::Logger& logger);
+ctf_fs_ds_file::UP ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream,
+                                         const char *path, const bt2c::Logger& logger);
 
 ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
                                                struct ctf_fs_ds_file_info *ds_file_info,
index 4405ca2fa0e31aa2b6d67e8c3eb6f9a30c5ee913..1b76a79fa600e9cdfd23c530111726d59da23e64 100644 (file)
@@ -524,7 +524,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
      * stream file.
      */
     ds_file =
-        ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger);
+        ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger)
+            .release();
     if (!ds_file) {
         goto error;
     }
@@ -1128,7 +1129,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     BT_ASSERT(index_entry->path);
 
     ds_file = ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, index_entry->path,
-                                    ctf_fs_trace->logger);
+                                    ctf_fs_trace->logger)
+                  .release();
     if (!ds_file) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file");
         ret = -1;
This page took 0.02801 seconds and 4 git commands to generate.