Skip to content

Commit

Permalink
fix #25137, return value of dlclose on windows (#25175)
Browse files Browse the repository at this point in the history
- Invert boolean value returned by Windows FreeLibrary so it matches
  that of POSIX dlclose
- Add test of jl_dlclose/Libdl.dlclose to test/libdl.jl
  • Loading branch information
jdjohnston authored and JeffBezanson committed Dec 20, 2017
1 parent 564ecb0 commit 617afff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ JL_DLLEXPORT int jl_dlclose(void *handle)
{
#ifdef _OS_WINDOWS_
if (!handle) return -1;
return FreeLibrary((HMODULE) handle);
return !FreeLibrary((HMODULE) handle);
#else
dlerror(); /* Reset error status. */
if (!handle) return -1;
Expand Down
14 changes: 14 additions & 0 deletions test/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ let dl = C_NULL
end
end

# test dlclose
# If dl is NULL, jl_dlclose should return -1 and dlclose should return false
# dlclose should return true on success and false on failure
let dl = C_NULL
@test -1 == ccall(:jl_dlclose, Cint, (Ptr{Void},), dl)
@test !Libdl.dlclose(dl)

dl = Libdl.dlopen_e("libccalltest")
@test dl != C_NULL

@test Libdl.dlclose(dl)
@test_skip !Libdl.dlclose(dl) # Syscall doesn't fail on Win32
end

if Sys.KERNEL in (:Linux, :FreeBSD)
ccall(:jl_read_sonames, Void, ())
end
Expand Down

0 comments on commit 617afff

Please sign in to comment.