it doesn’t look from your code snippet that you have overridden the
variable txt, so it doesn’t appear that you’ve lost the gc-root. but since
pr isn’t a Ptr{Ptr{UInt8}}, but a Ptr{Any}, doing a pointer cast there is
generally a bad idea there anyways.
however, you shouldn’t need to call pointer to pass an array of strings to
a ccall. just pass an array of strings as argument type Ptr{Ptr{UInt8}} and
ccall will do the necessary conversion.
(in the soon-to-be-merged PR https://github.com/JuliaLang/julia/pull/9986,
you will be able to do a similar — but still gc-safe — transform outside of
ccall by calling Ref{Ptr{UInt8}}(["aa", "bb"]). and thus still avoiding the
need to call pointer)
On Tue, Mar 3, 2015 at 6:51 PM J Luis [email protected]
<http://mailto:[email protected]> wrote:
Ok, I need to send a table of texts via Ptr{Ptr{Uint8}} to a C struct and
> on the repl things seam to work well
>
> julia> txt={"aa","bb"};
>
> julia> r=cell(2);
>
> julia> r[1]=pointer(txt[1]);
>
> julia> r[2]=pointer(txt[2]);
>
> julia> pr=pointer(r)
> Ptr{Any} @0x0000000082edeeb0
>
> julia> ppr = convert(Ptr{Ptr{Uint8}}, pr)
> Ptr{Ptr{UInt8}} @0x0000000082edeeb0
>
> julia> bytestring(pointer_to_array(pr,1)[1])
> "aa"
>
> so the first text string was correctly recovers.
>
> But now if do similar but wrap it in a immutable (it has to an immutable)
> that implicitly calls the same convert method, the text is lost.
>
> immutable X
> rec::Ptr{Ptr{Uint8}}
> end
>
> julia> tx = X(pr)
> X(Ptr{Ptr{UInt8}} @0x0000000082edeeb0)
>
> julia> bytestring(pointer_to_array(tx.rec,1)[1])
> "\"?\t"
>
> What am I doing wrong? How else can I create a Ptr{Ptr{UInt8}} of a cell
> array of text strings?
>