From: "Török Edwin" <edwin+ml-ocaml@etorok.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] C interop: Return values in parameters
Date: Sun, 30 Dec 2012 16:01:06 +0200 [thread overview]
Message-ID: <50E04922.207@etorok.net> (raw)
In-Reply-To: <20121230140823.20f39bcd@xivilization.net>
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 '<yourtype> 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
next prev parent reply other threads:[~2012-12-30 14:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-30 13:08 Marek Kubica
2012-12-30 14:01 ` Török Edwin [this message]
2012-12-30 14:19 ` Marek Kubica
2012-12-30 14:36 ` Gabriel Scherer
2012-12-31 1:48 ` Marek Kubica
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50E04922.207@etorok.net \
--to=edwin+ml-ocaml@etorok.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).