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 2482DBB9C for ; Thu, 19 Jan 2006 01:38:28 +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 k0J0cR0U019600 for ; Thu, 19 Jan 2006 01:38:27 +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 BAA28491 for ; Thu, 19 Jan 2006 01:38:26 +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 k0J0cODM027017 for ; Thu, 19 Jan 2006 01:38:26 +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 k0J0cMe8021969; Thu, 19 Jan 2006 09:38:23 +0900 (JST) Date: Thu, 19 Jan 2006 09:39:55 +0900 (JST) Message-Id: <20060119.093955.97297811.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: 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 43CEDF83.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43CEDF80.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 pointers:01 bool:01 bool:01 allocations:01 functions:01 int:01 int:01 jacques:01 jacques:01 parameter:02 parameter:02 parameters:02 parameters: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 > value-type parameters to C functions exported to OCaml should be > registered with CAMLparamX(...). Does this hold in general, or is it > considered acceptable/appropriate to just ignore this for "immediate" > values that do not hold pointers, but, say, int, bool etc. values? Registration is required to have the GC properly update the values. The GC may be called by any allocation. 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. Jacques