[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Guillaume Yziquel <guillaume.yziquel@c...> |
| Subject: | Re: [Caml-list] problem creating .cma library |
Gerd Stolpmann a écrit :
>>
>> Would it be legitimate to include CAMLlocal2 inside the error-handling
>> braces?
>
> No. You would start a new context for local roots, and there is no way
> to end it (CAMLreturn ends the context).
>
> There are the macros Begin_roots<n> and End_roots that should be used in
> this case, e.g.
>
> if (error) {
> value ml_error_call = Val_unit;
> value ml_error_message = Val_unit;
>
> Begin_roots2(ml_error_call, ml_error_message);
> ...
> End_roots();
>
> raise_with_arg(...)
> }
End_roots before caml_raise_with_arg? Why not after?
I mean, you do not do a CAMLreturn before a caml_raise_with_args, so why
should't this be the same for End_roots()?
> The macros are only documented in memory.h.
>
> So far I know, raising an exception from within Begin_roots/End_roots is
> not allowed.
It seems to me that the major issue is how caml_local_roots gets
restored. With the CAMLparam/CAMLreturn macros, this is done by storing
its original value in caml__frame and restoring it via CAMLreturn.
As it is written in memory.h
> Your function may raise an exception or return a [value] with the
> [CAMLreturn] macro.
I assume that caml_local_roots gets restored by a mechanism in the 'try'
of the 'try / with' construct after the siglongjmp of caml_raise.
Therefore it should be OK to use caml_raise_with_args before End_roots().
Am I right, or is this plainly wild guessing?
--
Guillaume Yziquel
http://yziquel.homelinux.org/