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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id ACF9E7EE94 for ; Sun, 30 Dec 2012 15:01:10 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of edwin+ml-ocaml@etorok.net) identity=pra; client-ip=176.9.138.55; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="edwin+ml-ocaml@etorok.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of edwin+ml-ocaml@etorok.net designates 176.9.138.55 as permitted sender) identity=mailfrom; client-ip=176.9.138.55; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="edwin+ml-ocaml@etorok.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of postmaster@mail.etorok.net designates 176.9.138.55 as permitted sender) identity=helo; client-ip=176.9.138.55; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="postmaster@mail.etorok.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8JAJZI4FCwCYo3/2dsb2JhbABEg0i6FRZzgh4BAQVAAQE4DwsYCSUPAkYTCAKIE6UDhDoBBYx+BoxXgRqDKZYPhWuKXYJ2 X-IronPort-AV: E=Sophos;i="4.84,381,1355094000"; d="scan'208";a="187986536" Received: from mail.etorok.net ([176.9.138.55]) by mail1-smtp-roc.national.inria.fr with ESMTP; 30 Dec 2012 15:01:10 +0100 Received: from [172.30.42.2] (unknown [79.114.35.44]) by mail.etorok.net (Postfix) with ESMTPSA id 258B746B5 for ; Sun, 30 Dec 2012 15:01:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=etorok.net; s=MAILOUT; t=1356876069; bh=tZIQvSB+qFvplTChpurtZxTU2d0/RMTh+QoZ3abaKww=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=Rduv0U8ROUV1dLl1NiRm7zFw2zL0W6TOIe7N0cfNgZ0I2FxFj0lFlzaXVJBC38kka 2OBPjpwDsHPkyGLaKVFFyAM/EACDRQIohCvR/f03cvh4olvuhisvriiBH7VgKxQUXd YZS5eDcDbskmGQ7bnjOhoZRxb4opLvGytDgbcnRg= Message-ID: <50E04922.207@etorok.net> Date: Sun, 30 Dec 2012 16:01:06 +0200 From: =?ISO-8859-1?Q?T=F6r=F6k_Edwin?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 MIME-Version: 1.0 To: caml-list@inria.fr References: <20121230140823.20f39bcd@xivilization.net> In-Reply-To: <20121230140823.20f39bcd@xivilization.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.97.6 at mail X-Virus-Status: Clean Subject: Re: [Caml-list] C interop: Return values in parameters On 12/30/2012 03:08 PM, Marek Kubica wrote: > Hi, > > I am trying to wrap a C library in OCaml but I don't know how to do > this particular thing: > > I have a library that looks roughly like this: > > int function(void** ptr); > > So I get an int as return value to show whether the function succeeded > and it *sets* the ptr. > > void* ptr; > function(&ptr); > // ptr is different now > > How can I wrap such a function in OCaml? > When I call my OCaml wrapper > > let retval = function ptr in > ... > > the pointer does not get updated. Is there a function in the C API to > force OCaml to update the values? Use a ' ref' for the parameter (or a record with a mutable field) on the OCaml side, and you can update the field on the C side then. Or if your C type is not actually void*, and your C function doesn't have side-effects (besides updating ptr) you can also make the OCaml function return the actual value, and raise an exception if the function failed. Best regards, --Edwin