Skip to content

Commit

Permalink
switch to NLopt_jll build
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed May 13, 2020
1 parent cc23e91 commit 9c263e5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 145 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73"
NLopt_jll = "079eb43e-fd8e-5478-9966-2cf3e3edb778"

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

Expand Down
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

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

0 comments on commit 9c263e5

Please sign in to comment.