caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] C-Interface: CAMLreturn and failwith
Date: Fri, 20 Jan 2006 13:39:33 +0100	[thread overview]
Message-ID: <9FE64072-F2ED-4324-9482-5E9ECDF9A792@inria.fr> (raw)
In-Reply-To: <26EB47FDD566A7469FC862DAF373792F07D737@kaiserslautern1.lmsintl.com>


On Jan 20, 2006, at 13:18, Bauer, Christoph wrote:

> Hi,
>
> a question related to CAMLreturn and failwith in C-Stubcode:
>
> Is this code correct:
>
> #include <fail.h>
> ...
>
> CAMLprim value prim( value unit )
> {
>    CAMLparam0();
>    CAMLlocal( result );
>    int error;
>    /* allocate result, error has an errorcode */
>    if( error ) failwith( "error");
>    else CAMLreturn( result );
> }
>
> or should it be
>
> CAMLprim value prim( value unit )
> {
>    CAMLparam0();
>    CAMLlocal( result );
>    int error;
>    /* allocate result, error has an errorcode */
>    if( error ) {
>       caml_local_roots = caml__frame;
>       failwith( "error");
>    }
>    else CAMLreturn( result );
> }

The first one is correct: failwith will take care of deregistering
the local roots (actually, the bytecode interpreter does it when
failwith longjumps to the exception handler).

The second one should work in the current implementation, but it
may break in the future.

-- Damien


      reply	other threads:[~2006-01-20 12:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-20 12:18 Bauer, Christoph
2006-01-20 12:39 ` Damien Doligez [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=9FE64072-F2ED-4324-9482-5E9ECDF9A792@inria.fr \
    --to=damien.doligez@inria.fr \
    --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).