[julia-users] Re: Returning julia objects with ccall

2014-04-01 Thread Patrick Foley
Hi Steven, I just ran into the same problem. Your response to Carlos was very helpful and worked for my code. Thanks! - Patrick On Saturday, February 8, 2014 6:29:28 PM UTC-5, Steven G. Johnson wrote: On Saturday, February 8, 2014 2:21:36 PM UTC-5, Carlos Becker wrote: I tried out many

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Carlos Becker
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.

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Carlos Becker
Hi Tobias, it may be better to look at an example. For instance, to train my SQB classifier: model = SQBMatrixTrain( featureMatrix, labelVector, maxIters, options ) where featureMatrix and labelVector are matrices (2-dimensional) and vectors (1-dimensional), maxIters is a uint32 and options a

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Carlos Becker
Hi Tobias, model = SQBMatrixTrain( featureMatrix, labelVector, maxIters, options ) That is how the matlab call looks like, so it is very transparent. That is how I want the Julia call look like, and I think that it is better to pass Julia objects directly to ccall() in those cases. It also

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Tobias Knopp
Fair enough, if you wrap the C-API in C++ this can get quite neat. And having myself pushed the documentation of the Julia C-API I definately think that Julia's CAPI is quite good. My intention at that time was, however, embedding Julia in C, in which case the C-API is definately required.

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Carlos Becker
Hi Tobias, thanks for you support! I am still working on it, but when I have something ready for pushing I will let you know. I have two specific questions now: 1) I think that there would be a few issues with the lack of julia's exported symbols (non-DLLEXPORTed symbols in julia.h) The ones

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-10 Thread Tobias Knopp
Am Montag, 10. Februar 2014 18:27:03 UTC+1 schrieb Carlos Becker: 1) I think that there would be a few issues with the lack of julia's exported symbols (non-DLLEXPORTed symbols in julia.h) The ones related to arrays and basic types are exported now, but others are not, and therefore

Re: [julia-users] Re: Returning julia objects with ccall

2014-02-09 Thread Jameson Nash
You need to check jl_gc_is_enabled() before calling jl_gc_disable/jl_gc_enable. However, this is not recommended. Instead you should use JL_GC_PUSHn to root each argument. You also want to avoid using pointer_from_objref since it hides the object reference from the GC. You can use a ccall

[julia-users] Re: Returning julia objects with ccall

2014-02-09 Thread Tobias Knopp
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

[julia-users] Re: Returning julia objects with ccall

2014-02-08 Thread Steven G. Johnson
On Saturday, February 8, 2014 2:21:36 PM UTC-5, Carlos Becker wrote: 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)

[julia-users] Re: Returning julia objects with ccall

2014-02-08 Thread Carlos Becker
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