various: simplify mp_normalize_path usage

If a talloc_ctx was being made solely for a onetime usage of getting a
normalized string, we can now just pass NULL instead and free the string
directly to make things easier.
This commit is contained in:
Dudemanguy committed 2025-02-01 16:12:03 +00:00
1 parent 0755edb327
commit 956cb2c49f
4 files changed
+9 -15

No files matched your search

+2 -5
View File
@@ -53,7 +53,6 @@ struct mpv_deleter {
}
};
using mp_string = std::unique_ptr<char, mpv_deleter>;
using talloc_ctx = std::unique_ptr<void, mpv_deleter>;
struct mp_node : mpv_node {
mp_node() = default;
@@ -208,8 +207,7 @@ static void update_thumbnail(SystemMediaTransportControls &smtc, smtc_ctx &ctx)
try {
if (thumbnail) {
talloc_ctx ta_ctx{ talloc_new(nullptr) };
mp_string normalized_path{ mp_normalize_path(ta_ctx.get(), thumbnail) };
mp_string normalized_path{ mp_normalize_path(nullptr, thumbnail) };
MP_TRACE(&ctx, "Using thumbnail: %s\n", normalized_path.get());
auto hstr = winrt::to_hstring(normalized_path.get());
RandomAccessStreamReference stream_ref{ nullptr };
@@ -225,8 +223,7 @@ static void update_thumbnail(SystemMediaTransportControls &smtc, smtc_ctx &ctx)
updater.Thumbnail(stream_ref);
} else {
if (filepath && !mp_is_url(bstr0(filepath.get()))) {
talloc_ctx ta_ctx{ talloc_new(nullptr) };
mp_string path{ mp_normalize_path(ta_ctx.get(), filepath.get()) };
mp_string path{ mp_normalize_path(nullptr, filepath.get()) };
MP_TRACE(&ctx, "Generating thumbnail for: %s\n", path.get());
auto storage_file = StorageFile::GetFileFromPathAsync(winrt::to_hstring(path.get()));
+3 -4
View File
@@ -5924,15 +5924,14 @@ static void cmd_normalize_path(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
void *ctx = talloc_new(NULL);
char *path = mp_get_user_path(ctx, mpctx->global, cmd->args[0].v.s);
char *path = mp_get_user_path(NULL, mpctx->global, cmd->args[0].v.s);
cmd->result = (mpv_node){
.format = MPV_FORMAT_STRING,
.u.string = talloc_steal(NULL, mp_normalize_path(ctx, path)),
.u.string = mp_normalize_path(NULL, path),
};
talloc_free(ctx);
talloc_free(path);
}
static void cmd_escape_ass(void *p)
+2 -3
View File
@@ -396,8 +396,7 @@ exit:
void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
{
void *ctx = talloc_new(NULL);
char *path = mp_normalize_path(ctx, file ? file : mpctx->filename);
char *path = mp_normalize_path(NULL, file ? file : mpctx->filename);
if (!path)
goto exit;
@@ -424,7 +423,7 @@ void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
}
exit:
talloc_free(ctx);
talloc_free(path);
}
bool mp_load_playback_resume(struct MPContext *mpctx, const char *file)
+2 -3
View File
@@ -14,10 +14,9 @@ static void test_join(char *file, int line, char *a, char *b, char *c)
static void test_normalize(char *file, int line, char *expected, char *path)
{
void *ctx = talloc_new(NULL);
char *normalized = mp_normalize_path(ctx, path);
char *normalized = mp_normalize_path(NULL, path);
assert_string_equal_impl(file, line, normalized, expected);
talloc_free(ctx);
talloc_free(normalized);
}
static void test_dirname(char *file, int line, char *path, char *expected)