Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to load the values returned by callback functions (defined in a Julia wrapper) to C functions

$
0
0

I am trying to wrap ngspice_jll.jl And have generated wrapper functions to sharedspice.h file.

A typical function has pointers to callback functions as arguments. Initialization looks like:

function ngSpice_Init(sendchar, statfcn) #and 5 more similar callbacks
    ccall((:ngSpice_Init, libngspice), Cint, (Ptr{Cvoid}, Ptr{Cvoid}), sendchar, statfcn)
end

where sendchar = @cfunction($SendChar, Cint, (Ptr{Char}, Cint, Ptr{Cvoid})).ptr

(And SendChar is supposed to print the string pointed by Ptr{Char})

After executing ngSpice_Init(...), and loading circuit, I want to access the sendchar and its arguement. (This and other callbacks are expected to contain info about the simulation being run) When I unsafe_load it, as expected, points to nothing. unsafe_pointer_to_objref crashes the repl. What should I do to access the string (and other values) returned by the callback function.

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images