From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 7A9897EEF8 for ; Tue, 28 Jul 2015 20:40:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of goswin-v-b@web.de designates 212.227.17.12 as permitted sender) identity=mailfrom; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; 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@mout.web.de) identity=helo; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AcAQAWzLdVnAwR49RbymRMAQEBAQEBEgEBAQEBBg0JCSEuhFETezQFKCGIKwEZqlufdB+GE4pMiSiBFAWHFo1SjECBR4Z+DIx6g2KBcAw4HIFVgzkBAQE X-IPAS-Result: A0AcAQAWzLdVnAwR49RbymRMAQEBAQEBEgEBAQEBBg0JCSEuhFETezQFKCGIKwEZqlufdB+GE4pMiSiBFAWHFo1SjECBR4Z+DIx6g2KBcAw4HIFVgzkBAQE X-IronPort-AV: E=Sophos;i="5.15,564,1432591200"; d="scan'208";a="171928572" Received: from mout.web.de ([212.227.17.12]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Jul 2015 20:40:45 +0200 Received: from frosties.localnet ([95.208.221.151]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0LzsGF-1YoNln0SAN-0155I4 for ; Tue, 28 Jul 2015 20:40:44 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.84) (envelope-from ) id 1ZK9nv-0007Sb-6h for caml-list@inria.fr; Tue, 28 Jul 2015 20:40:43 +0200 Date: Tue, 28 Jul 2015 20:40:42 +0200 From: Goswin von Brederlow To: OCaml Mailing List Message-ID: <20150728184042.GA28321@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:vyq01LqtG9nTixM1Ei3ZJK9DhvtEO08ViDnJWzf+uIwrYiTKLpB d3RSB/xYgSuUhlKLOCwF5q9shsTRhnyG0C46XrPYTO7EfilBozXW26XPeZ3JNJF7ubZ3tty Ue8nbpZvqZF8rFsoJ4AXR/Q/5HqEoooyLZ40WHJHa4pkVfWbxfjXudziBVbz+OqUoogvCZz DTEQYq6YISGlQ37JDyxBA== X-UI-Out-Filterresults: notjunk:1;V01:K0:1UXF0un/LY4=:0uaX2++G9G46ail/Gq8rcE K7AdkFwVY5Qz8KqF0kVuHcgoS6NXMIZhHiw//FrDz0YH495Cx9kw9vdW3wXUsQMO1oVpnlV5g XL5PodITZM2YxXHFwiLJNW3Xh5so7O0UxY9jsmdP7K9s3TX+/pIFNQjplY63+Np3ZyGv4Jp3f jV7gzAY0G/jQnHWsK498/3g/Hb22GDviS9cT0IVOOfp5lKEkP+nblQevvY3eCMUW6AYl/1LhS 6Mem5UV9Yy1elIy3iyD08Li5DxaGgGJmvIksBHB6cpKCgJY6MbFtl8tlF2JPMely2C6U6OnGT Z55Krw75Tty6qZTYOdKSfV3xr1dqKOpFbBZXEiCPrUlZFCcy/QjmBtSnZPILupGf2VGJ7ox+7 pas5AMJfXB0uEukg0serOkwA6Zxg87xqQk7kb9Imybx1KuiFTxQMIPtsJsivcCZ9y+8sAKhzr XKyLZMbCm2VtTBjI+wz+eEIdmQTF/dp94yAjNGwAt0PEUqJeFe0VSzL6jP1IM/kbmeBPrzJQf lc3jfcGiCs8Bf9lCS3GfiUFKsaFvp+jIKpyX2H5RYCixi9vY3kSqbRNiXaRujkQRgNrD28mXo gPeTZ1WDBXtkIr5GpRTytmRVaF+CQwEOO5BGO7lYrdpduRxI35yNi/V4ylw509LQLWMABAGx7 QG2lRVq9aaKhPT+Osy0igjXH+tTJINFKqZ3X1iKxpv2fW/g== Subject: [Caml-list] What's the best practice for bindings for c++ templates? Hi, I'm halfway done writing a c++ library for a network protocol and considering writing some bindings for ocaml. The library uses templates to make objects customizable and am wondering what the best practice is there. For a simple example say I have the following: ---------------------------------------------------------------------- template class Foo { public: Foo(T t); ~Foo(); T swap(T t); T get(); }; ---------------------------------------------------------------------- type 'a t val make : 'a -> 'a t val swap : 'a t -> 'a -> 'a val get : 'a t -> 'a ---------------------------------------------------------------------- 1) For the stub code I need to instantiate the template with 'a, which obviously doesn't work since the C++ stub has no idea about what type ocaml will use in the future. So do I instantiate it with void *? uintptr_t? value? 2) I'm storing ocaml values in C++ structures and getting them back. How do I make that play nice with the GC? 3) I have the option of changing the libraries API as it's not set in stone yet. What would be beneficial to interfacing with ocaml (and maybe python) without making the c++ API to horrible? E.g. Foo could have: void set_T_destructor(void (*destructor)(T *t)); Then ~Foo() would call 'destructor(&t)' to "free" the stored T, which would unregister it from the GC. Does that make sense? Is it a bad idea? Would it be better to add a second template parameter for an Allocator class that handles interfacing with the GC in the stubs? Any other little tricks to add to the c++ library to make writing bindings and working with GCs easier? What's your experience there? MfG Goswin