I'm not sure if this is directly related, but the result of the syntactic
expression `pointer("y")` is undefined. using that result will cause
undefined behavior. undefined behavior is not bounded to the expression in
question and instead may alter anything it wants about your computer. do
not use the `pointer` function on anything other than the name a variable
(e.g. `pointer(y)`), or better yet, don't use it ever. on Julia 0.4,
`pointer` is simply the unsafe version of `Ref`. and on any version, it is
generally redundant with the automatic conversion implicit in ccall.also, fwiw, that's not how that c function appears to be defined ( http://opensmt.googlecode.com/svn-history/r30/trunk/src/api/opensmt_c.h), since it only expects 2 arguments and you are trying to pass 4: typedef void * opensmt_expr; typedef void * opensmt_context; opensmt_expr opensmt_mk_int_var(opensmt_context, char *); C actually defines that this does not cause undefined behavior, but it is also just not very useful here. On Wed, Apr 15, 2015 at 11:33 PM Zenna Tavares <[email protected]> wrote: > 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 >
