Skip to content

Commit

Permalink
Remove to_abs_path
Browse files Browse the repository at this point in the history
This function is not necessary.

I don't know how it could leak memory, but it was reported
that it does in #1355.
  • Loading branch information
rui314 committed Oct 8, 2024
1 parent 91e2daf commit c16d6e8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ std::filesystem::path filepath(const auto &path) {

std::string get_realpath(std::string_view path);
std::string path_clean(std::string_view path);
std::filesystem::path to_abs_path(std::filesystem::path path);

//
// demangle.cc
Expand Down
6 changes: 0 additions & 6 deletions lib/filepath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ std::string path_clean(std::string_view path) {
return filepath(path).lexically_normal().string();
}

std::filesystem::path to_abs_path(std::filesystem::path path) {
if (path.is_absolute())
return path.lexically_normal();
return (std::filesystem::current_path() / path).lexically_normal();
}

// Returns the path of the mold executable itself
std::string get_self_path() {
#if __APPLE__ || _WIN32
Expand Down
3 changes: 1 addition & 2 deletions src/linker-script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ Script<E>::read_output_format(std::span<std::string_view> tok) {

template <typename E>
static bool is_in_sysroot(Context<E> &ctx, std::string path) {
std::filesystem::path sysroot = to_abs_path(ctx.arg.sysroot);
std::string rel = to_abs_path(path).lexically_relative(sysroot).string();
std::string rel = std::filesystem::relative(path, ctx.arg.sysroot).string();
return rel != "." && !rel.starts_with("../");
}

Expand Down
3 changes: 2 additions & 1 deletion src/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,8 @@ void write_repro_file(Context<E> &ctx) {
// We reopen a file because we may have modified the contents of mf
// in memory, which is mapped with PROT_WRITE and MAP_PRIVATE.
MappedFile *mf2 = must_open_file(ctx, mf->name);
tar->append(to_abs_path(mf->name).string(), mf2->get_contents());
tar->append(std::filesystem::absolute(mf->name).string(),
mf2->get_contents());
mf2->unmap();
}
}
Expand Down

0 comments on commit c16d6e8

Please sign in to comment.