Version française
Home     About     Download     Resources     Contact us    
Browse thread
C binding and GC interaction: storing values outside the heap
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stéphane Glondu <steph@g...>
Subject: Re: [Caml-list] C binding and GC interaction: storing values outside the heap
Le 07/09/2010 23:23, Paolo Donadeo a écrit :
>> Why don't you call caml_register_global_root on &(data->state_value) as well?
> 
> This was a solution I tried, but with the additional global root the
> finalization function was never called by the GC, so it solved the
> segfault with a memory leak :-)

Oh, I see.

Well... could you provide a full self-contained example? In your
original mail, there is:

  lua_atpanic(L, &default_panic);

whereas everything around talks about default_panic_v.

My idea would be to add an indirection: luaL_newstate__stub would return
a simple custom block (OCaml-heap-allocated) with a field which is an
abstract block. The Lua structure would be in the inner block. And in
the Lua structure, add a pointer to the inner block, and register the
inner block as a global root (the inner block should probably not be
allocated in the OCaml heap...). In the finalization function of the
outer block, un-register the global root and free the Lua structure.

How does that sound?

-- 
Stéphane