Hi,
Let me try to explain my need to fight with immutables. I made another
round to my GMT wrapper (which is hopefully almost ready) and struggled
again with the immutables. The point is that GMT API structs are deeply
nested and need to be mirrored with immutables (otherwise Julia crashes).
Namely this one
https://github.com/joa-quim/GMT.jl/blob/master/src/libgmt_h.jl#L1445
so I first went with the advised solution of creating and filling the type
is julia and replace the pointees of the immutable type, which I did here
(see the commented code):
https://github.com/joa-quim/GMT.jl/blob/master/src/gmt_main.jl#L874
but the problem now is that *TS* is a memory owned by Julia and that will
be fatal when GMT's own memory cleaning functions try to free it and ->
Julia crashes.
So if use a pure Julia solution I've no choice but to let memory leeks and
other house keeping to be done. Not good at all.
For the time being I ended up with this ugly C trick of sending to C the
job of changing some members (non-pointers) that need absolutely to changed
after the type has been created
http://gmt.soest.hawaii.edu/projects/gmt/repository/entry/branches/5.2.0/src/gmt_api.c#L7376
but besides being ugly I've no guarantee that I can convince my partners to
let that backdoor go into the GMT lib. I much lovelier trick would be if
this chunk only of that backdoor function would work.
else if (!strncmp (keyword, "API_POINTER_", 12U)) { /* Blindly
change a pointer to a scalar. Irritatingly Julia ignores this */
if (!strcmp(&keyword[12], "UINT64"))
*(uint64_t *)ptr = *(uint64_t *)what;
}
but the problem is that I am not able to get from Julia the pointers
address that would make that work. I tried with
pointer(S0.n_rows)
and
pointer_from_objref(S0.n_rows)
and others, but nothing. It seams to work in the C side (I can see it with
the debugger when I set in that piece of code) but than nothing changes.
The C struct doesn't change.
Is there a way to get the C pointer address from Julia?
So, I guess my question is:
How do we do to change immutable members that are not pointers?
Is that really impossible and I'm doomed to the path exemplified with
that C GMT_blind_change_struct() function?