From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 659A5BB9C for ; Thu, 19 Jan 2006 14:49:36 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0JDnZr2030034 for ; Thu, 19 Jan 2006 14:49:36 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA06769 for ; Thu, 19 Jan 2006 14:49:35 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0JDnXLQ021223 for ; Thu, 19 Jan 2006 14:49:34 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id k0JDnWmH012099; Thu, 19 Jan 2006 22:49:32 +0900 (JST) Date: Thu, 19 Jan 2006 22:49:28 +0900 (JST) Message-Id: <20060119.224928.102169339.garrigue@math.nagoya-u.ac.jp> To: Thomas.Fischbacher@Physik.Uni-Muenchen.DE Cc: caml-list@inria.fr Subject: Re: [Caml-list] C interface style question From: Jacques Garrigue In-Reply-To: References: <20060119.093955.97297811.garrigue@math.nagoya-u.ac.jp> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43CF98EF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43CF98ED.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 allocations:01 ocaml:01 bool:01 allocations:01 ocaml:01 damien:01 eternal:98 doligez:01 behaviour:01 essentially:01 int:01 jacques:01 jacques:01 thread:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Thomas Fischbacher > > Registration is required to have the GC properly update the values. > > The GC may be called by any allocation. > > Just by allocations in the local C code? Is this (and will this always > be) a guaranteed property? How about future extensions and multithreading? This is the point of the global locking mechanism. Only one thread may manipulate ocaml values (both access and allocation.) I'm not sure about the eternal guarantee, but most libraries around depend essentially on this property. > > So it is only safe not to register a parameter (or a variable) in any > > of the following 4 cases. > > 1) you know that it can only hold a non-pointer value (int, bool, ...) > > (i.e. the GC has nothing to update) > > 2) there are no allocations in your function > > 3) the parameter is not accessed after the first allocation > > 4) for a new variable whose contents is returned, there is no > > allocation between the setting of the variable and return. > > > > (1) and (2) are relatively easy to see, but (3) and (4) are a bit > > trickier (particularly with side-effecting expressions), so > > it is not a bad idea to register more parameters than strictly > > necessary. > > Can I take this as an official position of the OCaml team on the behaviour > of the C interface? For this you would have to ask Damien Doligez :-) But this seems to be basic enough to be safe. Rules about assignment are much more tricky! Jacques