From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B3223BC57 for ; Tue, 7 Sep 2010 23:49:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4DAKNQhkyK54gDgWdsb2JhbACDGZ1wFQEBFiIir1mRaIEigyd0BIoY X-IronPort-AV: E=Sophos;i="4.56,330,1280700000"; d="scan'208";a="69029373" Received: from rouge.crans.org ([138.231.136.3]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Sep 2010 23:49:18 +0200 Received: from localhost (localhost.crans.org [127.0.0.1]) by rouge.crans.org (Postfix) with ESMTP id C7F6385F3; Tue, 7 Sep 2010 23:49:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at crans.org Received: from rouge.crans.org ([10.231.136.3]) by localhost (rouge.crans.org [10.231.136.3]) (amavisd-new, port 10024) with LMTP id k-6er1AKrELI; Tue, 7 Sep 2010 23:49:17 +0200 (CEST) Received: from [192.168.39.1] (fbx.up7.fr [88.185.141.188]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTPSA id 8B67C85E1; Tue, 7 Sep 2010 23:49:17 +0200 (CEST) Message-ID: <4C86B331.1060009@glondu.net> Date: Tue, 07 Sep 2010 23:48:33 +0200 From: =?UTF-8?B?U3TDqXBoYW5lIEdsb25kdQ==?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100805 Icedove/3.0.6 MIME-Version: 1.0 To: Paolo Donadeo Cc: OCaml mailing list , OCaml-Lua devel ML Subject: Re: [Caml-list] C binding and GC interaction: storing values outside the heap References: <4C86AABC.3010501@glondu.net> In-Reply-To: X-Enigmail-Version: 1.0.1 OpenPGP: id=49881AD3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; segfault:01 indirection:01 stub:01 pointer:01 ocaml:01 phane:98 steph:98 23,:98 phane:98 abstract:01 heap:01 heap:01 caml-list:01 finalization:01 finalization:01 Le 07/09/2010 23:23, Paolo Donadeo a =C3=A9crit : >> Why don't you call caml_register_global_root on &(data->state_value) a= s well? >=20 > 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? --=20 St=C3=A9phane