From: Jeremie Dimino <jdimino@janestreet.com>
To: Romain Bardou <romain.bardou@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Auxiliary C function which manipulates the OCaml heap
Date: Tue, 12 Mar 2013 15:13:11 +0000 [thread overview]
Message-ID: <CANhEzE70wXOWXbaqw1Q3SdJyWLGRtYdDQLku3FDq7jSsa4PFeg@mail.gmail.com> (raw)
In-Reply-To: <513F41BC.7070509@inria.fr>
Hi,
On Tue, Mar 12, 2013 at 2:54 PM, Romain Bardou <romain.bardou@inria.fr> wrote:
> However, this function does not use CAMLreturn, as it does not return an
> OCaml value but a C value (actually void). So the compiler emits a warning:
> "unused variable 'caml__frame'" if I use CAMLparam in aux.
>
> Is it ok to call CAMLlocal in this way? The documentation says it cannot be
> called inside nested blocks. Is an auxiliary function considered a nested
> block?
No, you must use [CAMLreturn0] in this case.
> Note that the caller of "aux", or (in another case) the caller of the caller
> of "aux", has called CAMLparam. If this was not the case, would it make a
> difference?
No, CAMLparam macros are only for the current function. They register
the C local variables as local roots. In sub-function they are
different local variables (different position on the stack) so you
need to register them too.
> Similarly, if "aux" had some OCaml value arguments, should it call CAMLparam
> even though the caller of "aux" has declared them to the GC using CAMLparam
> or CAMLlocal?
Yes.
> Similarly, if "aux" did return an OCaml value, should it call CAMLreturn
> (and thus CAMLparam) to return the value, or should it use the normal
> "return"?
You must use [CAMLreturnT(C-type, expr)] in this case.
And for other cases you can also use Begin_roots and End_roots.
prev parent reply other threads:[~2013-03-12 15:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 14:54 Romain Bardou
2013-03-12 15:13 ` Jeremie Dimino [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=CANhEzE70wXOWXbaqw1Q3SdJyWLGRtYdDQLku3FDq7jSsa4PFeg@mail.gmail.com \
--to=jdimino@janestreet.com \
--cc=caml-list@inria.fr \
--cc=romain.bardou@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