Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mlx/backend/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ std::filesystem::path current_binary_dir() {
if (!dladdr(reinterpret_cast<void*>(&current_binary_dir), &info)) {
throw std::runtime_error("Unable to get current binary dir.");
}
return std::filesystem::path(info.dli_fname).parent_path();
// dli_fname is the path the binary was loaded by, which may be relative,
// contain ".." or go through a symlink. Callers append relative paths to
// the result and check them for existence, so it has to be resolved.
return std::filesystem::weakly_canonical(info.dli_fname).parent_path();
}();
return binary_dir;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/utils_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

#include "doctest/doctest.h"

#include "mlx/backend/common/utils.h"
#include "mlx/mlx.h"

using namespace mlx::core;

TEST_CASE("test current binary dir is resolved") {
auto dir = current_binary_dir();
CHECK(dir.is_absolute());
CHECK_EQ(dir, std::filesystem::weakly_canonical(dir));
}

TEST_CASE("test type promotion") {
for (auto t : {bool_, uint32, int32, int64, float32}) {
auto a = array(0, t);
Expand Down