From: "\"Sayan (Sébastien Li-Thiao-Té)\"" <sayan@crans.org>
To: caml-list@yquem.inria.fr
Subject: Allocating caml lists from C : possible bug on amd64
Date: Mon, 13 Mar 2006 15:53:36 +0100 [thread overview]
Message-ID: <44158770.6000407@crans.org> (raw)
In-Reply-To: <440F556A.9010209@crans.org>
[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]
Hi list,
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 :
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/bigarray.h>
value 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));
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);
return (cons);
}
I call it from (test_liste.ml) :
external test_liste : string -> int list = "test_liste";;
test_liste "oaue";;
Makefile :
gcc -c -I/usr/lib64/ocaml readPeaks.c
ocamlc -custom readPeaks.o test_liste.ml -o a.out
The a.out file is compiled without problems but it crashes with a
segfault. However, if I compile on the same machine in a 32-bit chroot,
the program works.
Can anyone reproduce this behavior? Is that a bug linked to the 64bit
implementation of Ocaml or is it a gcc bug?
--
Li-Thiao-Té Sébastien
[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 187 bytes --]
OUTPUT = a.out
all : top
echo "Make finished."
clean :
rm *.cm* *.o $(OUTPUT)
top :
gcc -c -I/usr/lib64/ocaml readPeaks.c
ocamlc -custom readPeaks.o test_liste.ml -o $(OUTPUT)
[-- Attachment #3: readPeaks.c --]
[-- Type: text/x-csrc, Size: 552 bytes --]
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/bigarray.h>
value 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));
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);
return (cons);
}
[-- Attachment #4: test_liste.ml --]
[-- Type: text/plain, Size: 79 bytes --]
external test_liste : string -> int list = "test_liste";;
test_liste "oaue";;
next prev parent reply other threads:[~2006-03-13 14:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-08 22:06 Caml interface with C on x86_64 Li-Thiao-Té Sébastien
2006-03-13 14:53 ` "Sayan (Sébastien Li-Thiao-Té)" [this message]
2006-03-13 15:13 ` [Caml-list] Allocating caml lists from C : possible bug on amd64 Markus Mottl
2006-03-13 15:54 ` "Sayan (Sébastien Li-Thiao-Té)"
2006-03-13 16:39 ` Markus Mottl
2006-03-13 17:42 ` Xavier Leroy
2006-03-13 18:05 ` Li-Thiao-Té Sébastien
2006-03-13 18:53 ` Markus Mottl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44158770.6000407@crans.org \
--to=sayan@crans.org \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox