caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] GC and interoperability with C
@ 2001-07-09  4:59 Alexander V. Voinov
  2001-07-09  6:59 ` Jacques Garrigue
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander V. Voinov @ 2001-07-09  4:59 UTC (permalink / raw)
  To: caml

Hi All,

>From what I see in the documentation, I see no way to 'lock' an OCaml
value on the heap so that it can be safely accessed from C code, and
then 'unlock' it, say, in the finalization function of some
Custom_block. In contrast to Python, e.g., where you just increment and
decrement the reference count.

Is this right?

If this is right, the interaction of OCaml to C becomes one-way, you
cannot safely access OCaml world from arbitrary C code.

Is this right?

Alexander
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [Caml-list] GC and interoperability with C
@ 2001-07-09 22:08 Alexander V. Voinov
  0 siblings, 0 replies; 7+ messages in thread
From: Alexander V. Voinov @ 2001-07-09 22:08 UTC (permalink / raw)
  To: caml

Hi Jacques,

Jacques Garrigue wrote:
> 
> > From what I see in the documentation, I see no way to 'lock' an OCaml
> > value on the heap so that it can be safely accessed from C code, and
> > then 'unlock' it, say, in the finalization function of some
> > Custom_block. In contrast to Python, e.g., where you just increment and
> > decrement the reference count.
> 
> Yes, Python uses (used?) reference counting. More clever (and faster)
> GC's, like that of caml, have to move things around.
> 
> > If this is right, the interaction of OCaml to C becomes one-way, you
> > cannot safely access OCaml world from arbitrary C code.
> 
> Yes, you can. You just have to register a pointer with the GC, and
> everytime the target is moved around, the pointer will be updated.
> See
>     void register_global_root (value *);
>     void remove_global_root (value *);

Thank you. But how can get a pointer to a value, which came as a
parameter, say:

value my_func(value a, value b)
{
   ...
   make a sophisticated C structure, referring to these values...
   ...
   return result;
}

because &a and &b point to the stack which will vanish upon exit. Or do
the CAMLparam wrappers do what is needed in this case?

Alexander
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-07-12 15:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-09  4:59 [Caml-list] GC and interoperability with C Alexander V. Voinov
2001-07-09  6:59 ` Jacques Garrigue
     [not found]   ` <3B49C748.9CFB4E6@quasar.ipa.nw.ru>
     [not found]     ` <20010710094419W.garrigue@kurims.kyoto-u.ac.jp>
2001-07-10  0:46       ` Alexander V. Voinov
2001-07-12  5:47       ` Alexander V. Voinov
2001-07-12  7:34         ` Xavier Leroy
2001-07-12 15:42           ` Alexander V. Voinov
2001-07-09 22:08 Alexander V. Voinov

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