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 2A92F7F0BD for ; Sun, 25 Sep 2016 10:43:23 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=edgar.factorial@gmail.com; spf=Pass smtp.mailfrom=edgar.factorial@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f66.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of edgar.factorial@gmail.com) identity=pra; client-ip=74.125.82.66; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edgar.factorial@gmail.com"; x-sender="edgar.factorial@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of edgar.factorial@gmail.com designates 74.125.82.66 as permitted sender) identity=mailfrom; client-ip=74.125.82.66; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edgar.factorial@gmail.com"; x-sender="edgar.factorial@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-wm0-f66.google.com) identity=helo; client-ip=74.125.82.66; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edgar.factorial@gmail.com"; x-sender="postmaster@mail-wm0-f66.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AuPBkbhAGqJHoXs63oJu9UyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP3ypcbcNUDSrc9gkEXOFd2CrakV0ayP6uu6CCRAuc/H6y9SNsQUFlcsso?= =?us-ascii?q?Y/oU8JOIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0Iu?= =?us-ascii?q?frymUt2as8Pi++ms+pGbSgFMnz2lefsmIA+/6APcqdI+hIZ+I70twxDK5HBPfr?= =?us-ascii?q?IF63lvIAe+kxn1/I+ZtMpu/ytZobQv/sVcVr/7dqAQQrlRDTBgOGcwsp64/SLf?= =?us-ascii?q?RBeCsyNPGl4dlQBFVlDI?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CSAADtjedXf0JSfUpdHAEBBAEBCgEBG?= =?us-ascii?q?AEFAQsBgxABAQEBAXUtT40zn3CLXYIEGQ+FdgKBODgUAQEBAQEBAQEBAQESAQE?= =?us-ascii?q?JCwsJFzGCMhiCGAEBBAECDxEdARsdAQMMBgULAwoCAiYCAiMRAQUBHAYTGgiID?= =?us-ascii?q?gEDFwQKow+BMj4yiz2Ba4JfBYNaChknDVOCbwEBAQEBAQEBAQEBAQEBAQEBAQE?= =?us-ascii?q?BARQCBhB2hy2CWIREgwQrgi8FjyuKS4YniUGBbk6EFoMGDiOFYoxrgjoxgREeg?= =?us-ascii?q?0EOHIFwUgGGawEBAQ?= X-IPAS-Result: =?us-ascii?q?A0CSAADtjedXf0JSfUpdHAEBBAEBCgEBGAEFAQsBgxABAQE?= =?us-ascii?q?BAXUtT40zn3CLXYIEGQ+FdgKBODgUAQEBAQEBAQEBAQESAQEJCwsJFzGCMhiCG?= =?us-ascii?q?AEBBAECDxEdARsdAQMMBgULAwoCAiYCAiMRAQUBHAYTGgiIDgEDFwQKow+BMj4?= =?us-ascii?q?yiz2Ba4JfBYNaChknDVOCbwEBAQEBAQEBAQEBAQEBAQEBAQEBARQCBhB2hy2CW?= =?us-ascii?q?IREgwQrgi8FjyuKS4YniUGBbk6EFoMGDiOFYoxrgjoxgREeg0EOHIFwUgGGawE?= =?us-ascii?q?BAQ?= X-IronPort-AV: E=Sophos;i="5.30,392,1470693600"; d="scan'208";a="238161559" Received: from mail-wm0-f66.google.com ([74.125.82.66]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 25 Sep 2016 10:43:12 +0200 Received: by mail-wm0-f66.google.com with SMTP id b184so9337808wma.3 for ; Sun, 25 Sep 2016 01:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=oWUX/VEzVvyZhDvQ16k2mn0L/FTd7Lm4JEzeBxps4pg=; b=UqyuNBmHeR9f8R/kES0CoHBAy995oZ4742DSKXWzM/1eFcJhLVTQJXWjW54Mm19683 ZQtfIc2mS/pxuAXNwmWyrbfF7OkiUKDN4YPTR+G1pmj20ZO7CINr0sDjlxo/koEs3I5z rl5prf/SR/tPhqDScPxaaFDhN80pqnU+BPqiewM6BX4M13nxH8c+KnSeyD9ZkWMlPm2Q KYbVFuR+/KXlF96MR7LQH1JRuM0DKYEB+Zd1extQCq1Alb9sMTI9XO7dmvlZNU8yp2Q9 8B4qcdc+rTk57OjV+Jikd/EgzZW5lW+wottbgA47OLrFP6v/Nmrx+rZS9cNDvFAtj/zf wqFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=oWUX/VEzVvyZhDvQ16k2mn0L/FTd7Lm4JEzeBxps4pg=; b=ctm01wXVl/aSzRD+BPlCMZlP3dwuqlkcFKAk/XsP6ALT9HVhm/EfgsnWT4tJRa3A6L e4I7dJGvOrYVFzBYH8VKErESd9CW97RjvWXHbq6Cxj4OkXhDfQt/lrnJmQuOIL6n4ngg B2fBHnPVc/OifgqbdLGN6qoWxcTBqdNx+ft8b5JL/bNHrREXa7MXqhhVJTTwZ0rho1Vd UnsolULPsZDTNlAliplh9hjmlX+BDYo/TuC8XrJbbpBVySaIk3f4BDEqKgYQUadwJGM/ tfqr+yUWJbATszPC6BkE1phACXlB4TBqByi0RUtdHP+nJ78yGKzcl4l4J0Ts9pOetsRR 5WCg== X-Gm-Message-State: AA6/9RnoEzvWTF2Tf+Wy7BIbTI0JPqg+s7PJ4f9yRXgFJy9svtoKelJrAbMOzE7xUl9rKA== X-Received: by 10.28.196.200 with SMTP id u191mr9164855wmf.67.1474792991884; Sun, 25 Sep 2016 01:43:11 -0700 (PDT) Received: from [192.168.6.89] ([37.157.215.95]) by smtp.gmail.com with ESMTPSA id jn7sm16067739wjb.5.2016.09.25.01.43.11 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Sep 2016 01:43:11 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) From: Edgar A In-Reply-To: Date: Sun, 25 Sep 2016 01:43:09 -0700 Cc: "caml-list@inria.fr" Content-Transfer-Encoding: quoted-printable Message-Id: References: <090F68D4-7CA4-4091-BC5D-5F2C9BFB2AEC@gmail.com> To: David Allsopp X-Mailer: Apple Mail (2.3124) X-Validation-by: edgar.factorial@gmail.com Subject: Re: [Caml-list] Getting some C values over to the OCaml side correctly Thank you! Yes, did read through the manual but I was concerned about the u= nsigned part, does that not matter?=20 > On Sep 25, 2016, at 1:40 AM, David Allsopp wrote: >=20 > Edgar A wrote: >> Greetings, >>=20 >> I have some C values that I want to get over to the OCaml side using the >> FFI. >>=20 >> Specifically I have `uint32_t`, `intptr_t` and `int32_t` and I=E2=80=99m= not sure >> how to get it over to the OCaml side correctly. >>=20 >> Would the uint32_t be expressed as a Int32.t? Do I really need to put an >> integer as block just to get it to the OCaml side, because of the 31 bit >> integers on the OCaml side right? >=20 > Yes, you do, unless you can guarantee that you don't need bit 31 ever. Th= e Unix library, for example, uses a 31/63-bit int for Unix FDs (https://git= hub.com/ocaml/ocaml/blob/trunk/otherlibs/unix/open.c) on the realistic assu= mption that bit 31 will never be set. >=20 > You should use a nativeint (still boxed) for an intptr_t, as that will tr= ansparently work for 32/64-bit variants. >=20 >> Been looking for examples but can=E2=80=99t find any, example code great= ly >> appreciated, the C side and the ml side please. >=20 > There's quite a lot in the manual for this (http://caml.inria.fr/pub/docs= /manual-ocaml/intfc.html) - Int32_val and Nativeint_val are the two functio= ns for converting an OCaml value to a C type and caml_copy_int32 and caml_c= opy_nativeint are the equivalents for converting the C type back to an OCam= l value. >=20 > Putting caml_copy_nativeint into a GitHub search reveals, for example, ht= tps://github.com/yallop/ocaml-unix-type-representations/blob/master/lib/uni= x_type_representation_stubs.c (you can find many more examples by searching= for caml_copy_nativeint or caml_copy_int32) >=20 >=20 > David