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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B7432BC37 for ; Mon, 1 Mar 2010 07:26:06 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgMDAD7tikvUGyoGkWdsb2JhbACRJolwFQEBAQEJCwoHEwMfiBujC4VtLYhPhHsE X-IronPort-AV: E=Sophos;i="4.49,557,1262559600"; d="scan'208";a="57939738" Received: from smtp6-g21.free.fr ([212.27.42.6]) by mail4-smtp-sop.national.inria.fr with ESMTP; 01 Mar 2010 07:26:05 +0100 Received: from smtp6-g21.free.fr (localhost [127.0.0.1]) by smtp6-g21.free.fr (Postfix) with ESMTP id BDD69E08096 for ; Mon, 1 Mar 2010 07:26:00 +0100 (CET) Received: from localhost.localnet (88-123-240-180.rev.libertysurf.net [88.123.240.180]) by smtp6-g21.free.fr (Postfix) with ESMTP id DCEE0E0801F for ; Mon, 1 Mar 2010 07:25:57 +0100 (CET) From: Florent Monnier To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] How to pass C pointers to Caml Date: Mon, 1 Mar 2010 07:22:15 +0100 User-Agent: KMail/1.12.2 (Linux/2.6.31.12-desktop586-1mnb; KDE/4.3.2; i686; ; ) References: <9dfe358d1002281955k4cb9207bi4afe5d649fc20e05@mail.gmail.com> In-Reply-To: <9dfe358d1002281955k4cb9207bi4afe5d649fc20e05@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201003010722.15601.monnier.florent@gmail.com> X-Spam: no; 0.00; pointers:01 ocaml:01 pointers:01 ocaml:01 pointer:01 pointer:01 zhao:98 abstract:01 caml-list:01 int:01 caml:02 caml:02 ptr:02 ptr:02 structures:02 Le lundi 1 mars 2010 04:55:00, Jianzhou Zhao a =E9crit : > I have been calling OCaml code from C in my project. > The C code has some pointers to C structures. > I got 'seg fault' when calling the OCaml function receiving > C structure pointers. >=20 > 18.7 at http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html > gives the examples that pass int into OCaml. These examples work for me. > But, Does OCaml support to pass C structure pointers to OCaml? Yes it does. Just cast your pointer to the type value. In this tutorial there is an example "Pointers to C structures": http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_ptr the pointer to a C struct is wrapped on the ocaml side by an abstract type= =20 called "t" here, and it is provided back to C with print_t / dump_ptr.