Hi Isaiah,

I have actually read your previous e-mails and they were very helpful! I am
able to construct structs in Julia and pass them to C by mirroring the
struct layout as a Julia immutable, but I still couldn't manage to get
results back from C.

I tried writing a simple library to make figuring this out easier (
https://gist.github.com/jfsantos/9136352) but it seems the null pointer I
pass to C is not changed after ccall (i.e., it is still a pointer to
C_NULL) (please ignore the last few lines in test_ccall.jl, they are
supposed to work only after I am able to convert the pointer to Cdvec).
Could you point out where is my mistake?

Thanks!

--
João Felipe Santos


On Fri, Feb 21, 2014 at 10:30 AM, Isaiah Norton <isaiah.nor...@gmail.com>wrote:

> Sorry, I misread - ignore what I said about (1).
>
>
> On Fri, Feb 21, 2014 at 10:25 AM, Isaiah Norton 
> <isaiah.nor...@gmail.com>wrote:
>
>> For (1) see here:
>>
>> http://julia.readthedocs.org/en/latest/manual/calling-c-and-fortran-code/#passing-pointers-for-modifying-inputs
>>
>> For (2) you do basically the same thing (varout = Ptr[C_NULL]). You need
>> to have the struct layout mirrored as an immutable in Julia... search the
>> list history for my name, for a very recent email with a detailed
>> explanation.
>>
>>
>> On Fri, Feb 21, 2014 at 10:13 AM, John Myles White <
>> johnmyleswh...@gmail.com> wrote:
>>
>>> Re (1), check out the section on the & operator in the docs:
>>> http://julia.readthedocs.org/en/latest/manual/calling-c-and-fortran-code/
>>>
>>> It took me a while to figure out to use that operator, but I think it's
>>> what you'll need.
>>>
>>> Not sure about (2).
>>>
>>>  -- John
>>>
>>> On Feb 21, 2014, at 7:06 AM, João Felipe Santos <joao....@gmail.com>
>>> wrote:
>>>
>>> > Hi,
>>> >
>>> > I am using ccall to write a wrapper for a C library in Julia and have
>>> a couple of questions:
>>> >
>>> > 1. One of the functions I am wrapping gets several pointers to long
>>> and double as arguments. Let's say I have a function signature as:
>>> >
>>> > int my_function(long* a, double* b).
>>> >
>>> > From the manual, I understood that I have to wrap it as:
>>> >
>>> > ccall((:my_function, "mylib"), Cint, (Ptr{Clong}, Ptr{Cdouble}, a, b)
>>> >
>>> > with a and b being Vector{Int64} and Vector{Float64} in Julia.
>>> However, when I try to use this, I am getting back this error message: "no
>>> method convert(Type{Int64}, Array{Int64,1})", which is weird, since I don't
>>> try to do this conversion anywhere. What am I doing wrong?
>>> >
>>> > 2. Some functions in my library return pointers to structs and I would
>>> like to be able to read these structs from Julia. I implemented these
>>> strucs as bittypes but I'm not sure on how can I pass an "empty pointer to
>>> struct" and get back a pointer to a struct allocated in C after my ccall.
>>> Is it possible?
>>> >
>>> > Best regards
>>> >
>>> > --
>>> > João Felipe Santos
>>>
>>>
>>
>

Reply via email to