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.5 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D61EDBC0A for ; Tue, 17 Apr 2007 05:11:14 +0200 (CEST) Received: from web23312.mail.ird.yahoo.com (web23312.mail.ird.yahoo.com [217.146.189.82]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id l3H3BE5p015694 for ; Tue, 17 Apr 2007 05:11:14 +0200 Received: (qmail 77115 invoked by uid 60001); 17 Apr 2007 03:11:14 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=NZJ4036gScweognsjubaNWJDqUglT3MGviPHrilwnTeEda6S80fOCW93trFh1hsL06C6Qco2suR5diykAPNwFyHaMq7l6CLDSpE3SPgugg4L7Ol2rQLqoEzROeQjQzMycusQErg/rH8JIDPNHIxiLd9e1ttY7US4N25F/+idQsI=; X-YMail-OSG: goh8uWoVM1kxfO5AvvZ.UVLgrSEaHU4x8omLhtzR Received: from [200.108.236.97] by web23312.mail.ird.yahoo.com via HTTP; Tue, 17 Apr 2007 05:11:13 CEST Date: Tue, 17 Apr 2007 05:11:13 +0200 (CEST) From: Stefano Ballabeni Subject: Interfacing C and OCAML using the bigarray library To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <219784.75442.qm@web23312.mail.ird.yahoo.com> X-Miltered: at discorde with ID 46243AD2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; interfacing:01 ocaml:01 bigarray:01 ocaml:01 bigarray:01 mlvalues:01 dims:01 malloc:01 sizeof:01 malloc:01 sizeof:01 dims:01 alloc:01 elt:01 gcc:01 Hi everybody, First of all, sorry for my english, it's so bad, but I'll try to be understandable. I'm trying to send a dynamically allocated C matrix to OCAML. I've seen that the bigarray library seems to be what I need. The problem is that I can't pass a _dynamically_ allocated matrix to OCAML, the values don't arrive to OCAML. A quick example : test.c ---- #include #include value make_c_matrix(void) { long dims[2]; unsigned char **my_c_array; my_c_array = malloc(sizeof (unsigned char *) * 2); my_c_array[0] = malloc(sizeof (unsigned char) * 2); my_c_array[1] = malloc(sizeof (unsigned char) * 2); my_c_array[0][0] = 3; my_c_array[0][1] = 4; my_c_array[1][0] = 5; my_c_array[1][1] = 6; dims[0] = 2; dims[1] = 2; return (alloc_bigarray(BIGARRAY_UINT8 | BIGARRAY_C_LAYOUT, 2, my_c_array, dims)); } test.ml -- external take_matrix : unit -> (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array2.t = "make_c_matrix" let _ = let m = take_matrix () in print_string "-- CAML --\n"; print_int m.{0, 0}; print_string " "; print_int m.{0, 1}; print_newline (); print_int m.{1, 0}; print_string " "; print_int m.{1, 1}; print_newline (); Then I compile : gcc -W -Wall -ansi -pedantic -c test.c ocamlc -custom bigarray.cma test.o test.ml I run it : ./a.out and it displays : -- CAML -- 208 208 6 8 As you can see these values are not exactly the one I entered in the C code. So, is that possible to use a dinamically allocated C matrix in OCAML using bigarray ? If it is, what do I do wrong ? I have been searching for days to make this lib work fine... If not, do you have a pretty solution ? Thanks in advance. -- Stefano Ballabeni stefano.ballabeni@yahoo.fr ___________________________________________________________________________ Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses http://fr.answers.yahoo.com