I’m calling c++ code - to do this I added a C wrapper. One of the arguments (extrinsic) is an Array, which is passed as a Ptr. When the C code gets the pointer, it points to nonexistent memory. Other arguments are passed fine! I’m stumped.
Relevant code is:
type LDPC_DECODER
s::simcase
bofc::Array{Int32,2}
w::Array{Int32,2}
apost::Array{Int32,1}
extrinsic::Array{Int32,1}
dec_codeword::Array{Int32,1}
LDPC_DECODER(s::simcase, bofc::Array{Int32,2}) = new(s, bofc, Array(Int32, s.CUMCHE2, s.DC2), Array(Int32,s.N), Array(Int32,s.NXMIT), Array(Int32,s.N))
end
function compute_scalar(dec::LDPC_DECODER, inp::Array{Int32,1}, xmit::Array{Int32,1}, current_it::Int, genie::Bool=true, max_it::Int=1)
assert(length(inp) == dec.s.NXMIT && length(xmit) == dec.s.KXMIT)
msg = Array(Int32,dec.s.K)
msg_shortened = Array(Int32, dec.s.KXMIT)
ccall((:ldpc_decoder_c, "./ldpc_decoder.so"), Void, (simcase_c, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Int32, Int32, Int32), dec.s, inp, dec.apost, dec.w, dec.bofc, msg, xmit, dec.extrinsic, dec.dec_codeword, Int32(genie), current_it, max_it)
C wrapper is:
extern "C" {
void ldpc_decoder_c(Csimcase c,
int* in_c,
int* apost_c,
int* w_c,
int* b_c,
int* msg_c,
int* xmit_c,
int* extrinsic_c,
int* dec_codeword_c,
int genie,
int it,
int max_it) {
gdb says:
Thread 1 "julia" hit Breakpoint 1, ldpc_decoder_c (c=..., in_c=0x24747c0, apost_c=0x25c2b00, w_c=0x25bdb80, b_c=0x25abf00,
msg_c=0x268e7c0, xmit_c=0x253e5c0, extrinsic_c=0x7ffd00000001, dec_codeword_c=0x25de880, genie=38282368, it=1, max_it=0)
at ldpc_decoder.cc:561
The args up to xmit_c look OK, but extrinsic_c is not a valid pointer. Also, the argument genie is wrong and current_it and max_it seem swapped