Version française
Home     About     Download     Resources     Contact us    
Browse thread
C interface style question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] C interface style question
From: Thomas Fischbacher <Thomas.Fischbacher@Physik.Uni-Muenchen.DE>

> > Registration is required to have the GC properly update the values.
> > The GC may be called by any allocation.
> 
> Just by allocations in the local C code? Is this (and will this always 
> be) a guaranteed property? How about future extensions and multithreading?

This is the point of the global locking mechanism. Only one thread may
manipulate ocaml values (both access and allocation.)
I'm not sure about the eternal guarantee, but most libraries around
depend essentially on this property.

> > So it is only safe not to register a parameter (or a variable) in any
> > of the following 4 cases.
> > 1) you know that it can only hold a non-pointer value (int, bool, ...)
> >    (i.e. the GC has nothing to update)
> > 2) there are no allocations in your function
> > 3) the parameter is not accessed after the first allocation
> > 4) for a new variable whose contents is returned, there is no
> >    allocation between the setting of the variable and return.
> > 
> > (1) and (2) are relatively easy to see, but (3) and (4) are a bit
> > trickier (particularly with side-effecting expressions), so
> > it is not a bad idea to register more parameters than strictly
> > necessary.
> 
> Can I take this as an official position of the OCaml team on the behaviour 
> of the C interface?

For this you would have to ask Damien Doligez :-)
But this seems to be basic enough to be safe.
Rules about assignment are much more tricky!

      Jacques