caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exceptions and C
@ 2002-12-06 18:40 Mitchell N Charity
  2002-12-06 20:21 ` Basile STARYNKEVITCH
  0 siblings, 1 reply; 2+ messages in thread
From: Mitchell N Charity @ 2002-12-06 18:40 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Caml-list] Exceptions and C
  2002-12-06 18:40 [Caml-list] Exceptions and C Mitchell N Charity
@ 2002-12-06 20:21 ` Basile STARYNKEVITCH
  0 siblings, 0 replies; 2+ messages in thread
From: Basile STARYNKEVITCH @ 2002-12-06 20:21 UTC (permalink / raw)
  To: mcharity; +Cc: caml-list

>>>>> "Mitchell" == Mitchell N Charity <mcharity@vendian.org> writes:

    Mitchell> I gather run-time type checking is not occurring.  Can I
    Mitchell> at least count on avoiding a segfault, or is behavior
    Mitchell> completely undefined if callback arguments are
    Mitchell> incorrectly typed?

Behavior is undefined. For details, read the Chapter 18 "Interfacing C
with Objective Caml" of the reference manual. To understand what is
happening, read the section 18.2 (the value type) - or read the source
of the runtime system.

And there is a reason for that. The whole philosophy of Ocaml is
static typing, which the OCaml team pushes to the extreme (for
instance by refusing dynamic casting or class checking for objects).

I miss more dynamic ability of the object part of Ocaml (even if this
means having a tree of classes, not a forest, and reject multiple
inheritance).



-- 

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
alias: basile<at>tunes<dot>org 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-12-06 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 18:40 [Caml-list] Exceptions and C Mitchell N Charity
2002-12-06 20:21 ` Basile STARYNKEVITCH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).