Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Stéphane Glondu" <steph@glondu.net>
To: Paolo Donadeo <p.donadeo@gmail.com>
Cc: OCaml mailing list <caml-list@yquem.inria.fr>,
	OCaml-Lua devel ML <ocaml-lua-devel@lists.forge.ocamlcore.org>
Subject: Re: [Caml-list] C binding and GC interaction: storing values outside the heap
Date: Tue, 07 Sep 2010 23:48:33 +0200	[thread overview]
Message-ID: <4C86B331.1060009@glondu.net> (raw)
In-Reply-To: <AANLkTimj8tpJHQamUB+wf_uQ0A-AOra5CL2Uu6dn=LUA@mail.gmail.com>

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


  reply	other threads:[~2010-09-07 21:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-07 20:58 Paolo Donadeo
2010-09-07 21:12 ` [Caml-list] " Stéphane Glondu
2010-09-07 21:23   ` Paolo Donadeo
2010-09-07 21:48     ` Stéphane Glondu [this message]
2010-09-09  8:11       ` Paolo Donadeo
2010-09-07 22:53 ` Damien Doligez
2010-09-09  8:16   ` Paolo Donadeo
2010-09-08  5:06 ` Romain Beauxis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C86B331.1060009@glondu.net \
    --to=steph@glondu.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=ocaml-lua-devel@lists.forge.ocamlcore.org \
    --cc=p.donadeo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox