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
marshal and C structures crash
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-08 (00:16)
From: Andres Varon <avaron@g...>
Subject: Re: [Caml-list] marshal and C structures crash

On Feb 7, 2007, at 5:59 PM, Robert Roessler wrote:

> Andres Varon wrote:
>> ...
>> For those of you who reached this line of my email, thanks for the  
>> effort! I will listen at any ideas that could pop up in your minds.
> Hey, I will read the full message just to see what someone is doing  
> with 70K lines of OCaml code! :)
jejeje, we detect very complex combinatorial events in DNA sequences,  
using different optimality criteria, over an evolutionary tree that  
we are searching for. The program was in version 3 and became painful  
to maintain (8 years of many hands working on it and - most important  
-, learning OCaml on it), so now it has been rewritten from scratch.

> The usual comment - you don't mention any version and platform  
> details... especially with something that took as long as this  
> probably did, those might be of interest (particularly since some  
> teams doing a project of this size might have not been keeping up  
> with OCaml releases).
I realized that afterwards! In part I didn't mention it because it's  
happening consistently in all versions of OCaml and platforms that  
are applicable to:
3.08.4 and 3.09.2, 3.09.3 running in the following platforms:

  Mac OS X - PPC / Intel, Linux x86, Linux AMD64, Linux EMT-64. I  
truly believe it is something I do wrong in my C side, but for the  
life of mine, I don't see what it is, and I don't understand why it  
shows up only in relation to successive marshals. Note that the  
marshalled structure do not include any of my C types wrapped in an  
OCaml abstract one. It did at the beginning (that was my first  
suspect), but before working around representations in pure ocaml to  
try to get rid of the problem, I even compared the output of separate  
marshals of the same values multiple times, unmarshaling and  
marshaling again, and comparing different repetitions, with no errors  

> It is not crystal clear that you are using "finalize" routines - if  
> so, they are an obvious (and easy) place to position check code.   
> If not, why not?  It sounds like you might *need* to wrap some of  
> your values created in C-land in smart-but-thin OCaml objects, if  
> for nothing else than to more delicately handle lifetime issues.
> These "popped up" for me on my initial reading. ;)

We malloc the C structures, and store the pointer to them in a custom  
type for which we provide the functions in OCaml. The registration of  
the custom type (using a custom_operations structure), includes a  
free function to deallocate whatever C allocated memory should be  
when the garbage collector does its job, and we provide them.

AFAIK, having a pointer to an allocated C structure wrapped in a  
custom type is safe, provided the C structure does not point back to  
the OCaml heap, and we don't: the pointers go in only one direction  
to the C side.

> Robert Roessler
> roessler@rftp.com
> http://www.rftp.com



> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs