From: Marek Kubica <marek@xivilization.net>
To: Alain Frisch <alain@frisch.fr>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] OCaml C macros, what do they do?
Date: Wed, 10 Apr 2013 23:04:56 +0200 [thread overview]
Message-ID: <20130410230456.5c2605ea@xivilization.net> (raw)
In-Reply-To: <51659BC2.5030702@frisch.fr>
Hello Alain,
Thanks for your answer, I'm glad that I was not so far off and can see
clearer now.
On Wed, 10 Apr 2013 19:05:06 +0200
Alain Frisch <alain@frisch.fr> wrote:
> 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.
If I understand correctly, GC is only triggered by the caml_*
allocation functions, or is there some other possibility that I am
missing?
> > - 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.
Okay, I suspected so much but wasn't sure since when I tried chaining
without CAMLlocal it worked. But an edge case might require it. I'll
add CAMLlocals to my code to be on the safe side, thanks.
> 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.
Great, so it doesn't apply to my code at all. Will remove it.
regards,
Marek
prev parent reply other threads:[~2013-04-10 21:04 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
2013-04-10 21:04 ` Marek Kubica [this message]
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=20130410230456.5c2605ea@xivilization.net \
--to=marek@xivilization.net \
--cc=alain@frisch.fr \
--cc=caml-list@inria.fr \
/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).