caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andres Varon <avaron@gmail.com>
To: Robert Roessler <roessler@rftp.com>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] marshal and C structures crash
Date: Wed, 7 Feb 2007 19:16:28 -0500	[thread overview]
Message-ID: <320AFD70-08FF-4F6F-8C1A-E6D5A38B18B7@gmail.com> (raw)
In-Reply-To: <45CA59CA.7030809@rftp.com>


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

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

Thanks!

Andres

> _______________________________________________
> 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


      reply	other threads:[~2007-02-08  0:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-07 22:05 Andres Varon
2007-02-07 22:59 ` [Caml-list] " Robert Roessler
2007-02-08  0:16   ` Andres Varon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=320AFD70-08FF-4F6F-8C1A-E6D5A38B18B7@gmail.com \
    --to=avaron@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=roessler@rftp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).