To formulate my question a bit more specifically (about the last part of my 
email)

Suppose I want to call jl_new_struct() to instantiate a 'type', I need to 
provide the type, so I guess
I have to pass the right jl_datatype_t *, which might be found 
with jl_get_global().
Now, jl_get_global() needs the module pointer, which is not available as a 
linking symbol sin this would come from an
external module (let's say called MyModule). Is there a function to lookup 
the pointer of a module given its string name?

Thanks.


El sábado, 8 de febrero de 2014 21:10:11 UTC+1, Carlos Becker escribió:
>
> Hi Jeff, thanks for the quick reply.
>
> If "Any" is used as the return type of the ccall, the result will be 
>> treated as a julia reference and you can skip 
>> unsafe_pointer_to_objref. 
>>
>
> If returning "Any", would the GC take care of it?
>  
>
>>
>> A variant of this is to allocate the array in julia, and pass it to 
>> the C function to be filled in (ccall will effectively call 
>> jl_array_ptr for you to pass the array to C). 
>>
>
> Right, but if the final size is not known before ccall(), then it may not 
> be as easy as creating it from C.
>
> Now, I am also looking for something a bit more involved.
> For example, I need to return what in C is an array of structs 
> (std::vector<struct type>).
> Do you see some problems when creating and filling a specific Julia type, 
> to add several of them
> into a Julia array? Would you point me to some of the functions of the API 
> that could be used for this?
>
> Thanks,
> Carlos
>
>
>  
>
>>
>> On Sat, Feb 8, 2014 at 2:21 PM, Carlos Becker <carlos...@gmail.com> 
>> wrote: 
>> > Hello everyone, 
>> > 
>> > I just got started with Julia, and I wanted to try to wrap a C/C++ 
>> library 
>> > to Julia to check whether it would work out for my purposes. 
>> > 
>> > I tried out many ways of passing arrays and other objects from C back 
>> to 
>> > Julia. 
>> > So far it seems that it takes a lot of extra code if I want to return, 
>> for 
>> > example, a simple double-array or an array of types (eg structs). 
>> > 
>> > Then I thought that I could call the Julia API from the ccalled binary, 
>> to 
>> > allocate an array and return it to julia, 
>> > then use unsafe_pointer_to_objref() and get a neat Julia object 
>> directly. 
>> > 
>> > You can see a very simple example here 
>> > https://gist.github.com/anonymous/8888647 
>> > 
>> > This would simplify _significantly_ a lot of code from the C side, at 
>> least 
>> > with what I am working right now. 
>> > 
>> > Now, my question is: is it safe to call functions such as 
>> > jl_alloc_array_1d() from the C binary? 
>> > would this be a problem in some situations? 
>> > 
>> > I understand that it may mess memory up if those functions are called 
>> > outside the main thread, but I would certainly not do that. 
>> > 
>> > Thanks in advance, 
>> > Carlos 
>>
>

Reply via email to