C Global Structs

115 views
Skip to first unread message

Steve Kelly

unread,
Sep 15, 2014, 12:30:48 PM9/15/14
to julia...@googlegroups.com
I'd like to see if Julia is running in code-coverage mode or not.

In the REPL I can do the following:

julia> a = cglobal(:(jl_compileropts))
Ptr{Void} @0x00007fa3e01bbc90


The struct is defined like so:
https://github.com/JuliaLang/julia/blob/aab2c6e67b5aaee7f23bc5a52897f7219473c153/src/julia.h#L1330-L1338

How can I access the code_coverage member?

Thanks,
Steve

Isaiah Norton

unread,
Sep 15, 2014, 12:43:34 PM9/15/14
to julia...@googlegroups.com
julia> immutable JCopt
           build_path::Ptr{Uint8}
           cc::Int8
           ml::Int8
           cb::Int8
           dbc::Int8
           il::Cint
           ce::Int8
       end


julia>  a = cglobal(:(jl_compileropts))
Ptr{Void} @0x000000006d7daf90

julia> unsafe_load(reinterpret(Ptr{JCopt}, a))
JCopt(Ptr{Uint8} @0x0000000000000000,1,0,0,0,0,16)

Jake Bolewski

unread,
Sep 15, 2014, 12:46:59 PM9/15/14
to julia...@googlegroups.com
julia> immutable CompilerOpts
       build_path::Ptr{Cchar}
       code_coverage::Int8
       malloc_log::Int8
       check_bounds::Int8
       dumpbitcode::Int8
       int_literals::Cint
       compile_enabled::Int8
       end

julia> a = cglobal(:jl_compileropts, CompilerOpts)
Ptr{CompilerOpts} @0x000000010f840a88

julia> unsafe_load(a)
CompilerOpts(Ptr{Int8} @0x0000000000000000,0,0,0,0,0,1)

Steve Kelly

unread,
Sep 15, 2014, 9:30:03 PM9/15/14
to julia...@googlegroups.com
This works excellent, thank you both!

Do you think this would be useful to have these user-facing in Base?

Isaiah Norton

unread,
Sep 15, 2014, 9:42:23 PM9/15/14
to julia...@googlegroups.com
I'm not sure; what do you want to do with this? It seems kind of devious to me to change the runtime behavior based on whether coverage is enabled :)

Steve Kelly

unread,
Sep 15, 2014, 9:59:39 PM9/15/14
to julia...@googlegroups.com
I am working on local code coverage analysis for Coverage.jl. I want to warn the user if tests are being run without --code-coverage.

By user facing, I mean the ability to read them as Bools, similar to the isinteractive() method. I am going to implemented this in Coverage.jl for 0.3, but If the struct changes in 0.4 this will double the code. I will file an issue to get a discussion started.

Reply all
Reply to author
Forward
0 new messages