caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Marc EBER <jeanmarc.eber@lexifi.com>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: question about the OCaml/C interface
Date: Wed, 09 May 2007 11:28:41 +0200	[thread overview]
Message-ID: <46419449.5090404@lexifi.com> (raw)

Hello to all,

I have a little technical question about the OCaml/C interface:

Is the following code "correct":

CAMLprim value my_func(...)
{
   CAMLlocal2(ret);
   ...
   result = ...
   ret = caml_alloc(5, 0);
   Store_field(ret, 0, caml_copy_double(result));
   ...
   CAMLreturn (ret);
}

or, arguing that [caml_copy_double] allocates and may therfore launch a gc cycle 
that may therefore modify [ret], one must write:

CAMLprim value my_func(...)
{
   ...
   CAMLlocal2(v, ret);
   ...
   result = ...
   ret = caml_alloc(5, 0);
   v = caml_copy_double(result);
   Store_field(ret, 0, v);
   ...
   CAMLreturn (ret);
}

I don't find a clear answer to that question in the documentation.

Jean-Marc Eber


             reply	other threads:[~2007-05-09  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-09  9:28 Jean-Marc EBER [this message]
2007-05-09  9:39 ` [Caml-list] " Olivier Andrieu
2007-05-09 13:47 ` Markus Mottl

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=46419449.5090404@lexifi.com \
    --to=jeanmarc.eber@lexifi.com \
    --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).