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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Baptiste Rouquier <Jean-Baptiste.Rouquier@i...>
Subject: Re: [Caml-list] interfacing C and OCaml
> JBR> 1. Should I use
> JBR> CAMLprim value input(value channel, value buffer, value offset, value
> JBR> length)
> JBR> {
> JBR>   return Val_long (...);
> JBR> }
>
> Yes. This function can be called from other C function or from OCaml.
>
> JBR> as in 18.1.2 in the manual, or
>
> JBR> void foo (value v1, value v2, value v3)
> JBR> {
> JBR> CAMLparam3 (v1, v2, v3);
> JBR> ...
> JBR> CAMLreturn0;
> JBR> }
>
> This if for functions called from C only. Not suitable for use from
> OCaml directly.
>
> Should be specified in the manual, I believe, but I've got no response
> in the list to my comment on this. I hope it will be in the manual for
> the OCaml 3.07.
>


Strange !
The complete example given in 18.6 contains :

curses.mli :
external initscr: unit -> window = "curses_initscr"

curses.c ("curses.o" in the manual) :
value curses_initscr(value unit)
{
CAMLparam1 (unit);
CAMLreturn ((value) initscr());
}

curses.ml :
open Curses
let main_window = initscr () in


So functions using CAMLparam and CAMLreturn are called from OCaml directly.
Or am I completely wrong ?
I'm worried about the GC (for now, my code seems to run correctly, but use
perhaps to much memory).


Thanks,
JBR

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