Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request JuliaLang#19663 from JuliaLang/nl/dlopen
Browse files Browse the repository at this point in the history
Avoid adding extension again when looking for library from versioned name
  • Loading branch information
nalimilan committed Jan 31, 2017
2 parents 552d5e0 + 1006a2e commit 88ef041
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ static int endswith_extension(const char *path)
for (size_t i = 1;i < N_EXTENSIONS;i++) {
const char *ext = extensions[i];
size_t extlen = strlen(ext);
if (len >= extlen && memcmp(ext, path + len - extlen, extlen) == 0) {
if (len < extlen) return 0;
// Skip version extensions if present
size_t j = len-1;
while (j > 0) {
if (path[j] == '.' || (path[j] >= '0' && path[j] <= '9')) j--;
else break;
}
if ((j == len-1 || path[j+1] == '.') && memcmp(ext, path + j - extlen + 1, extlen) == 0) {
return 1;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ end
# opening a library that does not exist throws an ErrorException
@test_throws ErrorException Libdl.dlopen("./foo")

# opening a versioned library that does not exist does not result in adding extension twice
err = @test_throws ErrorException Libdl.dlopen("./foo.$(Libdl.dlext).0")
@test !contains(err.value.msg, "foo.$(Libdl.dlext).0.$(Libdl.dlext)")
err = @test_throws ErrorException Libdl.dlopen("./foo.$(Libdl.dlext).0.22.1")
@test !contains(err.value.msg, "foo.$(Libdl.dlext).0.22.1.$(Libdl.dlext)")

# test dlsym
let dl = C_NULL
try
Expand Down

0 comments on commit 88ef041

Please sign in to comment.