caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christoph Bauer <christoph.bauer@lmsintl.com>
To: Romain Bardou <romain.bardou@inria.fr>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: RE: [Caml-list] C Interface question about failwith
Date: Fri, 1 Mar 2013 12:40:19 +0100	[thread overview]
Message-ID: <9A8556989A396A408C72088C69EDE56308AE441B10@KAIP-EXMSG01.lmsintl.com> (raw)
In-Reply-To: <51308CCA.3020904@inria.fr>

Hello Romain,

Great idea, this will definitely work.  Thanks!

By checking asmrun/fail.c I also understand the link error: caml_global_data is only used for bytecode.
With ocamlopt, this could work:

static
void failwith_string_value(value msg) Noreturn;

typedef value caml_generated_constant[1];

extern caml_generated_constant caml_exn_Failure;

static
void failwith_string_value(value msg)
{
  CAMLparam1(msg);
  caml_raise_with_arg((value)caml_exn_Failure, msg);
  CAMLnoreturn;
}

Kind Regards,
Christoph Bauer

-----Original Message-----
From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On Behalf Of Romain Bardou
Sent: Freitag, 1. März 2013 12:11
To: caml-list@inria.fr
Subject: Re: [Caml-list] C Interface question about failwith

Hello,

I guess you could apply the generic mechanism described in the user manual:

http://caml.inria.fr/pub/docs/manual-ocaml/manual033.html
19.7.3  Registering OCaml exceptions for use in C functions

Maybe Failure is already registered for callback but I don't know.

Cheers,

--
Romain Bardou

Le 01/03/2013 12:06, Christoph Bauer a écrit :
> Hi,
>
> In C code I have a malloced-string error message, which must be freed. 
> But I want also raise an OCaml exception with this string. Actually what I need something like this:
>
> static
> void failwith_string_value(value msg)
> {
>    CAMLparam1(msg);
>    caml_raise_with_arg(Field(caml_global_data, FAILURE_EXN), msg);
>    CAMLnoreturn;
> }
>
> Then I could do:
>
>
>       msg = caml_copy_string(s);
>      free(s);
>      failwith_string_value(msg);
>
>
> But FAILURE_EXN is not defined in fail.h and more important 
> caml_global_data is defined in mlvalues.h, but I get an undefined reference link error.
>
> Any ideas how to solve such a problem?
>
> Thanks,
> Christoph Bauer
>
>
>
>
>


--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

      reply	other threads:[~2013-03-01 11:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 11:06 Christoph Bauer
2013-03-01 11:11 ` Romain Bardou
2013-03-01 11:40   ` Christoph Bauer [this message]

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=9A8556989A396A408C72088C69EDE56308AE441B10@KAIP-EXMSG01.lmsintl.com \
    --to=christoph.bauer@lmsintl.com \
    --cc=caml-list@inria.fr \
    --cc=romain.bardou@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).