Skip to content

Commit

Permalink
Fix Libdl changes (JuliaLang#28953)
Browse files Browse the repository at this point in the history
* Update `NEWS.md` for `Libdl.{dlopen,dlsym}` changes

* Fix `dlopen()` and `dlsym()` backwards incompatibility

* Update tests
  • Loading branch information
staticfloat authored and Keno committed Sep 1, 2018
1 parent 8acad0c commit d9d2b9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ Refer to the [Release Notes for
v0.7](https://github.com/JuliaLang/julia/blob/master/HISTORY.md) for a
detailed list of changes from Julia v0.6.

Standard Library Changes
------------------------

* The `Libdl` module's methods `dlopen()` and `dlsym()` have gained a
`throw_error` keyword argument, replacing the now-deprecated `dlopen_e()`
and `dlsym_e()` methods. When `throw_error` is `false`, failure to locate
a shared library or symbol will return `nothing` rather than `C_NULL`.
([#28888])

Deprecated or removed
---------------------

The old package manager (now called `OldPkg`) has been moved to a
separate repository at https://github.com/JuliaArchive/OldPkg.jl ([#27930])
* The old package manager (now called `OldPkg`) has been moved to a
separate repository at https://github.com/JuliaArchive/OldPkg.jl ([#27930])

<!--- generated by NEWS-update.jl: -->
[#27930]: https://github.com/JuliaLang/julia/issues/27930
[#28888]: https://github.com/JuliaLang/julia/issues/28888
16 changes: 9 additions & 7 deletions stdlib/Libdl/src/Libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ end
"""
dlsym_e(handle, sym)
Look up a symbol from a shared library handle, silently return `NULL` pointer on lookup failure. It is preferred to use dlsym(handle, sym; throw_error=false).
Look up a symbol from a shared library handle, silently return `C_NULL` on lookup failure.
This method is now deprecated in favor of `dlsym(handle, sym; throw_error=false)`.
"""
function dlsym_e(hnd::Ptr, s::Union{Symbol,AbstractString})
return dlsym(hnd, s; throw_error=false)
return something(dlsym(hnd, s; throw_error=false), C_NULL)
end

"""
dlopen(libfile::AbstractString [, flags::Integer])
dlopen(libfile::AbstractString [, flags::Integer]; throw_error:Bool = true)
Load a shared library, returning an opaque handle.
Expand All @@ -96,7 +97,8 @@ instance `RTLD_LAZY|RTLD_DEEPBIND|RTLD_GLOBAL` allows the library's symbols to b
for usage in other shared libraries, addressing situations where there are dependencies
between shared libraries.
If the library cannot be found, this method returns `nothing`.
If the library cannot be found, this method throws an error, unless the keyword argument
`throw_error` is set to `false`, in which case this method returns `nothing`.
"""
function dlopen end

Expand All @@ -114,10 +116,10 @@ end
"""
dlopen_e(libfile::AbstractString [, flags::Integer])
Similar to [`dlopen`](@ref), except returns a `NULL` pointer instead of raising errors.
It is preferred to directly call dlopen(libfile, flags; throw_error=false)`
Similar to [`dlopen`](@ref), except returns `C_NULL` instead of raising errors.
This method is now deprecated in favor of `dlsym(handle, sym; throw_error=false)`.
"""
dlopen_e(args...) = dlopen(args...; throw_error=false)
dlopen_e(args...) = something(dlopen(args...; throw_error=false), C_NULL)

"""
dlclose(handle)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Libdl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ let dl = C_NULL
@test_throws ErrorException Libdl.dlsym(dl, :foo)

fptr = Libdl.dlsym_e(dl, :set_verbose)
@test fptr !== nothing
@test fptr != C_NULL
fptr = Libdl.dlsym_e(dl, :foo)
@test fptr === nothing
@test fptr == C_NULL
finally
Libdl.dlclose(dl)
end
Expand Down

0 comments on commit d9d2b9c

Please sign in to comment.