Version française
Home     About     Download     Resources     Contact us    
Browse thread
Caml interface with C on x86_64
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sayan_(Sébastien_Li-Thiao-Té) <sayan@c...>
Subject: Re: [Caml-list] Allocating caml lists from C : possible bug on amd64
Markus Mottl wrote:
> On 3/13/06, *"Sayan (Sébastien Li-Thiao-Té)"* <sayan@crans.org 
> <mailto:sayan@crans.org>> wrote:
> 
>     I am trying to learn how to allocate a list in C and pass the result to
>     Caml on an opteron Debian box. Here is the function that I use :
> 
> 
> Your function does not protect "str" from being reclaimed by the GC 
> (which can happen in "caml_alloc_small"), and you should use the 
> Field-macro only to overwrite the contents of the cons-block in this 
> particular case, because you had used "caml_alloc_small" as allocation 
> function, and there was no intermediate allocation.
> 
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?

#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/bigarray.h>

test_liste (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);
    Store_field(cons,0, Val_int(1));
    Store_field(cons,1, Val_int(0));

    printf("This is test_liste.\n");
    printf(String_val(str));
    fflush(stdout);

    if (Is_block(cons)) { printf("true\n");};
    fflush(stdout);
    printf("cons has size %i \n",Wosize_val(cons));
    fflush(stdout);
    CAMLreturn (cons);
}

-- 
Li-Thiao-Té Sébastien