* 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
* Re: [Caml-list] question about the OCaml/C interface
2007-05-09 9:28 question about the OCaml/C interface Jean-Marc EBER
@ 2007-05-09 9:39 ` Olivier Andrieu
2007-05-09 13:47 ` Markus Mottl
1 sibling, 0 replies; 3+ messages in thread
From: Olivier Andrieu @ 2007-05-09 9:39 UTC (permalink / raw)
To: Jean-Marc EBER; +Cc: Ocaml Mailing List
Hi,
On 5/9/07, Jean-Marc EBER <jeanmarc.eber@lexifi.com> wrote:
> Hello to all,
>
> I have a little technical question about the OCaml/C interface:
>
> Is the following code "correct":
yes
> 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:
no, that's the whole point of this Store_field macro, cf. its definition:
#define Store_field(block, offset, val) do{ \
mlsize_t caml__temp_offset = (offset); \
value caml__temp_val = (val); \
caml_modify (&Field ((block), caml__temp_offset), caml__temp_val); \
}while(0)
--
Olivier
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] question about the OCaml/C interface
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
1 sibling, 0 replies; 3+ messages in thread
From: Markus Mottl @ 2007-05-09 13:47 UTC (permalink / raw)
To: Jean-Marc EBER; +Cc: Ocaml Mailing List
On 5/9/07, Jean-Marc EBER <jeanmarc.eber@lexifi.com> wrote:
> Is the following code "correct":
>
> CAMLprim value my_func(...)
> {
> CAMLlocal2(ret);
There should be a CAMLparam0() on entry, otherwise the code seems correct to me.
Regards,
Markus
--
Markus Mottl http://www.ocaml.info markus.mottl@gmail.com
^ 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