Hi Markku.
You have correctly diagnosed the problem that the initially
set global variables "are not stable". In your call
to myinit, you store a C-level reference to the var and func
R objects. But you need to tell R's memory management
that you need to hold onto them. Otherwise it is entitle
R never moves objects in memory, but it may garbage collect them.
What is not clear to me is that you can guarantee that the objects you
pass in are not copies subject to garbage collection, but then I don't
know how you are calling your functions. A way to make sure that your
pointers remain