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

switch to NLopt_jll #145

Merged
merged 5 commits into from
May 14, 2020
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
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- 1.3
- 1.4
- nightly
env:
matrix:
- FORCE_COMPILE_NLOPT=yes
- FORCE_COMPILE_NLOPT=no
notifications:
email: false
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name = "NLopt"
uuid = "76087f3c-5699-56af-9a33-bf431cd00edd"
version = "0.5.1"
version = "0.6"

[deps]
MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73"
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
CMakeWrapper = "d5fb7624-851a-54ee-a528-d3f3bac0b4a0"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
NLopt_jll = "079eb43e-fd8e-5478-9966-2cf3e3edb778"

[compat]
MathProgBase = "0.5, 0.6, 0.7, 0.8"
BinaryProvider = ">= 0.3.0"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1
- julia_version: 1.3
- julia_version: 1.4
- julia_version: nightly

platform:
Expand Down
3 changes: 0 additions & 3 deletions deps/.gitignore

This file was deleted.

65 changes: 0 additions & 65 deletions deps/build.jl

This file was deleted.

29 changes: 0 additions & 29 deletions deps/compile.jl

This file was deleted.

60 changes: 17 additions & 43 deletions src/NLopt.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
VERSION < v"0.7.0-beta2.199" && __precompile__()

module NLopt

export Opt, NLOPT_VERSION, algorithm, algorithm_name, ForcedStop,
Expand All @@ -10,18 +8,7 @@ export Opt, NLOPT_VERSION, algorithm, algorithm_name, ForcedStop,
import MathProgBase.SolverInterface
import MathProgBase.SolverInterface.optimize!

import Libdl
const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if !isfile(depsjl_path)
error("NLopt not installed properly; run Pkg.build(\"NLopt\"), restart Julia, and try again.")
end
include(depsjl_path)

function __init__()
check_deps()
v = version()
v >= v"2.5" || error("NLopt $v < 2.5 is too old")
end
using NLopt_jll

############################################################################
# Mirrors of NLopt's C enum constants:
Expand Down Expand Up @@ -176,38 +163,25 @@ function Base.copy(o::Opt)
end
end

try
# n.o, for each callback, stores a pointer to an element of o.cb,
# and we need to convert this into a pointer to the corresponding
# element of n.cb. nlopt_munge_data allows us to call a function
# to transform each stored pointer in n.o, and we use the cbi
# dictionary to convert pointers to indices into o.cb, whence
# we obtain the corresponding element of n.cb.
cbi = Dict{Ptr{Cvoid},Int}()
for i in 1:length(cb)
try
cbi[pointer_from_objref(cb[i])] = i
catch
end
end
munge_callback_ptr = @cfunction(munge_callback, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{Cvoid}))
ccall((:nlopt_munge_data,libnlopt), Cvoid, (_Opt, Ptr{Cvoid}, Any),
n, munge_callback_ptr,
p::Ptr{Cvoid} -> p==C_NULL ? C_NULL :
pointer_from_objref(n.cb[cbi[p]]))
catch e0
# nlopt_munge_data not available, punt unless there is
# no callback data
# n.o, for each callback, stores a pointer to an element of o.cb,
# and we need to convert this into a pointer to the corresponding
# element of n.cb. nlopt_munge_data allows us to call a function
# to transform each stored pointer in n.o, and we use the cbi
# dictionary to convert pointers to indices into o.cb, whence
# we obtain the corresponding element of n.cb.
cbi = Dict{Ptr{Cvoid},Int}()
for i in 1:length(cb)
try
cb[1]
catch e
if length(cb) == 1 && isa(e, UndefRefError)
return n
end
cbi[pointer_from_objref(cb[i])] = i
catch
end
error("copy(o::Opt) not supported for NLopt version < 2.4")
end
munge_callback_ptr = @cfunction(munge_callback, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{Cvoid}))
ccall((:nlopt_munge_data,libnlopt), Cvoid, (_Opt, Ptr{Cvoid}, Any),
n, munge_callback_ptr,
p::Ptr{Cvoid} -> p==C_NULL ? C_NULL :
pointer_from_objref(n.cb[cbi[p]]))

return n
end
Expand Down