From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 678EB7EE51 for ; Wed, 10 Apr 2013 19:05:04 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=pra; client-ip=193.252.23.214; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain@frisch.fr) identity=mailfrom; client-ip=193.252.23.214; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="alain@frisch.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@msa.smtpout.orange.fr) identity=helo; client-ip=193.252.23.214; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain@frisch.fr"; x-sender="postmaster@msa.smtpout.orange.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjsBAO6aZVHB/BfWlGdsb2JhbABQwg2CZ4ElDgEBAQEJCwkJFAMlgh8BAQU4QBELGAkWDwkDAgECAUUGAQwIAQGIFL89jx2DQQOXAIYDjhg X-IPAS-Result: AjsBAO6aZVHB/BfWlGdsb2JhbABQwg2CZ4ElDgEBAQEJCwkJFAMlgh8BAQU4QBELGAkWDwkDAgECAUUGAQwIAQGIFL89jx2DQQOXAIYDjhg X-IronPort-AV: E=Sophos;i="4.87,449,1363129200"; d="scan'208";a="10505332" Received: from msa05.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.214]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Apr 2013 19:05:03 +0200 Received: from [192.168.1.109] ([86.195.22.55]) by mwinf5d20 with ME id NH501l0121BJsxy03H51iG; Wed, 10 Apr 2013 19:05:03 +0200 Message-ID: <51659BC2.5030702@frisch.fr> Date: Wed, 10 Apr 2013 19:05:06 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:20.0) Gecko/20100101 Thunderbird/20.0 MIME-Version: 1.0 To: Marek Kubica , Caml List References: <20130410181526.2597c7a4@xivilization.net> In-Reply-To: <20130410181526.2597c7a4@xivilization.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] OCaml C macros, what do they do? On 04/10/2013 06:15 PM, Marek Kubica wrote: > - CAMLparam1(foo), notifies the GC that foo is used in this function > and not to be collected. And also that the foo pointer must be updated if the corresponding block is moved by the GC. So even if you can guarantee that foo will not be collected (because it is accessible otherwise), you must use CAMLparam if there is a possibility that the GC will be triggered in the function. > - CAMLlocal1(foo), creates a local variable foo. This is only required > if I want to bind some "value" type to a variable name. Not required > if I immediately return it. Same as above. All local values holding OCaml values that can be blocks (not only "ints") must reside in variables marked as CAMLlocal/CAMLparam at the time a GC occurs. In particular, it is generally unsafe to chain function calls without putting the intermediate result in a local variable marked as CAMLlocal. > - CAMLreturn(foo) returns a foo value and tells the GC that everything > declared by CAMLparam will not be used anymore and could be > collected. Yes. > - CAMLprim defines a function as "primitive" according to the > documentation. I have no idea what that means. The example in the > manual, section 19.6 does not use CAMLprim to start with. AFAIK, CAMLprim is only used within the OCaml distribution itself to collect (with sed) names of builtin primitives to be exposed by default by ocamlrun to bytecode programs. -- Alain