From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA00429 for caml-redistribution; Fri, 7 May 1999 09:45:20 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA31952 for ; Thu, 6 May 1999 22:36:38 +0200 (MET DST) Received: from pevele.eudil.fr (pevele.eudil.fr [134.206.63.9]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id WAA08813 for ; Thu, 6 May 1999 22:36:35 +0200 (MET DST) Received: from servnx.priv.eudil.fr (servnx.priv.eudil.fr [192.168.60.5]) by pevele.eudil.fr (8.9.3/jtpda-5.3.1) with ESMTP id WAA06787 for ; Thu, 6 May 1999 22:36:32 +0200 Received: from (rex@localhost) by servnx.priv.eudil.fr (8.8.4/jtpda-5.3) id WAA27067 for caml-list@inria.fr; Thu, 6 May 1999 22:36:29 +0200 (MET DST) From: Xavier.Redon@eudil.fr (Xavier.Redon) Message-Id: <199905062036.WAA27067@servnx.priv.eudil.fr> Subject: A list of finalized values ? To: caml-list@inria.fr Date: Thu, 6 May 1999 22:36:29 +0200 (MET DST) X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis I try to build a list of finalized values in C and use it under Caml. If I use alloc_final with used=0 and max=1, no problem, that works. But if I try with used=1 and max=1000 the custom top level enter in a endless loop (presumably in the GC). There are the sources of an small example : I must do a very basic error but I had spend a lot of time seeking it ... If you have a hint send it also to Xavier.Redon@eudil.fr I'm not sure I'm yet in the mailing list. Essai.mli: ==================================== type t val int_list : unit -> t list val int_convert : t -> int ==================================== Essai.ml: ==================================== type entier type t = entier external int_list : unit -> entier list = "int_list" ;; external int_convert : entier -> int = "int_get" ;; ==================================== Essai.c: ==================================== #include #include #include #include #include void int_free(value integer) { int *temp=(int *)Field(integer,1); if(temp!=NULL) free(temp); } value int_list(void) { CAMLlocal1(result); int i; result=Val_int(0); for(i=0;i<10;i++){ CAMLlocal2(subelement,temp); int *integer=malloc(sizeof(int)); *integer=i; subelement=alloc_final(2,int_free,1,100); Store_field(subelement,1,(value)integer); temp=alloc(2,0); Store_field(temp,0,subelement); Store_field(temp,1,result); result=temp; } CAMLreturn result; } value int_get(value integer) { CAMLparam1(integer); CAMLreturn Val_int(*(int *)Field(integer,1)); } ==================================== PS: The CAMLxxx macros generate a very long list of warnings when compiled with -Wall. CAMLreturn is not very safe : try if(cond) CAMLreturn result :-)