From: Mitchell N Charity <mcharity@vendian.org>
To: caml-list@inria.fr
Subject: [Caml-list] Exceptions and C
Date: Fri, 6 Dec 2002 13:40:43 -0500 [thread overview]
Message-ID: <200212061840.gB6Iehc17706@vendian.org> (raw)
I rather expected this to raise an exception...
$ cat test1.ml
let plus_f x y = x +. y;;
Callback.register "plus_f" plus_f;;
$ cat test2.c
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
#include <stdio.h>
int main (int argc, char **argv) {
char * args[2] = { "fake_name", NULL };
caml_startup(args);
{
CAMLparam0();
CAMLlocal2(f,res);
value the_args[3];
the_args[0] = copy_double(32.1);
the_args[1] = copy_string("go boom"); /** incorrect type **/
f = *(caml_named_value("plus_f"));
res = callbackN_exn(f,2,the_args);
if(Is_exception_result(res)) {
fprintf(stderr,"OCaml exception raised.\n");
exit(1);
}
fprintf(stderr,"No exception.\n");
fprintf(stderr,"%lf\n",Double_val(res));
}
}
$ gcc -c test2.c -I/usr/local/lib/ocaml
$ ocamlopt test2.o test1.ml
$ ./a.out
No exception.
32.100000
But it doesn't.
Any thoughts?
I gather run-time type checking is not occurring. Can I at least
count on avoiding a segfault, or is behavior completely undefined if
callback arguments are incorrectly typed?
Thanks,
Mitchell Charity
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next reply other threads:[~2002-12-06 20:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-06 18:40 Mitchell N Charity [this message]
2002-12-06 20:21 ` Basile STARYNKEVITCH
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=200212061840.gB6Iehc17706@vendian.org \
--to=mcharity@vendian.org \
--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