caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* question about the OCaml/C interface
@ 2007-05-09  9:28 Jean-Marc EBER
  2007-05-09  9:39 ` [Caml-list] " Olivier Andrieu
  2007-05-09 13:47 ` Markus Mottl
  0 siblings, 2 replies; 3+ messages in thread
From: Jean-Marc EBER @ 2007-05-09  9:28 UTC (permalink / raw)
  To: Ocaml Mailing List

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-09 13:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-09  9:28 question about the OCaml/C interface Jean-Marc EBER
2007-05-09  9:39 ` [Caml-list] " Olivier Andrieu
2007-05-09 13:47 ` Markus Mottl

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).