Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Libdl changes #28953

Merged
merged 3 commits into from
Sep 1, 2018
Merged
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
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()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly off topic but it seems like this keyword could have been more concisely called error or throw; throw_error feels unpleasantly long. Is it too late to change that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not, but let's get this merged to fix the regression. We can change the keyword name anytime before the release of 1.1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I don't mean it should be changed in this PR, just a more general remark.

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