From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA06761; Fri, 27 Jun 2003 10:59:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA07111 for ; Fri, 27 Jun 2003 10:59:49 +0200 (MET DST) Received: from post.kis.ru (post.kis.ru [195.98.32.206]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5R8xmf12054 for ; Fri, 27 Jun 2003 10:59:49 +0200 (MET DST) Received: from [195.98.54.162] (HELO heaven.merann.ru) by post.kis.ru (CommuniGate Pro SMTP 4.0.6) with ESMTP id 2993347; Fri, 27 Jun 2003 12:59:48 +0400 Date: Fri, 27 Jun 2003 12:59:56 +0400 From: Mikhail Fedotov X-Mailer: The Bat! (v1.62r) Reply-To: Mikhail Fedotov X-Priority: 3 (Normal) Message-ID: <21255847.20030627125956@kittown.com> To: "Jean-Baptiste Rouquier" CC: caml-list@inria.fr Subject: Re[2]: [Caml-list] interfacing C and OCaml In-Reply-To: <015e01c33c86$e06b79d0$7115c7c2@inrialpes.fr> References: <003001c33c17$343a0d80$355afac1@zofo> <54997465.20030627092459@kittown.com> <015e01c33c86$e06b79d0$7115c7c2@inrialpes.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 interfacing:01 camlprim:01 buffer:01 val:01 foo:01 camlparam:01 camlreturn:01 curses:01 mli:01 initscr:01 lacks:01 camlextern:01 dlls:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello Jean-Baptiste, Friday, June 27, 2003, 12:31:44 PM, you wrote: >> 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. >> JBR> Strange ! JBR> The complete example given in 18.6 contains : JBR> curses.mli : JBR> external initscr: unit -> window = "curses_initscr" JBR> curses.c ("curses.o" in the manual) : JBR> value curses_initscr(value unit) JBR> { JBR> CAMLparam1 (unit); JBR> CAMLreturn ((value) initscr()); JBR> } JBR> curses.ml : JBR> open Curses JBR> let main_window = initscr () in JBR> So functions using CAMLparam and CAMLreturn are called from OCaml directly. JBR> Or am I completely wrong ? JBR> I'm worried about the GC (for now, my code seems to run correctly, but use JBR> perhaps to much memory). Sorry, I've made a mistake myself. I've been talking mostly about "void" vs "value" issue in your examples, but this is already addressed in the manual by stating that the primitive function must return value. The documentation lacks introduction into the macroses "CAMLprim", "CAMLextern" etc, but they are not strictly required now if you are not dealing with Windows DLLs. I'd say that it is a bad style to write code without those macroses, at least. -- Best regards, Mikhail mailto:mikhail@kittown.com ------------------- 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