Hi Tobias,

I want to be able to return different types from ccall(), according to what
happens inside my C/C++ code,
without the need for telling julia what I want to return, its size, etc.
Argument passing gets complicated in such cases,
and I believe returning julia objects directly is neater.

I know this means that I have to write more C code to interface with julia,
but at the same time I don't have to simultaneously maintain C and Julia
code
if something changes in the C code (eg, I add a member in a struct, or I
change the output type)

Another example is with a boosting library I wrote, for which I wrote
matlab wrappers
(here<https://sites.google.com/site/carlosbecker/resources/gradient-boosting-boosted-trees>
).
In this case its train function accepts a structure with options, plus some
arrays. It returns an array of structs
as a 'model' that can be later used. It is nice to have a interface that
needs almost no tuning from the matlab or julia end.

I think many would consider this 'direct julia type return' as an
advantage, particularly people coming from python/matlab.
I also like very much how ccall can handle void pointers, which is
necessary in some situations, but in some other cases
it may be cleaner to work with julia object directly.

I hope I was clear. If I have nice code running I will make it available
for other developers.

Cheers.



------------------------------------------
Carlos


On Sun, Feb 9, 2014 at 7:23 PM, Tobias Knopp <tobias.kn...@googlemail.com>wrote:

> Carlos, the code that you showed can be completely written in Julia. It
> would be helpful if you could give us more insight what you want to
> achieve. Is there a specific API that you want to wrap? You said that the
> API returns a double pointer but the length of the memory is not know (if I
> get that right) How can one use this pointer if the length is unknown?
>
> Am Sonntag, 9. Februar 2014 12:46:24 UTC+1 schrieb Carlos Becker:
>>
>> I think I finally made it work, close to what I wanted.
>>
>> This could be good for future reference for anyone trying to do something
>> similar.
>> The code is at https://gist.github.com/anonymous/8897943.
>>
>> I have two questions about it:
>>   1) calling jl_gc_disable() and jl_gc_enable() is ok in that context?
>> (see link above)
>>   2) I still don't know how to avoid passing a pointer to the module I
>> want to get the type from to the C call.
>>
>> Thanks.
>>
>>
>> El domingo, 9 de febrero de 2014 00:40:33 UTC+1, Carlos Becker escribió:
>>>
>>> Hi Steven,
>>>
>>> I tried that before, I know it is possible, but if the size is unknown
>>> to julia, it must be returned as another variable, which makes
>>> coding more difficult if many of such return arrays are needed.
>>>
>>> That is why I think it would be interesting to see the julia-api side of
>>> it, to see if this can be avoided.
>>> (I prefer to write a bit more of C code but make the ccall clearer in
>>> julia)
>>>
>>> About my previous question, I am still struggling to create a custom
>>> type with julia's C API and fill it in, to pass it back then.
>>> Has anyone done this in such scenario before? I wonder if the necessary
>>> symbols are already exported for 3rd party use.
>>>
>>> Cheers.
>>>
>>

Reply via email to