English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
GC with C issues
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-03 (12:50)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] GC with C issues
 ronniec95@lineone.net [Thu, 3 Feb 2005]:
 > On Thu, Feb 03, 2005 at 12:16:43PM +0100, Olivier Andrieu wrote:
 > >  > I can't see what I'm doing wrong in the allocation? I expect
 > >  > this to leak because I'm not freeing the allocated
 > >  > 'someObject' but I don't expect it to segfault though?
 > > 
 > > When you use CAMLparam in a function you have to exit it with
 > > CAMLreturn (or CAMLreturn0).
 > > 
 > > Do not use Store_field on your block: it's an Abstract block, not
 > > traced by the GC, use the Field macro directly :
 > > 
 > >  Field (retVal, 0) = (value) x;
 > Hmm... I thought I was only supposed to do that when using
 > alloc_small/alloc_shr interface? However using your method does
 > work in this small example though I'm worried about if something
 > unexpected will happen in more 'real-life' code...

No, Store_field should only be used on structured blocks (check the
manual). You can access and modify abstract blocks directly since
their content is not examined by the GC. 

Your code works fine in this small example because the block initially
contains zeroes, but an abstract block can contain anything and this can
confuse the GC if you use Store_field.