Skip to content

Commit

Permalink
Add getters and setters for log/debug (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored May 15, 2021
1 parent fbe1127 commit 7530963
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 57 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ using MathOptInterface, CDDLib
model = CDDLib.Optimizer{Rational{BigInt}}()
```

## Debugging

CDD uses two global boolean to enable debugging outputs: `debug` and `log`.
You can query the value of `debug` (resp. `log`) with `get_debug` (resp. `get_log`)
and set its value with `set_debug` (resp. `set_log`).

[build-img]: https://github.com/JuliaPolyhedra/CDDLib.jl/workflows/CI/badge.svg?branch=master
[build-url]: https://github.com/JuliaPolyhedra/CDDLib.jl/actions?query=workflow%3ACI
[codecov-img]: http://codecov.io/github/JuliaPolyhedra/CDDLib.jl/coverage.svg?branch=master
Expand Down
59 changes: 2 additions & 57 deletions src/CDDLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,7 @@ end

using Polyhedra

macro dd_ccall_pointer_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ptr = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"dd_$f", ptr, err[])
ptr
end
end

macro dd_ccall_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ret = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"dd_$f", err[])
ret
end
end

macro dd_ccall(f, args...)
quote
ret = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...))
ret
end
end

macro ddf_ccall_pointer_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ptr = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"ddf_$f", ptr, err[])
ptr
end
end

macro ddf_ccall_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ret = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"ddf_$f", err[])
ret
end
end

macro ddf_ccall(f, args...)
quote
ret = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...))
ret
end
end


macro cdd_ccall(f, args...)
quote
ret = ccall(($"$f", libcddgmp), $(map(esc,args)...))
ret
end
end
include("ccall.jl")

@static if VERSION < v"1.3"
function __init__()
Expand All @@ -85,6 +29,7 @@ end

import Base.convert, Base.push!, Base.eltype, Base.copy

include("debug_log.jl")
include("cddtypes.jl")
include("error.jl")
include("mytype.jl")
Expand Down
57 changes: 57 additions & 0 deletions src/ccall.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
macro dd_ccall_pointer_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ptr = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"dd_$f", ptr, err[])
ptr
end
end

macro dd_ccall_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ret = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"dd_$f", err[])
ret
end
end

macro dd_ccall(f, args...)
quote
ret = ccall(($"dd_$f", libcddgmp), $(map(esc,args)...))
ret
end
end

macro ddf_ccall_pointer_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ptr = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"ddf_$f", ptr, err[])
ptr
end
end

macro ddf_ccall_error(f, args...)
quote
err = Ref{Cdd_ErrorType}(0)
ret = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...), err)
myerror($"ddf_$f", err[])
ret
end
end

macro ddf_ccall(f, args...)
quote
ret = ccall(($"ddf_$f", libcddgmp), $(map(esc,args)...))
ret
end
end


macro cdd_ccall(f, args...)
quote
ret = ccall(($"$f", libcddgmp), $(map(esc,args)...))
ret
end
end
15 changes: 15 additions & 0 deletions src/debug_log.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export get_debug, set_debug, get_log, set_log
_debug() = cglobal((:ddf_debug, CDDLib.libcddgmp), CDDLib.Cdd_boolean)
function get_debug()
unsafe_load(_debug())
end
function set_debug(value)
unsafe_store!(_debug(), value)
end
_log() = cglobal((:ddf_log, CDDLib.libcddgmp), CDDLib.Cdd_boolean)
function get_log()
unsafe_load(_log())
end
function set_log(value)
unsafe_store!(_log(), value)
end
11 changes: 11 additions & 0 deletions test/debug_log.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function debug_log_test(getter, setter)
@test getter() == 0
setter(true)
@test getter() == 1
setter(false)
@test getter() == 0
end
@testset "debug and log" begin
debug_log_test(get_debug, set_debug)
debug_log_test(get_log, set_log)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Test
using Polyhedra
using CDDLib

include("debug_log.jl")
include("polyhedral_function.jl")

using JuMP
Expand Down

2 comments on commit 7530963

@blegat
Copy link
Member Author

@blegat blegat commented on 7530963 May 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/36811

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 7530963dbb7bf137f1ea4cab81ef81180a2658a1
git push origin v0.7.0

Please sign in to comment.