You can't modify an immutable. There are no exceptions.
>

First let me why I'm struggling with the immutables. The library I'm 
wrapping use complicated structures with sometimes several levels of 
nesting and several fixed length members (which are the ones that are 
currently causing me the troubles). Clag.jl translated them with immutables 
and if I try to make those type muttable than I get lots of Julia crashes. 
So I'm stuck with this round problem. Cannot make them muttable and can't 
mutate an imuttable.

 

> Why do you insist on writing `pointer([x])`? I have repeated said that is 
> an invalid code fragment. However, in this case, perhaps you meant 
> `unsafe_store(C.range,z)`?
>

Yes you warned me that it may sometimes segv, but what else can I do to get 
the pointer to a variable (a scalar or a composite type)? 
I asked it once in 
https://groups.google.com/forum/?fromgroups=#!topic/julia-users/i8DO3pBAHPU 
and my safe was to box it in pointer([M]). What else should I have done?

To send in a pointer to an integer to C that wants for example

function blabla(int *n) {}

what I do is

n = [0]
(wrapper to blabla) blabla(pointer(n))
n = unsafe_ref(n)

How should I proceed here instead of using pointer([n])?

The link you send me 
https://github.com/JuliaLang/julia/blob/jn/ccall3/doc/manual/calling-c-and-fortran-code.rst#passing-pointers-for-modifying-inputs

gives as example "width = Ref{Cint}(0)" but that errors

julia> width = Ref{Cint}(0)
ERROR: UndefVarError: Ref not defined

I'm more than happy to follow your advice but I need an alternative.

Thanks

Joaquim
 

>
>
> On Tue, Feb 24, 2015 at 11:36 AM J Luis <jmf...@gmail.com <javascript:>> 
> wrote:
>
>>
>>
>> use unsafe_load() to convert the value to a julia object, then 
>>> unsafe_store() to write the new struct back.
>>>
>>> at some point, I want to modify unsafe_load/unsafe_store to take a 
>>> fieldname symbol as the second argument to make this functionality more 
>>> direct available. however, there hasn't seemed to be a request / issue open 
>>> for it yet.
>>>
>>
>> PLEASE, do.
>>
>> I have the same type of problem but I'm not able to solve it with the 
>> solutions proposed in this thread.
>> See, I have this and want to change the *rgb_low*
>>
>> julia> gmt_lut = unsafe_load(C.range, 1);
>>
>> julia> gmt_lut.rgb_low
>> GMT.Array_4_Cdouble(0.583333333333333,0.0,1.0,0.0)
>>
>> which is a
>>
>> immutable Array_4_Cdouble
>>     d1::Cdouble
>>     d2::Cdouble
>>     d3::Cdouble
>>     d4::Cdouble
>> end
>>
>> so I do 
>>
>> julia> z = GMT.Array_4_Cdouble(0.0, 0.0, 0.0, 0.0)
>> GMT.Array_4_Cdouble(0.0,0.0,0.0,0.0)
>>
>> julia> unsafe_store!(pointer([gmt_lut.rgb_low]), z)
>> Ptr{GMT.Array_4_Cdouble} @0x00000000819faf60
>>
>> no errors but I don't know where new *z* immutable landed on because I 
>> keep seeing the old value
>>
>> julia> gmt_lut.rgb_low
>> GMT.Array_4_Cdouble(0.583333333333333,0.0,1.0,0.0)
>>
>> I suspect part of it is dues to the pointer([gmt_lut.rgb_low]) command  
>> because when I do several of those on line I keep getting different 
>> addresses
>>
>> julia> pointer([gmt_lut.rgb_low])
>> Ptr{GMT.Array_4_Cdouble} @0x0000000082b7baf0
>>
>> julia> pointer([gmt_lut.rgb_low])
>> Ptr{GMT.Array_4_Cdouble} @0x0000000082ba00d0
>>
>> julia> pointer([gmt_lut.rgb_low])
>> Ptr{GMT.Array_4_Cdouble} @0x0000000082ba0670
>>
>> but than how can modify this field(s)?
>>
>>
>>
>>  
>>
>

Reply via email to