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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 39A1FBC57 for ; Mon, 1 Mar 2010 14:23:18 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AisDAF1Oi0vRVdO4kGdsb2JhbACPMwWEAodMCBUBAQEBCQkMBxMDH4gbo3NCg2ciiFUBAQMFhHYEgxeJBg X-IronPort-AV: E=Sophos;i="4.49,560,1262559600"; d="scan'208";a="53798102" Received: from mail-yw0-f184.google.com ([209.85.211.184]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Mar 2010 14:23:17 +0100 Received: by ywh14 with SMTP id 14so1261267ywh.15 for ; Mon, 01 Mar 2010 05:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=GjIzjPFwOHydx/oG7BJP0vor2f+JVGPpRg7cKL1uCBU=; b=ozCYHwABBHG5psa29SuySFfMK1Xq3luQhzFyRVB85Y+XBFL0Dbtx025nhNpNdgSCw/ RpxkZTio4nAlsxEiSS5KOp9qpqastj5NCTrktJ11M6zs8KBM+n/nRj/OmdQk6oni8xL2 rFxJC2gVpdP6Ymv4izf45mqMGWxzYmry3JJac= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=tROO1xbUUJNnEYaSrLp3JPdQSYnUIJxc7QWhsugCISO/0L5d5L4kgcP0P0D/kn2Mtv +k6c1/YVD9Kaim5m/n6acIGd8yXLmt2h3KVdFAMdLUVr+BBuymJp2+0on380DB21QZ1h E9BcNgSllSrPA1kBL7ztb41SdTe1vC9w7Ln80= MIME-Version: 1.0 Sender: jianzhou.zh@gmail.com Received: by 10.101.27.34 with SMTP id e34mr6044436anj.129.1267449796756; Mon, 01 Mar 2010 05:23:16 -0800 (PST) In-Reply-To: <201003010722.15601.monnier.florent@gmail.com> References: <9dfe358d1002281955k4cb9207bi4afe5d649fc20e05@mail.gmail.com> <201003010722.15601.monnier.florent@gmail.com> Date: Mon, 1 Mar 2010 08:23:16 -0500 X-Google-Sender-Auth: ca30725783c6f697 Message-ID: <9dfe358d1003010523x158ba5f4u61999fde49ff7719@mail.gmail.com> Subject: Re: [Caml-list] How to pass C pointers to Caml From: Jianzhou Zhao To: Florent Monnier Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; pointers:01 ocaml:01 pointers:01 ocaml:01 pointer:01 pointer:01 struct:01 beginner's:01 bug:01 zhao:98 zhao:98 beginners:01 wrote:01 abstract:01 upenn:01 On Mon, Mar 1, 2010 at 1:22 AM, Florent Monnier wrote: > 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. >> >> 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 typ= e > called "t" here, and it is provided back to C with print_t / dump_ptr. Thanks. This tutorial helps a lot when calling C from OCaml. What I was doing is more like calling OCaml from C, at section http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_mlfrom= c. Because my main program is C. In this case, does OCaml have any restriction when passing a C pointer (which points to a struct) to OCaml runtme in this direction? Jianzhou > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --=20 Jianzhou