From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 5653D800B6 for ; Tue, 3 Jan 2017 14:00:01 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=ilitzroth@gmail.com; spf=Pass smtp.mailfrom=ilitzroth@gmail.com; spf=None smtp.helo=postmaster@mail-it0-f68.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of ilitzroth@gmail.com) identity=pra; client-ip=209.85.214.68; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of ilitzroth@gmail.com designates 209.85.214.68 as permitted sender) identity=mailfrom; client-ip=209.85.214.68; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="ilitzroth@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-it0-f68.google.com) identity=helo; client-ip=209.85.214.68; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ilitzroth@gmail.com"; x-sender="postmaster@mail-it0-f68.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3ASg459B8qVFILTv9uRHKM819IXTAuvvDOBiVQ1KB9?= =?us-ascii?q?1+0cTK2v8tzYMVDF4r011RmSDNmdsqkP17ae8/i5HzdfsdDZ6DFKWacPfiFGoP?= =?us-ascii?q?1epxYnDs+BBB+zB9/RRAt+Iv5/UkR49WqwK0lfFZW2TVTTpnqv8WxaQU2nZkJd?= =?us-ascii?q?b974EY/Kjsmxy/v6u9iKO10J1wyGfKhqIR6qgQLUv8gQycs+e+digifO91VBcf?= =?us-ascii?q?5Xzm4gAV/bsRvn/c624NY33S1aofMq+ohkXJL0cr8jRLpEJDUgKWE8osPx40rt?= =?us-ascii?q?VwyKs3oZV2wQjxdMSwzE8APgWYvx+n/7suthyjOdIc3eQrU9WDDk5KBuHky7wB?= =?us-ascii?q?wbPiI0pTmEwvd7i7hW9Vf8/hE=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A9AACzn2tYbETWVdFdGwEBAQMBAQEJA?= =?us-ascii?q?QEBFwEBBAEBCgEBgwwBAQEBAR9fgQwHhCudaoI0jToFhSiCCCqEHoFaAoFaB0E?= =?us-ascii?q?SAQEBAQEBAQEBAQESCwsLBx8wgjMEARUFghYBAQEDASMEGQEbEgsBAwELBgULD?= =?us-ascii?q?Q0dAgIhAQERAQUBChIGExKIQgEDEAgOojw/jAKBaxgFARyDCQWDUAoZJwMKVII?= =?us-ascii?q?1AQEBAQEBBAEBAQEBAQEZAgYShjOEYYJOgiWCV4JdBYcRDJMrNYZUgT+FMoN5g?= =?us-ascii?q?XVRhDeJWIlzhwQUHoEUDxYBggkSgxkpggo9NIZvgU8BAQE?= X-IPAS-Result: =?us-ascii?q?A0A9AACzn2tYbETWVdFdGwEBAQMBAQEJAQEBFwEBBAEBCgE?= =?us-ascii?q?BgwwBAQEBAR9fgQwHhCudaoI0jToFhSiCCCqEHoFaAoFaB0ESAQEBAQEBAQEBA?= =?us-ascii?q?QESCwsLBx8wgjMEARUFghYBAQEDASMEGQEbEgsBAwELBgULDQ0dAgIhAQERAQU?= =?us-ascii?q?BChIGExKIQgEDEAgOojw/jAKBaxgFARyDCQWDUAoZJwMKVII1AQEBAQEBBAEBA?= =?us-ascii?q?QEBAQEZAgYShjOEYYJOgiWCV4JdBYcRDJMrNYZUgT+FMoN5gXVRhDeJWIlzhwQ?= =?us-ascii?q?UHoEUDxYBggkSgxkpggo9NIZvgU8BAQE?= X-IronPort-AV: E=Sophos;i="5.33,451,1477954800"; d="scan'208,217";a="252668263" Received: from mail-it0-f68.google.com ([209.85.214.68]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Jan 2017 13:59:59 +0100 Received: by mail-it0-f68.google.com with SMTP id n68so50632030itn.3; Tue, 03 Jan 2017 05:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HWEHRnUNp6dgwfJ4PyGeGrLNnyc3zmqkEzhbtsQ7Ks0=; b=ccrzWJsgC/E0iLzNh5UuhkVFztgJt4lR3aVh7FypUf5aR3IWejDdGUr2Z9EV5UWz0i IfmZg57xY3O0/kHawz0D6kXstzY9TeQ17kWRPDqZ8FzCMiShPB7qqvZWbjYpr0oQJK1m pjKIxI4VezgPxCsvxftG5qMyPqL9fnmcglg02BhJZZWd2AECY62zIu2wTI0t7vdp/Yd9 6OvhFYih97dpbVYjF3ocJhC87vf2O8QjFOP81a2q+X5S9wlpCmiNNHXeu9viLxliQdnH PWoI0XF+tYmSRTlp5kZUOp6wfJQp13BMnVpSzKMshWJdrs1ce/QuQZ1ibjV76AFlzob+ ZpfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HWEHRnUNp6dgwfJ4PyGeGrLNnyc3zmqkEzhbtsQ7Ks0=; b=PbhF+p1iGLI/u3bS7a7bHGifQFC3z77ZFmYOEpd4vqV1NXargbFuRI53ByI0yNLnko BD4pNgPp8fsW6XKgFXnmgmj31hdCplASQW/mWq/DOPG2sg5I2bttqwutJFgLVZu+g6JF UeJN8PMXn9Pv9iVCMHYHvhWRXfbNvkUnOQd+TS1UYr4qcdFfHot2osJDtB+9/ukBg6g0 asTCUEPkUhE2lhPk1PD/frQizRgehnCgSkUHZ6xcOHyJI7AfsOaO4Aqj9xtBiX33kWkn WxVyF7AkDcH0o+AZAy3VRo5DSLtatnPg+og5/lBPEb6W9QeHS/HToagocT3Oo1jCCDyP 9weA== X-Gm-Message-State: AIkVDXIL7UzeHtOlfcqJHq3HWH0q8RrhMa8wLh9w/Sfhq4PlPB9+LdDvIEWJXy2bleCGX8GH6zdEyVSOmhUgAw== X-Received: by 10.36.200.10 with SMTP id w10mr47084599itf.21.1483448398675; Tue, 03 Jan 2017 04:59:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.184.85 with HTTP; Tue, 3 Jan 2017 04:59:38 -0800 (PST) In-Reply-To: References: <7033084.csZPQNGq1J@twitter> From: immanuel litzroth Date: Tue, 3 Jan 2017 13:59:38 +0100 Message-ID: To: Fabrice Le Fessant Cc: Chet Murthy , Caml List Content-Type: multipart/alternative; boundary=94eb2c057e92d882400545303e04 Subject: Re: [Caml-list] C++ for Ocaml FFI bindings --94eb2c057e92d882400545303e04 Content-Type: text/plain; charset=UTF-8 It is possible to write generic C++ for mapping any C++ class as a new type in ocaml by wrapping it in a shared_ptr or unique_ptr, in such a way that the object can be kept alive by the c++ side or by the ocaml side. There is some code on the net that explores that idea here: https://github.com/ygrek/scraps/blob/master/cxx_wrapped.h but that seems to be using the older auto_ptr at the moment. The code I have written for this is proprietary. Immanuel On Tue, Jan 3, 2017 at 11:34 AM, Fabrice Le Fessant < Fabrice.Le_fessant@inria.fr> wrote: > Hi Chet, > > I wrote a very basic tool to generate OCaml bindings for the WxWidgets > C++ library (https://github.com/OCamlPro/ocplib-wxOCaml), and then a very > different one for LLDB (https://github.com/OCamlPro/typerex-lldb). In > both cases, methods of C++ class A are mapped to functions of OCaml module > A. The main difference is that WxWidgets makes heavy use of inheritance, > while LLDB does not use it at all. Consequently, there are many "cast" > functions in WxOCaml, while there are none for LLDB. Also, LLDB is very > strict on the syntax of its include files, which makes it very easy to > parse them directly from OCaml (there is no need for a DSL), whereas for > WxWidgets, I had to copy and slightly modify the C++ method definitions > into a subset (the DSL) that could be used from OCaml. > > So, in your bindings, which OCaml type do you target for a C++ class ? > Also, is there some support for garbage collection ? How do you detect that > a C++ object is removed, so that the corresponding OCaml object can be > removed ? Is it generalizable to any C++ framework ? > > Cheers, > --Fabrice > > > > On Tue, Jan 3, 2017 at 6:55 AM Chet Murthy wrote: > >> Hi, I've been watching the discussions over the years regarding FFI >> bindings from Ocaml. I've built a ton of such bindings using Camlidl. >> I've used some done using Ctypes. And it's always hard. But >> recently, I've come to the conclusion that bindings against C++ would >> be (shockingly, yes I know) -easier- than against C. >> >> To demonstrate this, and because I had need of it, I've writte a >> little IDL compiler, along with an example FFI wrappering of the C++ >> Rocksdb API. Only as an example. The code is raw, and really >> .... raw. But it works, works well, and is dreamily easy to add new >> entry-points to. I'm hoping that over the next few weeks, as I use >> this, I'll add tests, more examples, and documentation. >> >> --> oboy, does it need documentation (if anybody but me is -ever- >> gonna use it) >> >> Right now though, I just thought I'd send this note, to try to raise >> the subject that .... >> >> Maybe C++ is a ripe target for FFIs from Ocaml? >> >> I've released the code (such as it is) on Github: >> >> https://github.com/chetmurthy/ocaml-cppffigen >> >> https://github.com/chetmurthy/ocaml-rocksdb >> >> Please don't take this as an advertisement for the code. But do take >> it as an advertisement for the -idea-. >> >> Cheers, >> --chet-- >> >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > --94eb2c057e92d882400545303e04 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
It is possible to write generic C++ for mapping any C++ cl= ass as
a new type in ocaml by wrapping it in a shared_ptr or unique_ptr= ,
in such a way that the object can be kept alive by the c++ side= or
by the ocaml side. There is some code on the net that explore= s that
idea here:
but that seems to be using the older auto= _ptr at the moment. The=C2=A0
code I have written for this is pro= prietary.
Immanuel

On Tue, Jan 3, 2017 at 11:34 AM, Fabrice Le Fessant = <Fabrice.Le_fessant@inria.fr> wrote:
Hi Chet,

=C2=A0 = =C2=A0I wrote a very basic tool to generate OCaml bindings for the WxWidget= s C++ library (https://github.com/OCamlPro/ocplib-wxOCaml), and then= a very different one for LLDB (https://github.com/OCamlPro/typerex-lldb). In both cases, methods of C++ class A are mapped to functions of OCaml= module A. The main difference is that WxWidgets makes heavy use of inherit= ance, while LLDB does not use it at all. Consequently, there are many "= ;cast" functions in WxOCaml, while there are none for LLDB. Also, LLDB= is very strict on the syntax of its include files, which makes it very eas= y to parse them directly from OCaml (there is no need for a DSL), whereas f= or WxWidgets, I had to copy and slightly modify the C++ method definitions = into a subset (the DSL) that could be used from OCaml.

=
=C2=A0 So, in your bindings, which OCaml type do you target for a C++ = class ? Also, is there some support for garbage collection ? How do you det= ect that a C++ object is removed, so that the corresponding OCaml object ca= n be removed ? Is it generalizable to any C++ framework ?

Cheers,
--Fabrice



Hi, I've been watching = the discussions over the years regarding FFI
bindings from Ocaml.=C2=A0 I've built a ton of such bindings using Caml= idl.
I've used some done using Ctypes.=C2=A0 And it's always hard.=C2=A0= But
recently, I've come to the conclusion that bindings against C++ would be (shockingly, yes I know) -easier- than against C.

To demonstrate this, and because I had need of it, I've writte a
little IDL compiler, along with an example FFI wrappering of the C++
Rocksdb API.=C2=A0 Only as an example.=C2=A0 The code is raw, and really .... raw.=C2=A0 But it works, works well, and is dreamily easy to add new entry-points to.=C2=A0 I'm hoping that over the next few weeks, as I us= e
this, I'll add tests, more examples, and documentation.

=C2=A0 --> oboy, does it need documentation (if anybody but me is -ever-=
=C2=A0 =C2=A0 =C2=A0 gonna use it)

Right now though, I just thought I'd send this note, to try to raise the subject that ....

=C2=A0 Maybe C++ is a ripe target for FFIs from Ocaml?

I've released the code (such as it is) on Github:

https://githu= b.com/chetmurthy/ocaml-cppffigen

https://github.= com/chetmurthy/ocaml-rocksdb

Please don't take this as an advertisement for the code.=C2=A0 But do t= ake
it as an advertisement for the -idea-.

Cheers,
--chet--


--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.in= ria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml= .inria.fr/bin/caml-bugs

--94eb2c057e92d882400545303e04--