caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mathias Kende <mathias.kende@ens.fr>
To: Jeffrey Barber <jeff@mathgladiator.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] caml_copy_string
Date: Sun, 22 Aug 2010 01:46:07 +0200	[thread overview]
Message-ID: <1282434367.988.11.camel@mathias-ens> (raw)
In-Reply-To: <AANLkTi=vo41hxuw_uwtCVD6YMHeUBfBR+YYNCxKrCjU0@mail.gmail.com>

Le samedi 21 août 2010 à 18:30 -0500, Jeffrey Barber a écrit :
> Is there a way to get a string from C to OCaml without the
> caml_copy_string
> function, or is there a version that doesn't copy the string?

There is no such function in the Caml FFI. You could write one yourself
but then the string must have been specially allocated because you need
to add a one word header to the string and maybe some byte at the end.
So, if you have to exchange strings between OCaml and C, the easiest way
is to always allocate them with the caml_alloc_string function. That way
you can use the pointer returned by String_val in your C code and the
string remains a valid Caml string (except caml does not use zero as the
end of string and will stick to its allocated size).

Mathias


  parent reply	other threads:[~2010-08-21 23:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21 23:30 caml_copy_string Jeffrey Barber
2010-08-21 23:42 ` [Caml-list] caml_copy_string Romain Beauxis
2010-08-21 23:46 ` Mathias Kende [this message]
2010-08-22 17:16   ` Till Varoquaux
2010-08-23  0:42     ` Till Varoquaux
2010-08-23  1:02       ` Jeffrey Barber
2010-08-23 12:09 ` Florent Monnier
2010-08-23 12:59   ` Stéphane Glondu
2010-08-23 13:46     ` Florent Monnier
2010-08-23 20:24   ` Romain Beauxis
2010-08-24 14:21     ` Florent Monnier
2010-08-24 14:52       ` Till Varoquaux
2010-08-24 15:22         ` Anil Madhavapeddy
2010-08-24 15:35           ` Romain Beauxis
2010-08-25 19:16             ` Florent Monnier
2010-08-25 19:33               ` Romain Beauxis
2010-08-25 15:21   ` Goswin von Brederlow
  -- strict thread matches above, loose matches on Subject: below --
2005-10-29  0:24 Jonathan Roewen
2005-10-29  0:32 ` Robert Roessler

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=1282434367.988.11.camel@mathias-ens \
    --to=mathias.kende@ens.fr \
    --cc=caml-list@inria.fr \
    --cc=jeff@mathgladiator.com \
    /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).