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.
>
Sorry, I didn't mean to say that the original content was lost (it's not
easy to find a good title subject to these issues)
> 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.
>
But, that I know off, there is no call to ccall (yet). Only wrapping into a
type and trying to get the info back.
If don't use pointer
julia> tx = X(txt)
WARNING: convert{T}(p::Type{Ptr{T}},a::Array) is deprecated, use convert(p,
pointer(a)) instead.
in convert at deprecated.jl:29
in call at no file
X(Ptr{Ptr{UInt8}} @0x0000000082ed9170)
julia> bytestring(pointer_to_array(tx.rec,1)[1])
"?F"
and still not able to recover the text strings
(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)
>
looking forward to try my luck with it
> 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?
>>
>
>