cfunction is quite finicky about the return type of the function you pass it.
In this case it may not be certain that convert actually returns a value of the
requested type – after all, convert is just a normal function and you can make
it return anything at all. You may have to add a ::Cint annotation to convince
it that this will actually return a Cint. There also seems to be a mismatch in
argument types: you're declaring these functions to take two Ptr{T} args and
then calling cfunction with Ptr{Int} and Ptr{Void}.
> On Aug 4, 2014, at 4:25 AM, Gerry Weaver n <[email protected]> wrote:
>
> Hello All,
>
> Here is some Julia code I've been fiddling with:
>
> # c prototypes
> #
> #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{T}(a_::Ptr{T}, b_::Ptr{T})
>
> a = unsafe_load(a_)
> b = unsafe_load(b_)
>
> return convert(Cint, 0)
>
> end
>
> const init_func_c = cfunction(init_func, Cint, (Ptr{Cint}, Ptr{Void})) # [
> line 9 ]
>
>
>
> function service_func{T}(a_::Ptr{T}, b_::Ptr{T})
>
> a = unsafe_load(a_)
> b = unsafe_load(b_)
>
> while a == 0
> sleep(1)
> end
>
> return convert(Cint, 0)
>
> end
>
> const service_func_c = cfunction(service_func, Cint, (Ptr{Cint}, Ptr{Void}))
>
>
>
> ccall((:pq_service_create, "/build/compvia/x86_linux_64/pqvm/libservice.so"),
> Int32,
> (Ptr{Uint8}, Ptr{Uint8}, init_func_c, service_func_c, Ptr{Void}),
> "test_service", "test_service", init_func, service_func, 0)
>
>
> I keep getting the following error:
>
> ERROR: function is not yet c-callable
> in cfunction at c.jl:23
> in include at ./boot.jl:245
> in include_from_node1 at loading.jl:128
> in process_options at ./client.jl:285
> in _start at ./client.jl:354
> while loading /build/compvia/src/pqvm/service_test.jl, in expression starting
> on line 9
>
> Have I misunderstood something with regard to how this callback business
> works?
>
> Thanks,
> -G
>
>