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>
/* 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;
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) {
error:
/* Do not touch "borrowed" file. */
- delete ds_file;
- ds_file = NULL;
+ ds_file.reset();
end:
return ds_file;
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"}
{
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,
* 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;
}
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;