From: "Dr. Thomas Fischbacher" <t.fischbacher@soton.ac.uk>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Custom blocks and finalization
Date: Wed, 6 May 2009 17:30:11 +0100 [thread overview]
Message-ID: <4A01BB13.1040602@soton.ac.uk> (raw)
In-Reply-To: <f8560b80905010900g6459388arc5c2be98059c980c@mail.gmail.com>
Markus Mottl wrote:
> Yes, if your C-finalizer e.g. needs to remove global roots, this may
> not be sound. I am not totally sure this is actually true in the
> current implementation, but at least the documentation clearly
> indicates that any interaction with the OCaml-runtime from within
> C-finalizers is prohibited. You may essentially just extract C-values
> / pointers from the OCaml-value to be reclaimed and manipulate those.
>
I take it you are referring to this part of the documentation (18.9.1
bottom):
===>
Note: the finalize, compare, hash, serialize and deserialize functions
attached to custom block descriptors must never trigger a garbage
collection.
Within these functions, do not call any of the Caml allocation
functions, and
do not perform a callback into Caml code. Do not use CAMLparam to
register the
parameters to these functions, and do not use CAMLreturn to return the
result.
<===
Let's have a look at byterun/globroots.c:
/* Un-register a global C root */
CAMLexport void caml_remove_global_root(value *r)
{
struct global_root * update[NUM_LEVELS];
struct global_root * e, * f;
int i;
/* Init "cursor" to list head */
e = (struct global_root *) &caml_global_roots;
/* Find element in list */
for (i = caml_global_roots.level; i >= 0; i--) {
while (1) {
f = e->forward[i];
if (f == NULL || f->root >= r) break;
e = f;
}
update[i] = e;
}
e = e->forward[0];
/* If not found, nothing to do */
if (e == NULL || e->root != r) return;
/* Rebuild list without node */
for (i = 0; i <= caml_global_roots.level; i++) {
if (update[i]->forward[i] == e)
update[i]->forward[i] = e->forward[i];
}
/* Reclaim list element */
caml_stat_free(e);
/* Down-correct list level */
while (caml_global_roots.level > 0 &&
caml_global_roots.forward[caml_global_roots.level] == NULL)
caml_global_roots.level--;
}
...and memory.c says:
CAMLexport void caml_stat_free (void * blk)
{
free (blk);
}
So... how could caml_remove_global_root() actually trigger a heap GC?
--
best regards,
Thomas Fischbacher
t.fischbacher@soton.ac.uk
next prev parent reply other threads:[~2009-05-06 16:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-30 15:46 Markus Mottl
2009-04-30 18:17 ` [Caml-list] " Dr. Thomas Fischbacher
[not found] ` <49FB04A9.3090008@soton.ac.uk>
2009-05-01 16:00 ` Markus Mottl
2009-05-06 16:30 ` Dr. Thomas Fischbacher [this message]
2009-05-06 16:54 ` Markus Mottl
2009-05-06 17:53 ` Dr. Thomas Fischbacher
2009-05-08 9:36 ` Xavier Leroy
2009-05-08 13:48 ` Markus Mottl
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=4A01BB13.1040602@soton.ac.uk \
--to=t.fischbacher@soton.ac.uk \
--cc=caml-list@yquem.inria.fr \
--cc=markus.mottl@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