caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: Marek Kubica <marek@xivilization.net>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] OCaml C macros, what do they do?
Date: Wed, 10 Apr 2013 19:05:06 +0200	[thread overview]
Message-ID: <51659BC2.5030702@frisch.fr> (raw)
In-Reply-To: <20130410181526.2597c7a4@xivilization.net>

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

  reply	other threads:[~2013-04-10 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10 16:15 Marek Kubica
2013-04-10 17:05 ` Alain Frisch [this message]
2013-04-10 21:04   ` Marek Kubica

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=51659BC2.5030702@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=marek@xivilization.net \
    /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;
as well as URLs for NNTP newsgroup(s).