Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] CamlDL/Abstract pointers problem
[ 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@k...>
Subject: Re: [Caml-list] CamlDL/Abstract pointers problem
From: Brian Hurt <bhurt@spnz.org>
> On Fri, 30 Jan 2004, Jacques Garrigue wrote:
> 
> > However, there is another scenario which could cause you problems:
> > if for some reason your C pointer get freed, and later the ML heap is
> > extended so that it includes the address of the pointer, then you may
> > have some pointers left on the ML which will now be seen as ML
> > pointers.
> 
> ML doesn't memset memory it just allocated?  This may be a problem- I 
> don't *think* the C standard requires malloc to memset the memory itself, 
> which means you might be getting garbage memory.

That's not the problem: blocks used by ML are always initialized
anyway.

The trouble is that you may at some point in time pass to your ML
program a pointer to some C structure outside of the heap. Since it is
outside of the heap, the garbage collector does not attempt to visit
it, and this creates no problem.
But it may happen (if your structure is freed on the C side), that at
some time in the future a new page is added to the heap, containing
the location where was the C structure.  If your pointer on the ML
side is still around, this is now a pointer to somewhere in the heap,
and the GC will attempt to visit it.

Even if ML was to zero the page before using it, after putting some
ML objects in the page, your pointer can easily end up pointing in the
middle of some random data.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners