I have been wrapping an API for nonlinear constraint solving in Julia0.4
(commit 176f9bcdc7e745560107038c6fd7333e85bb4c57).
I am getting different behaviour on what should be semantically identical
programs. That is, if I pass my a Ptr{Void} into a function my program
behaves incorrectly. If I don't use a function, or just use a global
variable for that Ptr{Void}, it works correctly
The following example uses constraint solving to check whether: if is an
integer y is between -100 and 100, is there some y such that y < 0. This
should of course be satisfiable (e.g. y = -1)
ctx = dReal.opensmt_mk_context(Cuint(1))
function test1(ctx)
ccall((:opensmt_mk_int_var, "libdreal"), Ptr{Void},
(Ptr{Void}, Ptr{UInt8}, Float64, Float64), ctx, pointer("y"), -100,
100)
end
function test2()
global ctx
ccall((:opensmt_mk_int_var, "libdreal"), Ptr{Void},
(Ptr{Void}, Ptr{UInt8}, Float64, Float64), ctx, pointer("y"), -100,
100)
end
println("Creating some integer variables")
y = test1(ctx) # CAUSES INCORRECT RESULT
#y = test2() # CAUSES CORRECT RESULT
# leq:= y < 0
zero = dReal.opensmt_mk_num_from_string(ctx, "0" )
leq1 = dReal.opensmt_mk_leq(ctx, y, zero )
# Asserting y < 0
dReal.opensmt_assert(ctx, leq1)
# Checking for satisfiability
res = dReal.opensmt_check(ctx)
@test res == true
Depending on whether I use test1 or test2 I get different results. How is
this possible? Is some strange garbage collection effect going on?
Thanks