Hi Jey,

The code is pretty simple. The C code runs correctly when called from C. 
The only other thing I can think of is a gc related issue. Anyway the 
process aborts at the service_func(service_func_c) call. The address of the 
function pointer does change after the fork. So I am assuming that the 
pointer is garbage.

#typedef int (*pq_service_handler)(int *exit_flag, void *user_data);

#int pq_service_create (const char *name, 
#                       const char *desc, 
#                       pq_service_handler init_func, 
#                       pq_service_handler service_func, 
#                       void *user_data);




function init_func{Cint}(a_::Ptr{Cint}, b_::Ptr{Void})

  a = unsafe_load(a_)
    
  println("init_func: $a")

  return convert(Cint, 0)

end

const init_func_c = cfunction(init_func, Cint, (Ptr{Cint}, Ptr{Void}))

function service_func{Cint}(a_::Ptr{Cint}, b_::Ptr{Void})
  
  a = unsafe_load(a_)
 
  while a == 0
    sleep(5)
  end  

  return convert(Cint, 0)

end

const service_func_c = cfunction(service_func, Cint, (Ptr{Cint}, Ptr{Void}))


res = ccall((:pq_service_create, 
"/build/compvia/x86_linux_64/pqvm/libservice.so"), 
      Cint, 
      (Ptr{Uint8}, Ptr{Uint8}, Ptr{Void}, Ptr{Void}, Ptr{Void}), 
      "test_service", "test_service", init_func_c, service_func_c, C_NULL)

Thanks,
-G

Reply via email to