I will try to answer your questions one by one:
Is there any other way to pass a two-dimensional matrix to a C function that expects an argument of type int ** arg?
Yes. You must add the method to the julia cconvert function so that it performs the conversion from Matrix{Cint} to Ptr{Ptr{Cint}} . So you define:
Base.cconvert(::Type{Ptr{Ptr{Cint}}},xx2::Matrix{Cint})=Ref{Ptr{Cint}}([Ref(xx2,i) for i=1:size(xx2,1):length(xx2)])
(see the following question for an explanation), and after that you can directly pass your matrix to ccall:
xx2=zeros(Cint,5,6) ccall((:fill_matrix, "mylib.so"),Void, (Ptr{Ptr{Cint}}, Cint, Cint), xx2, 6,5)
However, I would suggest it is very conservative to use the cconvert methods that you overwrite, because other julia code might expect the original behavior.
If not, how can you convert an already existing two-dimensional Julia array into an array of arrays of structure C?
The following should work: you create an array of pointers to each column of your matrix, so in julia-0.4:
xx2=zeros(Cint,5,6) refAr=[Ref(xx2,i) for i=1:size(xx2,1):length(xx2)] ccall((:fill_matrix, "mylib.so"),Void, (Ptr{Ptr{Cint}}, Cint, Cint), refAr, 6,5)
Now the matrix xx2 filled with function C. Note that in julia v0.3 you need to replace Ref(xx2,i) with pointer(xx2,i)
and vice versa?
I do not think that this is possible at all. To build a julia 2D array, the data must be in a contiguous block of memory. If you are REALLY sure that this is so, you can do:
p=pointer(refAr)
Returns the original matrix. Here, the last argument pointer_to_array determines whether Julia will own the array and the data should be freed by Julia gc.