You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 221 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
Hello,
it seems that the C-interface to OCaml has changed slightly in an
unexpected way. I want to raise an exception that takes two arguments
from C. Xavier had sent me the code snippet to do this quite a while
ago, and it used to work fine last time I tested this code part (very
seldom executed).
Can anybody tell me what's different now / what I am doing wrong? Below
are two short snippets to try this out. Compile them with:
ocamlc -custom bla_c.c bla.ml -o bla
and run "bla" (crashes on my machine - a Pentium III / Linux). I haven't
tried it with an older OCaml-release yet, only with OCaml-3.00.
void raise_with_two_args(value tag, value arg1, value arg2)
{
value exc;
/* Protects tag, arg1 and arg2 from being reclaimed by the garbage
collector when the exception value is allocated */
Begin_roots3(tag, arg1, arg2);
exc = alloc_small(3, tag);
Field(exc, 1) = arg1;
Field(exc, 2) = arg2;
End_roots();
mlraise(exc);
}
void f () {
raise_with_two_args(*caml_named_value("Test"),
copy_string("foo"),
Val_int(42));
}
file: bla.ml
external f : unit -> unit = "f"
exception Test of string * int
let main () =
Callback.register_exception "Test" (Test ("", 0));
f ()
it seems that the C-interface to OCaml has changed slightly in an
unexpected way. I want to raise an exception that takes two arguments
from C. Xavier had sent me the code snippet to do this quite a while
ago, and it used to work fine last time I tested this code part (very
seldom executed).
void raise_with_two_args(value tag, value arg1, value arg2)
{
value exc;
/* Protects tag, arg1 and arg2 from being reclaimed by the garbage
collector when the exception value is allocated */
Begin_roots3(tag, arg1, arg2);
exc = alloc_small(3, tag);
Field(exc, 1) = arg1;
Field(exc, 2) = arg2;
End_roots();
mlraise(exc);
}
I'm surprised this ever worked at all! (But I won't go into my old
mail to see if this is really the code I sent you :-).)
Try the following instead:
Original bug ID: 221
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Hello,
it seems that the C-interface to OCaml has changed slightly in an
unexpected way. I want to raise an exception that takes two arguments
from C. Xavier had sent me the code snippet to do this quite a while
ago, and it used to work fine last time I tested this code part (very
seldom executed).
Can anybody tell me what's different now / what I am doing wrong? Below
are two short snippets to try this out. Compile them with:
ocamlc -custom bla_c.c bla.ml -o bla
and run "bla" (crashes on my machine - a Pentium III / Linux). I haven't
tried it with an older OCaml-release yet, only with OCaml-3.00.
file: bla_c.c
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
#include <caml/callback.h>
void raise_with_two_args(value tag, value arg1, value arg2)
{
value exc;
/* Protects tag, arg1 and arg2 from being reclaimed by the garbage
collector when the exception value is allocated */
Begin_roots3(tag, arg1, arg2);
exc = alloc_small(3, tag);
Field(exc, 1) = arg1;
Field(exc, 2) = arg2;
End_roots();
mlraise(exc);
}
void f () {
raise_with_two_args(*caml_named_value("Test"),
copy_string("foo"),
Val_int(42));
}
file: bla.ml
external f : unit -> unit = "f"
exception Test of string * int
let main () =
Callback.register_exception "Test" (Test ("", 0));
f ()
let _ = Printexc.catch main ()
Best regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
The text was updated successfully, but these errors were encountered: