Skip to content

Commit bf44959

Browse files
committed
Update
1 parent b489de3 commit bf44959

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/gen/libhighs.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,49 @@
88

99
HIGHS_LOG_FILE() = nothing
1010

11-
_trace_format_value(x) = unsafe_convert(Ptr{Cvoid}, x)
11+
function _trace_format_value(x)
12+
if x === C_NULL
13+
return "C_NULL"
14+
end
15+
return Base.unsafe_convert(Ptr{Cvoid}, x)
16+
end
17+
_trace_format_value(::Nothing) = "nothing"
1218
_trace_format_value(x::Number) = x
1319
_trace_format_value(x::Vector) = string(x)
1420
_trace_format_value(x::AbstractString) = repr(x)
21+
_trace_format_value(x::Base.RefValue) = repr(x)
1522

1623
macro trace(def)
1724
@assert Meta.isexpr(def, :function, 2)
1825
fn_signature, fn_body = def.args
1926
fn_name, fn_args = fn_signature.args[1], fn_signature.args[2:end]
2027
io = gensym()
2128
print_args = Expr(:block)
22-
print_output_args = Expr(:block)
2329
for arg in fn_args
2430
input_arg = "$arg = "
31+
if arg == :highs
32+
input_arg = "# " * input_arg
33+
end
2534
push!(print_args.args, :(println($io, $input_arg, $_trace_format_value($arg))))
26-
push!(print_output_args.args, :(println($io, "# ", $input_arg, $_trace_format_value($arg))))
2735
end
2836
call = string("$fn_name(", join(fn_args, ", "), ")")
29-
print_call = :(println($io, "ret = ", $call))
37+
if fn_name == :Highs_create
38+
call = "highs = " * call
39+
end
3040
new_body = quote
3141
log_file = $HIGHS_LOG_FILE()
3242
if log_file === nothing
3343
$fn_body
3444
else
3545
open(log_file, "a") do $io
36-
println($io, "# === New call ===")
3746
$print_args
38-
$print_call
39-
result = (() -> $fn_body)()
40-
println($io, "# ret = ", $_trace_format_value(result))
41-
$print_output_args
42-
println($io)
43-
result
47+
println($io, "ret = ", $call)
48+
end
49+
result = (() -> $fn_body)()
50+
open(log_file, "a") do $io
51+
println($io, "# ret = ", $_trace_format_value(result), "\n")
4452
end
53+
result
4554
end
4655
end
4756
return Expr(:function, fn_signature, new_body) |> esc

0 commit comments

Comments
 (0)