caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* C-Interface: CAMLreturn and failwith
@ 2006-01-20 12:18 Bauer, Christoph
  2006-01-20 12:39 ` [Caml-list] " Damien Doligez
  0 siblings, 1 reply; 2+ messages in thread
From: Bauer, Christoph @ 2006-01-20 12:18 UTC (permalink / raw)
  To: caml-list

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 );
} 

Thanks,

Christoph Bauer
Dipl. Inf.

LMS Deutschland GmbH
Luxemburgerstr. 7
D-67657 Kaiserslautern

T +49 631 303 22 152

mailto:Christoph.Bauer@lms-gmbh.de
http://www.lmsintl.com 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] C-Interface: CAMLreturn and failwith
  2006-01-20 12:18 C-Interface: CAMLreturn and failwith Bauer, Christoph
@ 2006-01-20 12:39 ` Damien Doligez
  0 siblings, 0 replies; 2+ messages in thread
From: Damien Doligez @ 2006-01-20 12:39 UTC (permalink / raw)
  To: caml users


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-20 12:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-20 12:18 C-Interface: CAMLreturn and failwith Bauer, Christoph
2006-01-20 12:39 ` [Caml-list] " Damien Doligez

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).