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: Mikhail Fedotov <mikhail@k...>
Subject: Re[2]: [Caml-list] interfacing C and OCaml
Hi!

JBR> 1. Should I use
JBR> CAMLprim value input(value channel, value buffer, value offset, value
JBR> length)
JBR> {
JBR>   return ...
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.

JBR> ------------------------------------------------
JBR> 3. Is it correct to store p in the custom block v by
JBR> CAMLlocal(v);
JBR> v = alloc_custom(ops, 4, 0, 1);
JBR> (my_type *) Data_custom_val(v) = p;
JBR> ?
JBR> When does the parameter "size" (here "4") vary ?

CAMLlocal(v);
my_type *t;
my_type r;

v = alloc_custom(ops, 1 + sizeof(my_type), 1, 10);
t = (my_type *) Data_custom_val(v);

t->some_int_member = 7;

Mikhail

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