On Fri, Sep 9, 2016 at 8:36 PM, K leo <cnbiz...@gmail.com> wrote:

> Bart,
>
> Can you explain what you mean by "need to be rooted"?  The jl_new_struct
> statement as Isaiah suggested works, why do we need the additional
> statements as you suggested?
>

Because it doesn't, it'll segfault at any time if the GC feels like giving
you a bad day.

http://julia.readthedocs.io/en/latest/manual/embedding/#memory-management


>
>
> On Saturday, September 10, 2016 at 3:38:27 AM UTC+8, Bart Janssens wrote:
>>
>>
>>
>> On Fri, Sep 9, 2016 at 6:44 PM Isaiah Norton <isaiah...@gmail.com> wrote:
>>
>>>    // construct a TestType instance
>>>
>>>     jl_value_t* jl_A = jl_new_struct((jl_datatype_t*)
>>> jl_get_function((jl_module_t*)mod, "TestType"),
>>>                                      jl_box_float64(A.a),
>>> jl_box_float64(A.b));
>>>
>>>
>> The arguments to jl_new_struct need to be rooted, so you should do
>> something like:
>> jl_value_t* a = NULL;
>> jl_value_t* b = NULL;
>> JL_GC_PUSH2(a,b);
>> a = jl_box_float64(A.a);
>> b = jl_box_float64(A.b);
>> // use a and b in the new struct call
>> JL_GC_POP();
>>
>> What is the objective here? If this is still to be used from C++, there
>> may be easier ways using Cxx.jl or CxxWrap.jl.
>>
>> Cheers,
>>
>> Bart
>>
>

Reply via email to