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 6E0AA7FB82 for ; Mon, 29 Feb 2016 09:41:35 +0100 (CET) IronPort-PHdr: 9a23:n8X6vRBqJ7MRhCM1U+6RUyQJP3N1i/DPJgcQr6AfoPdwSP78ocbcNUDSrc9gkEXOFd2CrakU1KyI7Ou5ADJIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/niKbspNaKOlsArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIZoGJ/3dKUgTLFeEC9ucyVsvJWq5lH/Sl6q738XVWET2j9BHwHB7xiyCpL0uzfzsul08CafNMzyC7szXGLxwb1sTUrKhT0KMi9xwWjTjstoxPZKqRaloARXzIvdYYXTP/17KPCONegGTHZMC54CHxdKBZmxOs5WV7IM Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=yallop@gmail.com; spf=Pass smtp.mailfrom=yallop@gmail.com; spf=None smtp.helo=postmaster@mail-qg0-f51.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.192.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yallop@gmail.com designates 209.85.192.51 as permitted sender) identity=mailfrom; client-ip=209.85.192.51; receiver=mail2-smtp-roc.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 (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qg0-f51.google.com) identity=helo; client-ip=209.85.192.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-qg0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BUAACsA9RWlTPAVdFehAxeDwa6bYFmI4VwAoEkBzoSAQEBAQEBAQEQAQEBAQcLCwkhL4ItghQBAQEDARIRHQEbHQEDAQsGBQsDCgICJgICIQEBEQEFARwGEwgah2cBAwoIDqIogTE+MYs0gWmCV4RnChknDVGDbAEBAQEBBQEBAQEBFQEBBAoEbYhUfYI6gWWDFoE6AQSXDIVZhhWBdI50hwaGBhEegQ8nAoIvChQIgUg8LocJgToBAQE X-IPAS-Result: A0BUAACsA9RWlTPAVdFehAxeDwa6bYFmI4VwAoEkBzoSAQEBAQEBAQEQAQEBAQcLCwkhL4ItghQBAQEDARIRHQEbHQEDAQsGBQsDCgICJgICIQEBEQEFARwGEwgah2cBAwoIDqIogTE+MYs0gWmCV4RnChknDVGDbAEBAQEBBQEBAQEBFQEBBAoEbYhUfYI6gWWDFoE6AQSXDIVZhhWBdI50hwaGBhEegQ8nAoIvChQIgUg8LocJgToBAQE X-IronPort-AV: E=Sophos;i="5.22,520,1449529200"; d="scan'208";a="205005445" Received: from mail-qg0-f51.google.com ([209.85.192.51]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Feb 2016 09:41:34 +0100 Received: by mail-qg0-f51.google.com with SMTP id b67so110217534qgb.1 for ; Mon, 29 Feb 2016 00:41:34 -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; bh=6WvxIx+Ip36bWoV8AC/3kFoKhnp7pKnWTZ9aNmNWzZY=; b=ERv8HZGWPDV5mHxdReLld19AjZrCkYaU2RtIJ7/jzKgVTODx5NvggdsyYEPxy4nvnS qBXZri/1x48QBoyzHCUj5/OL5BlZMY0IUrAdaBnGyCwwLENXla3ypNls7mvMKrS0US1H kOQz7aX+dhnG5WmF4I5bX8y9PJ35TY+aKXrKuIPCSRRmbIoN7it192n3O4DA3k6bHZKR 8xGRoxICCUfhNQWr7H/a7CPx1qg2UeauyoZTWWoQQDNwmhcIBnAKnF/oPsutCtG61PG8 G/msJJ5XXdSPYSdDY4MsOg8n8giFaJIHgqE61lak1nIETxxkRUC8Ffo/gUetOdfKMfLO HuzQ== 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; bh=6WvxIx+Ip36bWoV8AC/3kFoKhnp7pKnWTZ9aNmNWzZY=; b=Lo1EiCrAWEM67uoj8KUiBkMSo0RVo+Acg3lCCSU/ISTu7jhRL41esokFSiYqNq/deE 7wZRlVNPHB810uoaBkxExjzMpy9ii74jBfnUnTuz11ZsCGD2zA6AReAFLUg0Qfn48q4q xy07h1M9NyTXxWekqUfcUj5YMPvhic3pqugaRi9V52dqDcP//oGEmLC9ioNquvm+T+km vBYRX948/cppq4G38b05PjubU/YR7Hs+70JB+ZjbXsFKKyFYza++K4A9F6GrRbxYqdKQ WHRqgu8IYB5ZmkbbWmAmzBKeYxxjvr01Xy4fqP0te6wREVUEKHjIn/nQ88O+C/oqNuJO xUxg== X-Gm-Message-State: AD7BkJJ+HHktf8BrDkSyevLyHx1c+xwbCQzsi70OZ4gw47UjF4iEJE8Y9NcSQCTYT9ZNiQwVdiVXMImn5TozBQ== MIME-Version: 1.0 X-Received: by 10.140.175.136 with SMTP id v130mr18662179qhv.74.1456735293713; Mon, 29 Feb 2016 00:41:33 -0800 (PST) Received: by 10.55.157.74 with HTTP; Mon, 29 Feb 2016 00:41:33 -0800 (PST) In-Reply-To: <86oab0hcjq.fsf@gmail.com> References: <86oab0hcjq.fsf@gmail.com> Date: Mon, 29 Feb 2016 08:41:33 +0000 Message-ID: From: Jeremy Yallop To: Malcolm Matalka Cc: Caml List , ctypes Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] ctypes - to string or to bigarray? On 28 February 2016 at 19:15, Malcolm Matalka wrote: > I'm writing bindings for a library that is just doing I/O and wondering > what the suggested best practice is around using string or bigarray. It > seems like using Bigarray is probably the most versatile interface. > People can decide to do the copying themselves or just use Bigarray > everywhere. Yes, Bigarray is the more versatile choice, and probably the better default. > Are there any other things to consider? Suggestions? Since ctypes bindings are just OCaml programs, one possibility is to abstract over the choice of storage. David Sheets's libsodium bindings are a good example of this approach; for example, here's a functor which builds bindings for half a dozen functions based on an abstract "Sodium_storage.S" signature: https://github.com/dsheets/ocaml-sodium/blob/95d26a85/lib_gen/sodium_bindings.ml#L64-L76 Elsewhere in the library are implementations of Sodium_storage.S for Bigarray and for Bytes: https://github.com/dsheets/ocaml-sodium/blob/95d26a85/lib/sodium_storage.ml One pleasant aspect of this approach is that the abstraction over storage type doesn't cause any loss of type safety. You can use all the typed abstraction facilities of OCaml to construct your binding descriptions, and the generated C code is checked against the headers for the bound library by the C compiler.