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 72061BC69 for ; Tue, 4 Dec 2007 21:14:34 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAJtDVUeAKgEfbWdsb2JhbACPUAsEBgkHGYEU X-IronPort-AV: E=Sophos;i="4.23,250,1194217200"; d="scan'208";a="5261103" Received: from mail.cs.rice.edu ([128.42.1.31]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 Dec 2007 21:14:33 +0100 Received: from mail.cs.rice.edu (localhost.localdomain [127.0.0.1]) by mail.cs.rice.edu (Postfix) with ESMTP id 1C71C2C2CE0 for ; Tue, 4 Dec 2007 14:14:32 -0600 (CST) X-Virus-Scanned: by amavis-2.4.0 at mail.cs.rice.edu Received: from mail.cs.rice.edu ([127.0.0.1]) by mail.cs.rice.edu (mail.cs.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LIn3+4zo+Imp for ; Tue, 4 Dec 2007 14:14:31 -0600 (CST) Received: from [10.249.109.2] (dunwlessnat.rice.edu [128.42.64.251]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.cs.rice.edu (Postfix) with ESMTP id 6D6F82C2CDC for ; Tue, 4 Dec 2007 14:14:31 -0600 (CST) Mime-Version: 1.0 (Apple Message framework v752.2) In-Reply-To: <474DC8DA.8070806@functionality.de> References: <474C48C5.708@starynkevitch.net> <474DADF7.5020204@rice.edu> <474DB454.9060507@inria.fr> <474DC28D.1060605@rice.edu> <474DC8DA.8070806@functionality.de> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <3DA0E7CA-2511-4282-89D1-8EB42876EC18@rice.edu> Content-Transfer-Encoding: 7bit From: Raj Bandyopadhyay Subject: Re: [Caml-list] Disabling the OCaml garbage collector Date: Tue, 4 Dec 2007 14:14:30 -0600 To: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.752.2) X-Spam: no; 0.00; ocaml:01 followup:01 ocaml:01 recursive:01 inserting:01 camlparam:01 val:01 camlreturn:01 val:01 alloc:01 alloc:01 sizeof:01 camlreturn:01 11000:98 garbage:01 Dear all, As a followup to this discussion, I have been trying to understand the OCaml/C interface better. Here's a very small program that I've been trying to get to work. It's a mutually recursive function, one part in C and the other in OCaml. (* (* Implement this in C *) let factC g n = if n=0 then [] else ("C",n)::(g (n-1));; *) external factC: (int ->(string * int) list) -> int -> ((string * int) list)= "caml_factC" let factO g n = if n=0 then [] else ("OCaml",n)::(g (n-1));; let rec fact n = factO (factC fact) n;; fact 12000;; The C function corresponding to factC is quite short, however the program crashes for values of n > about 11,000. I have tried inserting the code to register global roots (currently commented out), however, that makes no difference to the point of crash. I was just wondering if there is some really obvious step that I am missing, or using the wrong allocation function in Caml or something like that. Any suggestions would be welcome. I apologize in advice for inflicting code on you all, but I am out of ideas right now :( /* let factC g n = if n=0 then [] else ("C",n)::(g (n-1)) */ value caml_factC(value g,value n){ CAMLparam2(g,n); CAMLlocal3(e,l,new_l); //C value for n int locn = Int_val(n); //2 cases if (locn <= 0){ CAMLreturn(Val_int(0)); //empty list } else { e = alloc_tuple(2); //allocate a new list element ("C",n) Store_field(e,0,copy_string("C")); Store_field(e,1,n); //callback the closure g if(Tag_val(g) == Closure_tag) { //PROGRAM CRASHES HERE for large n and never returns from callback l = callback(g,Val_int(locn-1)); } else { exit(1); } //cons this tuple to the list obtained by callback new_l = alloc(2,0); //structured list value, tag is 0 Store_field(new_l,0,e); Store_field(new_l,1,l); //now we should register e,l and new_l with the GC //The program crashes at the same point (n>11000) regdless of whether the following //code is commented out or not. /* Vstore *roots = (Vstore *)caml_stat_alloc(sizeof (Vstore)); roots->v1 = e; roots->v2 = l; roots->v3 = new_l; caml_register_global_root(&roots->v1); caml_register_global_root(&roots->v2); caml_register_global_root(&roots->v3); CAMLreturn(roots->v3); //newly constructed list */ CAMLreturn(new_l); //newly constructed list } } Thanks! Raj