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 0289C800B7 for ; Tue, 3 Jan 2017 11:34:29 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=Fabrice.Le_fessant@inria.fr; spf=Pass smtp.mailfrom=fabrissimo@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 Fabrice.Le_fessant@inria.fr) identity=pra; client-ip=209.85.214.68; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="fabrissimo@gmail.com"; x-sender="Fabrice.Le_fessant@inria.fr"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of fabrissimo@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="fabrissimo@gmail.com"; x-sender="fabrissimo@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="fabrissimo@gmail.com"; x-sender="postmaster@mail-it0-f68.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AoxnY2hId4eU+/55v7NmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgULfnxwZ3uMQTl6Ol3ixeRBMOAuq4C0rGd6vyoGTRZp83e4DZaKN0EfiRGoP?= =?us-ascii?q?tVtjRoONSCB0z/IayiRA0BN+MGamVY+WqmO1NeAsf0ag6aiHSz6TkPBke3blIt?= =?us-ascii?q?dazdU7TfhMWv1u2054abI0AR3GL8MoVJMQ6uoA7Nms4TiIpkYuZtm1qa6kdPLs?= =?us-ascii?q?9WyH8gAE+JgxbtrpO14YR/8zUWsPIs6+ZPVKz7e+IzSrkOSHwNOmUxrOnqrgWL?= =?us-ascii?q?GQCG439ZVmQNjjJJBRLE5Vf0RMGinDH9s79T0SOAPMb7BZQ5ERqv9LxiTgOg3A?= =?us-ascii?q?kOPSQ4+2yRrsFHgq9AuxunuzR+xZTVacebLqwtLevmYdoGSD8ZDY5qXCtbD9b5?= =?us-ascii?q?MtIC?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0ABBAByfWtYbETWVdFdHQYMGQYMgw0BA?= =?us-ascii?q?QEBAR8hLw+BDKIcgjSFR4dzBYUogjKHWUATAQEBAQEBAQEBAQESCwsLBx8wgjM?= =?us-ascii?q?EARUFghcBBAEjBEcQCwsLGh0CAiEBEgEFAQoSBgESEohDAxAIDqJJP4wCgWs6h?= =?us-ascii?q?ygDCoMVJhKLFIJOhHyCXQWHEQyTKzVmhW6BP4Uyg3mBdVGEN4lYiXOHBDKBFA8?= =?us-ascii?q?SAoIMEgOFSD40hm+BTwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0ABBAByfWtYbETWVdFdHQYMGQYMgw0BAQEBAR8hLw+BDKI?= =?us-ascii?q?cgjSFR4dzBYUogjKHWUATAQEBAQEBAQEBAQESCwsLBx8wgjMEARUFghcBBAEjB?= =?us-ascii?q?EcQCwsLGh0CAiEBEgEFAQoSBgESEohDAxAIDqJJP4wCgWs6hygDCoMVJhKLFIJ?= =?us-ascii?q?OhHyCXQWHEQyTKzVmhW6BP4Uyg3mBdVGEN4lYiXOHBDKBFA8SAoIMEgOFSD40h?= =?us-ascii?q?m+BTwEBAQ?= X-IronPort-AV: E=Sophos;i="5.33,451,1477954800"; d="scan'208,217";a="252645730" 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 11:34:28 +0100 Received: by mail-it0-f68.google.com with SMTP id n68so50311266itn.3 for ; Tue, 03 Jan 2017 02:34:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=2F4dZ2gU/C0Ta44/38JvGUDG2KwTO1kztSYoR6SOddE=; b=n4v4DhKYOczpPnW6jB3yVzCgNKyIlwaqiMim8h87mK74Hj3HkMhxggWxFnGdf6X2ZI QmwJB774p1GmbVbsFIJHc2LAkNWrQuhSGaMK16XgOD+VA9++DUGxfh2VfJQMJ0t68VpK y4oQATzE16Q8V6rejYFYTkOkpv28sPouT43kPhiB41gMx7EzD7Om5fz6KZzGvh0dkFNX KP9qDSBxmoARd4a9VR3MHlqI4IVwMALDdlMTgS31LjiMiKyedqVfX73QPjasHZmMOQOu hSdfwXGp60qcGPsBrZfd1C72ard9TsMZEx5LvEmRSdrt6Ct0XS1LYnBA1DvwaKcSDgTq 8NFA== X-Gm-Message-State: AIkVDXLbWoIOqtgR/D/2rCYZfEFAf5d7P+Pbbqb+NBtrQVMdiHnerlZi0c6D/evVU58Q/N/v2K7nQSmSoPf34g== X-Received: by 10.36.11.65 with SMTP id 62mr49597907itd.118.1483439666675; Tue, 03 Jan 2017 02:34:26 -0800 (PST) MIME-Version: 1.0 References: <7033084.csZPQNGq1J@twitter> In-Reply-To: <7033084.csZPQNGq1J@twitter> From: Fabrice Le Fessant Date: Tue, 03 Jan 2017 10:34:16 +0000 Message-ID: To: Chet Murthy , Caml List Content-Type: multipart/alternative; boundary=001a1140b38260c7eb05452e3639 Subject: Re: [Caml-list] C++ for Ocaml FFI bindings --001a1140b38260c7eb05452e3639 Content-Type: text/plain; charset=UTF-8 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 > --001a1140b38260c7eb05452e3639 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Chet,

=C2=A0 =C2=A0I wrote a very ba= sic 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 o= f 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 man= y "cast" functions in WxOCaml, while there are none for LLDB. Als= o, LLDB is very strict on the syntax of its include files, which makes it v= ery easy to parse them directly from OCaml (there is no need for a DSL), wh= ereas for WxWidgets, I had to copy and slightly modify the C++ method defin= itions 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 detect that a C++ object is removed, so that the corresponding OCaml ob= ject can be removed ? Is it generalizable to any C++ framework ?
=
Cheers,
--Fabrice



On Tue, Jan 3, 201= 7 at 6:55 AM Chet Murthy <murth= y.chet@gmail.com> wrote:
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://github.com/chetmurthy/ocaml= -cppffigen

https://github.com/chetmurthy/ocaml-r= ocksdb

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.inria.fr/sympa/arc/caml-= list
Beginner's list: http://groups.= yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bug= s
--001a1140b38260c7eb05452e3639--