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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 830357FD8E for ; Thu, 4 Feb 2016 20:29:23 +0100 (CET) IronPort-PHdr: 9a23:xOTdpBE60bJMHtT+PxXW4p1GYnF86YWxBRYc798ds5kLTJ75oMqwAkXT6L1XgUPTWs2DsrQf27WQ6firADZYqb+681k8M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLsh7/0ocWYOl8QzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRuJN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IeezAcq85Vb1VCig9eyBwvZWz9EqLcQzaw3IYWWISl1JtChTM6BLzFsP0tyLmv+5+0QGVOMT3SfY/XjH0vIlxTxq9qiodOjsouFDejsh3lOoPsRuloxtn64HRaYCRcvF5e/WOLpshWWNdU5MJBGR6CYSmYt5KVrJZMA== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=yallop@gmail.com; spf=Pass smtp.mailfrom=yallop@gmail.com; spf=None smtp.helo=postmaster@mail-qk0-f178.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.220.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yallop@gmail.com designates 209.85.220.178 as permitted sender) identity=mailfrom; client-ip=209.85.220.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qk0-f178.google.com) identity=helo; client-ip=209.85.220.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-qk0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AjAgAWprNWlLLcVdFehAxeDwaIVbEPgWYjhSBKAoE4BzoSAQEBAQEBAQEQAQEBAQcLCwkfMEEOAYFdghQBAQEDARIRBBkBGx0BAwELBgULAwoCAiYCAiEBAREBBQEcBhMih2MBAwoIDqQSgTE+MYs0gWmCV4VJChknDVGDbgEBAQEBAQQBAQEBAQEUAQEECgRtiU6CNx2EXoE6BY4ZiFiFS4YRgXOOcYZ/hgURHoENJweCKh6BcRsugkiFYgEBAQ X-IPAS-Result: A0AjAgAWprNWlLLcVdFehAxeDwaIVbEPgWYjhSBKAoE4BzoSAQEBAQEBAQEQAQEBAQcLCwkfMEEOAYFdghQBAQEDARIRBBkBGx0BAwELBgULAwoCAiYCAiEBAREBBQEcBhMih2MBAwoIDqQSgTE+MYs0gWmCV4VJChknDVGDbgEBAQEBAQQBAQEBAQEUAQEECgRtiU6CNx2EXoE6BY4ZiFiFS4YRgXOOcYZ/hgURHoENJweCKh6BcRsugkiFYgEBAQ X-IronPort-AV: E=Sophos;i="5.22,396,1449529200"; d="scan'208";a="163222884" Received: from mail-qk0-f178.google.com ([209.85.220.178]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 04 Feb 2016 20:29:22 +0100 Received: by mail-qk0-f178.google.com with SMTP id x1so25364964qkc.1 for ; Thu, 04 Feb 2016 11:29:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=BGJ5wbKDEM+jQoHIj6+3m7zCM4D30pFfL6LwuJB8mS0=; b=GfSdKet6xBOZhmzm5hqvt+lNeT7BmlzU7WiqtouhQ6AGnTt4zsT5HlPQGdrFuE/sc8 /GWEEwEBzfzv9uM0ISWQVPtNN5UbChsFllX3peFqwJx2SsCII5XapBLr084KsASPRpd0 Aq2UWO4vqRa+Pkyj44C8cqChUkYiTnyY8CNoxgtcHgISFw6pGfHdatg8Xb84mos101I1 dXKBwv2l4x/np617pu+jco7dCgRs5sbF7d14kpedVfw44qpalrfgU6H78zIlrd0rSAuc pj651olAVGjmBHsgekIjj6sk1VjZFNYcFDsk3RbSo/cZdmt6RJOnTem36+KMdICacUoc /+gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=BGJ5wbKDEM+jQoHIj6+3m7zCM4D30pFfL6LwuJB8mS0=; b=NBI1oCevkJH5li9HgI1UWWW4wprTfqikfZMTDgFCGIOZ9nQc7BpCnhXKKmakPdwF12 ANkYUgDm9TVFepsV3GUulSaL2NsXOxJLFa4UCtVMBlmvyao4y3i76Yd9vH7D435TlIFP U4qQ6OTh9IRGe0mYFb6c/ms7UQzB5vZz4AYrwjRnAQ8WNup7NZu6ZFRE1VTfcALeXBiY 0teGHdW/Bn9oNiNQWbeeSsgfjngNj9ZoKUcUPOhWENh+gQYf2jKvRbZBJb3775nVxfhb UVFPkHklYFtvMaMfqv+Zn7/M91JANjdF4tZqHWtZr7ldHK/h85WRLWC5qLEkqje2BPf0 T27g== X-Gm-Message-State: AG10YORfO97Ww4tuFQa0/TankeKiOaTSOdHcTuONAiIM5sNv3nJyr+LQmTznss4yh7yDvp+XDKwFBhLIZdjFdw== MIME-Version: 1.0 X-Received: by 10.55.212.156 with SMTP id s28mr4643435qks.55.1454614161226; Thu, 04 Feb 2016 11:29:21 -0800 (PST) Received: by 10.55.201.68 with HTTP; Thu, 4 Feb 2016 11:29:20 -0800 (PST) In-Reply-To: <86io25q6lt.fsf@gmail.com> References: <56B1DC54.1060109@tu-berlin.de> <86r3guq8t4.fsf@gmail.com> <86mvrhr1o1.fsf@gmail.com> <86io25q6lt.fsf@gmail.com> Date: Thu, 4 Feb 2016 11:29:20 -0800 Message-ID: From: Jeremy Yallop To: Malcolm Matalka Cc: David Sheets , Jeremie Dimino , =?UTF-8?Q?Christoph_H=C3=B6ger?= , caml users Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Save callbacks from OCaml to C On 3 February 2016 at 23:26, Malcolm Matalka wrote: > Jeremy Yallop writes: >> Storing the functions in a table, and removing them automatically >> after they're called is one approach. An alternative is to use the >> new Ctypes.Roots module, which will be available in the next release: >> >> https://github.com/ocamllabs/ocaml-ctypes/blob/182a9e64src/ctypes/ctypes.mli#L419-L435 > > Thank you for the thorough response. It seems like Ctypes.Roots might > solve my problem, although the URL gives me a 404. Oops. Here's a working URL: https://github.com/ocamllabs/ocaml-ctypes/blob/182a9e64/src/ctypes/ctypes.mli#L419-L434 > Do you have an estimation of when this will be released (or anything someone like > myself can do to help?) There are a few issues left to address before the next release: https://github.com/ocamllabs/ocaml-ctypes/milestones/ctypes%200.5 Thanks for the offer of help! Feedback on the Ctypes.Roots design would be appreciated. More generally, some of the outstanding issues might be fixable by a motivated beginner, e.g. https://github.com/ocamllabs/ocaml-ctypes/issues/316 https://github.com/ocamllabs/ocaml-ctypes/issues/267 https://github.com/ocamllabs/ocaml-ctypes/issues/106 > What kind of sucks about that is the wrapper needs to be unique to each > type of closure that gets called, there doesn't seem like a really > generic way to do this wrapping. Am I on the wrong track? If you're only storing the closures in the table, and don't need to retrieve and call them, then you can use a type which hides the type of the closure in some way. One approach is to use Obj.t, and convert each closure using Obj.repr as you store it. If using Obj makes you uneasy (as it generally ought to, although it's currently safe in this case) then an alternative is to use an existential type, like this: type t = T : _ -> t which allows you to wrap any type of value, regardless of its type: # [T (+); T not; T 3; T ""];; - : t list = [T ; T ; T ; T ]