Thanks for the suggestions. Changing the return type results in complaints 
from Julia:

ERROR: error compiling anonymous: in anonymous: ccall: missing return type


or

ERROR: error compiling anonymous: error interpreting ccall return type:type 
cannot be constructed



Using a single variable name on the left-hand side is an improvement and I 
was just experimenting with that. Perhaps unsafe_pointer_to_objref() is 
relevant here, but it gave me a segfault...

On Thursday, April 10, 2014 12:25:40 AM UTC-7, Tobias Knopp wrote:
>
> Hi, this is more a guess but could you try changing the return type in 
> ccall to NTuple{3,Ptr{Any}}? Or maybe just Tuple. Further you could try 
> using on the left hand site only a single variable name, i.e.
>
> tup = = ccall((:my_c_function, "mylib"), Tuple, ())
>
> Am Donnerstag, 10. April 2014 09:15:30 UTC+2 schrieb Dominique Orban:
>>
>> My use case is a C function that creates a sparse matrix in triplet form 
>> (rows, cols, vals). What's the appropriate way to return this to Julia? 
>> I've tried the following, thinking that Julia accepts C pointers as return 
>> values, so why not tuples of C pointers:
>>
>> jl_value_t *my_c_function(void) {
>>
>>   jl_tuple_t *tuple = jl_alloc_tuple(3);
>>   long *rows, *cols;
>>   double *vals;
>>
>>   // allocate and populate rows, cols and vals...
>>
>>   jl_tupleset(tuple, 0, rows);
>>   jl_tupleset(tuple, 1, cols);
>>   jl_tupleset(tuple, 2, vals);
>>
>>   return (jl_value_t*)tuple;
>> }
>>
>> (The intention is then to call ptr_to_array() on each component of the 
>> tuple.) In Julia, I call this C function as follows:
>>
>> (rows, cols, vals) = ccall((:my_c_function, "mylib"), Ptr{Any}, ())
>>
>> But that gives me
>>
>> ERROR: no method start(Ptr{Any})
>>
>> I'm sure there's more than one mistake in that code, but I'm not finding 
>> documentation on the Julia API.
>>
>> Thanks!
>>
>

Reply via email to