From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D0507BBBC for ; Mon, 13 Mar 2006 18:42:49 +0100 (CET) Received: from smtp2-g19.free.fr (smtp2-g19.free.fr [212.27.42.28]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k2DHgnOa022865 for ; Mon, 13 Mar 2006 18:42:49 +0100 Received: from [192.168.1.2] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp2-g19.free.fr (Postfix) with ESMTP id 512717340A; Mon, 13 Mar 2006 18:42:49 +0100 (CET) Message-ID: <4415AF18.5070404@inria.fr> Date: Mon, 13 Mar 2006 18:42:48 +0100 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?=22Sayan_=28S=E9bastien_Li-Thiao-T=E9=29=22?= Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Allocating caml lists from C : possible bug on amd64 References: <440F556A.9010209@crans.org> <44158770.6000407@crans.org> <441595B8.3040203@crans.org> In-Reply-To: <441595B8.3040203@crans.org> X-Enigmail-Version: 0.91.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4415AF19.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; allocating:01 bug:01 compiler:01 compiler:01 gcc:01 -wall:01 stdio:01 mlvalues:01 bigarray:01 alloc:01 val:01 val:01 camlparam:01 alloc:01 printf:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 > I have already tried to be GC-friendly, and use the "standard" way to do > things. For example the following function also works using a 32-bit > chroot, but also fails with the 64-bit compiler. The question is : why > does it fail with the 64-bit compiler? Because your C code is wrong. gcc -Wall is your friend. > #include > #include > #include > #include > > test_liste (value str) { Should be "value test_list(value str)". > // test function to return a list to caml > // value cons; > // cons = caml_alloc_small (2,0); > // caml_modify(&Field(cons,0),Val_int(0)); > // caml_modify(&Field(cons,1),Val_int(0)); > > CAMLparam1(str); > CAMLlocal1(cons); > cons = caml_alloc (2,0); You haven't declared caml_alloc (include ), so the C compiler assumes it returns an int instead of a value, and generates wrong code. > Store_field(cons,0, Val_int(1)); > Store_field(cons,1, Val_int(0)); > > printf("This is test_liste.\n"); > printf(String_val(str)); Should be: printf("%s", String_val(str)); (Hint: what happens if str contains "%s" ?) > fflush(stdout); > > if (Is_block(cons)) { printf("true\n");}; > fflush(stdout); > printf("cons has size %i \n",Wosize_val(cons)); > fflush(stdout); > CAMLreturn (cons); > } > - Xavier Leroy