Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Exceptions and C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mitchell N Charity <mcharity@v...>
Subject: [Caml-list] Exceptions and C
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