caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Marek Kubica <marek@xivilization.net>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] OCaml C macros, what do they do?
Date: Wed, 10 Apr 2013 18:15:26 +0200	[thread overview]
Message-ID: <20130410181526.2597c7a4@xivilization.net> (raw)

Hi,

I've been using the OCaml C API lately with quite some success (after I
realized that the GC causes everything to crash and fixing a lot of
stuff).

While things work now quite well, I'd like to know what *exactly* the
macros are for, since sometimes I can leave them out without any ill
effect.

So, here's my insights. If anyone of you could point out what is
correct and what is not, I'd be grateful:

 - CAMLparam1(foo), notifies the GC that foo is used in this function
   and not to be collected.
 - 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.
 - CAMLreturn(foo) returns a foo value and tells the GC that everything
   declared by CAMLparam will not be used anymore and could be
   collected.
 - 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.

regards,
Marek

             reply	other threads:[~2013-04-10 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10 16:15 Marek Kubica [this message]
2013-04-10 17:05 ` Alain Frisch
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=20130410181526.2597c7a4@xivilization.net \
    --to=marek@xivilization.net \
    --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).