From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id EA5FDBBC4 for ; Thu, 19 Feb 2009 18:35:14 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnYGAIsnnUk+BBFoWmdsb2JhbACBbpJdARYKCQkSAr5GhA4G X-IronPort-AV: E=Sophos;i="4.38,236,1233529200"; d="scan'208";a="24388533" Received: from smtp-104-thursday.noc.nerim.net (HELO mallaury.nerim.net) ([62.4.17.104]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Feb 2009 18:35:00 +0100 Received: from hector.lesours (ours.starynkevitch.net [213.41.244.95]) by mallaury.nerim.net (Postfix) with ESMTP id CCDABA107F; Thu, 19 Feb 2009 18:34:58 +0100 (CET) Received: from glinka.lesours ([192.168.0.1] ident=basile018) by hector.lesours with esmtp (Exim 4.69) (envelope-from ) id 1LaCo0-0008Ry-75; Thu, 19 Feb 2009 18:35:24 +0100 Message-ID: <499D9843.9070007@starynkevitch.net> Date: Thu, 19 Feb 2009 18:34:59 +0100 From: Basile STARYNKEVITCH User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: John Whitington Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Debugging a C / Ocaml interface problem References: <15903958-833F-4698-94AB-DF517CBBCEF2@coherentgraphics.co.uk> In-Reply-To: <15903958-833F-4698-94AB-DF517CBBCEF2@coherentgraphics.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; basile:01 basile:01 ocaml:01 val:01 ocaml:01 wikipedia:01 wiki:01 interfacing:01 camlparam:01 val:01 generational:01 faiencerie:01 92340:01 reine:01 garbage:01 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: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} ***