caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Problem with external function
@ 2005-12-29  1:52 Jonathan Roewen
  0 siblings, 0 replies; only message in thread
From: Jonathan Roewen @ 2005-12-29  1:52 UTC (permalink / raw)
  To: caml-list

Hi,

I have a weird problem with ocaml and my external function. It seems
it never gets called, and ocaml appears to lockup. This may be that
problem with compare function coming back to haunt me, so if anyone
has some clues, it'd really make my day!

In iO.ml (Pervasives IO is built on top of this module), I have:

external write_ex : char -> unit = "caml_output_char"
(*let write_ex _ = raise Output_closed*)

let stdout =
  let output string off len = for i = off to len - off - 1 do write_ex
string.[i] done in
  let seek = (fun _ -> raise Seek_unsupported)
  and tell = (fun _ -> 0)
  in create_out write_ex output seek tell default_close default_flush
default_length

Now, if I make it raise an exception, then it gets raised as a fatal
exception, and ocaml tidies up after itself -- all nice and good.

When I try to call the external function, nothing happens. At the very
least, it should exit the kernel -- which means that it is -once
again- getting stuck in some sort of infinite loop or other bizarre
problem I have no idea about.

The C function is very simple:

CAMLprim value caml_output_char(value val) {
  CAMLparam1(val);
  caml_sys_error(NO_ARG);
  CAMLreturn(Val_unit);
}

which doesn't work.

The proper version is to change second line to: dprintf("%c",
Int_val(val)); which also doesn't work.

dprintf works, as that is how fatal exceptions are printed.

caml_output_char has been added to byterun files, and I output a list
of caml primitives.

I compile stdlib with -use-primitives byterun/primitives, and the same
for my test.ml file.

I also have a full tarball of the sources online if anyone would like
to have a poke around (this is for my OS afterall, so a bit more
complex than normal...), at http://dst.purevoid.org/dst-0.0.tar.bz2

This problem with external functions is making any development impossible =(

Jonathan


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-29  1:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-29  1:52 [Caml-list] Problem with external function Jonathan Roewen

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).