Ccall issue - totally stumped


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:

    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))

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, "./"), 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)

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


Platform and version?


This is rpm -q julia
fedora linux 25

Also, here is the top-level julia code excerpt:

dec = LDPC_DECODER(s, b)
xbits, extrinsic = compute_scalar(dec, y2*2-1, x, 0, true, 20)


OK, I finally found my problem!

The C declaration of the simcase_c struture wasn’t correct, it included a c+±ism

static const int blah = 1;

at the end, which had been copied/pasted from it’s c++ brother.