From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 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 A08C0BBAF for ; Wed, 6 May 2009 18:43:08 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkoBAIZaAUqYToBpkWdsb2JhbACWeAEBAQEJCwoHEQW6CoQBBQ X-IronPort-AV: E=Sophos;i="4.40,303,1238968800"; d="scan'208";a="39553354" Received: from mailgate4.iss.soton.ac.uk ([152.78.128.105]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 May 2009 18:43:08 +0200 Received: from mailgate4.iss.soton.ac.uk (localhost.localdomain [127.0.0.1]) by mailgate4.iss.soton.ac.uk (8.13.8/8.13.4) with ESMTP id n46GUDM8002576; Wed, 6 May 2009 17:30:13 +0100 Received: from uos-msg00011-si.soton.ac.uk (uos-msg00011-si.soton.ac.uk [152.78.119.34]) by mailgate4.iss.soton.ac.uk (mailgate4.iss.soton.ac.uk [152.78.128.105]) envelope-from with ESMTP id l45HUD0907305334sU ret-id none; Wed, 06 May 2009 17:30:13 +0100 Received: from alpha.sesnet.soton.ac.uk (152.78.96.56) by smtp.soton.ac.uk (152.78.119.34) with Microsoft SMTP Server id 8.1.291.1; Wed, 6 May 2009 17:30:12 +0100 Received: from [127.0.0.1] (localhost [127.0.0.1]) by alpha.sesnet.soton.ac.uk (Postfix) with ESMTP id 9153A163537; Wed, 6 May 2009 17:30:12 +0100 (BST) Message-ID: <4A01BB13.1040602@soton.ac.uk> Date: Wed, 6 May 2009 17:30:11 +0100 From: "Dr. Thomas Fischbacher" User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Markus Mottl Cc: OCaml List Subject: Re: [Caml-list] Custom blocks and finalization References: <49FB04A9.3090008@soton.ac.uk> In-Reply-To: Content-Type: text/plain; charset="iso-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: Pass (uos-msg00011-si.soton.ac.uk: domain of t.fischbacher@soton.ac.uk designates 152.78.96.56 as permitted sender) receiver=uos-msg00011-si.soton.ac.uk; client-ip=152.78.96.56; helo=alpha.sesnet.soton.ac.uk; X-smtpf-Report: client=relay,white,ipv6; mail=; rcpt= X-ISS-MailScanner-Information: Please contact Serviceline@soton.ac.uk for more information X-ISS-MailScanner: Found to be clean X-Spam: no; 0.00; markus:01 mottl:01 pointers:01 ocaml-value:01 hash:01 serialize:01 deserialize:01 descriptors:01 camlparam:01 camlreturn:01 byterun:01 globroots:01 camlexport:01 struct:01 struct:01 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