caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile STARYNKEVITCH <basile@starynkevitch.net>
To: John Whitington <john@coherentgraphics.co.uk>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Debugging a C / Ocaml interface problem
Date: Thu, 19 Feb 2009 18:34:59 +0100	[thread overview]
Message-ID: <499D9843.9070007@starynkevitch.net> (raw)
In-Reply-To: <15903958-833F-4698-94AB-DF517CBBCEF2@coherentgraphics.co.uk>

Hello All

John Whitington wrote:
>
>
> int fromFile(char* filename)
> {
>   return(Int_val(caml_callback(*caml_named_value("fromFile"), 
> caml_copy_string(filename))));
> }

You need to follow Ocaml strong garbage collection related rules for 
coding in C.
Are you aware of what a garbage collector is for precisely, how a 
copying GC works, what exactly are local and global roots?
Reading a few paragraphs could help a lot to get a big picture. Please 
read at least 
http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
Then read again chapter 18 [interfacing C with Ocaml] of the manual 
http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html

The major rule is that every allocated value should be an Ocaml root.

Try coding instead // untested!

int fromFile (char* filename)
{
  CAMLparam0;
  CAMLlocal3(fromfil_v, filnam_v, res_v);
  fromfil_v = *caml_named_value("fromFile");
  filnam_v =  caml_copy_string(filename);
  res_v = caml_callback(fromfil_v, filnam_v);
  CAMLreturnT(int, Int_val(res_v);
}

Hope this helps.

Don't forget that Ocaml (minor) garbage collector is a copying 
generational garbage collector, and read enough material to understand 
what that is meaning.

Regards.


-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


  reply	other threads:[~2009-02-19 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 17:18 John Whitington
2009-02-19 17:34 ` Basile STARYNKEVITCH [this message]
2009-02-19 17:43   ` [Caml-list] " John Whitington

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=499D9843.9070007@starynkevitch.net \
    --to=basile@starynkevitch.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=john@coherentgraphics.co.uk \
    /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).