caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rich@annexia.org>
To: immanuel litzroth <ilitzroth@gmail.com>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Raising invalid_argument with a constructed string.
Date: Sat, 3 Dec 2016 13:20:28 +0000	[thread overview]
Message-ID: <20161203132028.GA28111@annexia.org> (raw)
In-Reply-To: <CAJjmLU4n0NVWzzCQ6-P+R1Neg0Er7gUQFJYNeHfLja7VbzEhAA@mail.gmail.com>

On Mon, Nov 28, 2016 at 03:39:05PM +0100, immanuel litzroth wrote:
> caml_invalid_argument(str) is no return and does not free it's
> argument.
> So calling it with a string constructed dynamically will mean it'll never
> get freed.
> I could construct an ocaml string and pass that to caml_raise_with_arg,
> but I don't seem to be able to get to the caml_exn_Invalid_argument from
> c. Am I missing something?

We have the same problem in libguestfs in a few places.  The solution
is to use an allocation on the C stack, either a fixed size buffer or
[although we don't currently use this] a variable sized one using
alloca.  The string is freed when the stack is unwound.  Examples:

https://github.com/libguestfs/libguestfs/blob/master/builder/yajl-c.c#L108-L114
https://github.com/libguestfs/libguestfs/blob/master/v2v/domainxml-c.c#L120

Be nice to have a "freeing" version of caml_raise* I suppose.

Rich.

  parent reply	other threads:[~2016-12-03 13:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-28 14:39 immanuel litzroth
2016-11-28 15:43 ` David Allsopp
2016-11-28 15:50   ` Gabriel Scherer
2016-11-29 10:21     ` immanuel litzroth
2016-12-03 13:20 ` Richard W.M. Jones [this message]
2016-12-03 14:00   ` immanuel litzroth
2016-12-03 19:36     ` Richard W.M. Jones
2016-12-03 19:44       ` Gabriel Scherer

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=20161203132028.GA28111@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=ilitzroth@gmail.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).