Created
June 7, 2014 08:04
-
-
Save staticfloat/93d7050a08ff7bb52373 to your computer and use it in GitHub Desktop.
Code to read the `jl_compileropts` structure in julia at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
immutable jl_compileropts | |
build_path::ASCIIString | |
cpu_target::ASCIIString | |
code_coverage::Int8 | |
check_bounds::Int8 | |
int_literals::Int32 | |
end | |
function load_compileropts() | |
opts_addr = cglobal(:jl_compileropts) | |
build_path = unsafe_load(convert(Ptr{Ptr{Uint8}}, opts_addr)) | |
if build_path != C_NULL | |
build_path = bytestring(build_path) | |
else | |
build_path = "" | |
end | |
opts_addr += sizeof(Ptr{Uint8}) | |
cpu_target = unsafe_load(convert(Ptr{Ptr{Uint8}}, opts_addr)) | |
if cpu_target != C_NULL | |
cpu_target = bytestring(cpu_target) | |
else | |
cpu_target = "" | |
end | |
opts_addr += sizeof(Ptr{Uint8}) | |
code_coverage = unsafe_load(convert(Ptr{Int8}, opts_addr)) | |
opts_addr += sizeof(Int8) | |
check_bounds = unsafe_load(convert(Ptr{Int8}, opts_addr)) | |
opts_addr += sizeof(Int8) | |
int_literals = unsafe_load(convert(Ptr{Int32}, opts_addr)) | |
opts_addr += sizeof(Int32) | |
return jl_compileropts(build_path, cpu_target, code_coverage, check_bounds, int_literals) | |
end | |
println("cpu_target: $(load_compileropts().cpu_target)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unless you declared this struct as
__attribute__((packed))
in C, opts_addr has the wrong offset forint_literals
. In general, it is better to declare the entire struct in Julia and load it in one go: