<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/4555ce883e1f38c5fb439263eaeb6d6b"
  from="Mitchell N Charity &lt;mcharity@v...&gt;"
  author="Mitchell N Charity"
  date="2002-12-06T20:07:02"
  subject="[Caml-list] Exceptions and C"
  prev="2002/12/aea498f4b382c4c38c55ec6bcfe788a7"
  next="2002/12/dc088b981df0d96498a14857f400b381"
  next-in-thread="2002/12/dc088b981df0d96498a14857f400b381"
  prev-thread="2002/12/aea498f4b382c4c38c55ec6bcfe788a7"
  next-thread="2002/12/2deaecb005361aa08c2faca67fcaa675"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Exceptions and C">
<msg 
  url="2002/12/4555ce883e1f38c5fb439263eaeb6d6b"
  from="Mitchell N Charity &lt;mcharity@v...&gt;"
  author="Mitchell N Charity"
  date="2002-12-06T20:07:02"
  subject="[Caml-list] Exceptions and C">
<msg 
  url="2002/12/dc088b981df0d96498a14857f400b381"
  from="Basile STARYNKEVITCH &lt;basile@s...&gt;"
  author="Basile STARYNKEVITCH"
  date="2002-12-06T20:21:45"
  subject="[Caml-list] Exceptions and C">
</msg>
</msg>
</thread>

<contents>
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 &lt;caml/mlvalues.h&gt;
#include &lt;caml/memory.h&gt;
#include &lt;caml/callback.h&gt;
#include &lt;stdio.h&gt;

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

</contents>

</message>

